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.
EmoticonEmoticon