jQuery Selectors - jQuery Tutorial CodingTuting


jQuery Selectors


Use of jQuery selectors
jQuery Selectors jQuery Tutorial CodingTuting.com

We have to tell to the jQuery that - on which part or on which element we want to apply any action. We use the "selector" for this. We'll look for "How to use jQuery Selectors" in this jQuery Tutorial.

jQuery selectors are used to selecting the HTML element.

And jQuery Selectors are based on HTML Tag Name, ID, Class Name, attributes, the value of the attributes, etc.

Selectors are written in the parentheses with the $ sign. $(selector)


Select by .class

Write classname with the prefix. (dot) in the quotes.

Syntax:

$(".className")

Example:

 $(".testClass")
 $(".myClass")
 $(".darkMode")

Practical

This will hide the content of the class "hideText".

 

 

This is an example text. Click above button to hide this text.



Output:


This is an example text. Click above button to hide this text.



Select by #id

Write id with prefix # (hash) in the quotes.

Syntax:

$("#id")

Example:

 $("#testId")
 $("#myId")
 $("#fName")

Practical

This will hide the content of the id "hideId".

    

    

This is an example text. Click above button to hide this text.

    

Output:


This is an example text. Click above button to hide this text.



Select HTML element

Write tag name in the quotes.

Syntax:

$("tag name")

Example:

        $("span")
        $("p")
        $("ul")
    

Practical

This will hide the content of the "span" tag.

    

    
        This is an example text in a span tag. Click above button to hide this text. 
    
    

Output:


This is an example text in a span tag. Click above button to hide this text.

Thanks for Reading


Hi, I'm Jignesh Panchal. I'm a Web Developer & Designer. I've started this blog to help the programmers using my experience and skills. You will get solutions and tips about Programming, Web Development etc.

Share this

Related Posts