Image

jQuery - jQuery Selector - jQuery Selector

jQuery Selector

iv1" in the elements.

JQuery Selector

There are following selector in JQuery.

1 (“*”) All selector

“*” means it select all

2 : Animated selector

Select all elements which are progress in animation when the selector is run .

3 [name|=”value”]

Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-).

4 [name*=”value”]

Selects elements that have the specified attribute with a value containing a given substring.

5 $(this)

This keyword indicate that select the current html element.

6 $("p.intro")

Select all paragraph elements <p> with class =”intro”.

7 (“.class”)

Select all elements with given specific class.

8 :contains()

In html most of the elements contain text so this selector select all elements which contain the text.

9 $("[href]")

It select all elements with href attribute i.e hyper reference.

10 $("p:first")

If we want to select the first paragraph then use this selector.

11 $()

It represents a tag name available in the DOM. For example: $('p') selects all paragraphs'p'in the document.

12 $('#red-id')

It select the specific element in the document that has an ID of red-id.

EX :This will select all elements with tag name and the background color will be red.
<!DOCTYPE html>
2. <html>
3. <head>
4. <title>help4code</title>
5. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
6. </script>
7. <script type="text/javascript" language="javascript">
8. $(document).ready(function() {
9. $("p").css("background-color", "red");
10. });
11. </script>
12. </head>
13. <body>
14. <p>This is first paragraph.</p>
15. <p>This is second paragraph.</p>
16. <p>This is third paragraph.</p>
17. </body>
18. </html>