0% found this document useful (0 votes)
64 views

The Jquery Library Harnesses The Power of Cascading Style Sheets

The jQuery library uses CSS selectors to access elements in the DOM. The $() function selects elements using tag name, id, or class. It supports various selectors including selecting children, first/last elements, empty elements, and elements matching attributes.

Uploaded by

Ahmadullah Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

The Jquery Library Harnesses The Power of Cascading Style Sheets

The jQuery library uses CSS selectors to access elements in the DOM. The $() function selects elements using tag name, id, or class. It supports various selectors including selecting children, first/last elements, empty elements, and elements matching attributes.

Uploaded by

Ahmadullah Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

The jQuery library harnesses the power of Cascading Style Sheets (CSS) selectors to let us quickly

and easily access elements or groups of elements in the Document Object Model (DOM).A jQuery
Selector is a function which makes use of expressions to find out matching elements from a DOM
based on the given criteria.

The $() factory function:


All type of selectors available in jQuery, always start with the dollar sign and parentheses: $().
NOTE: The factory function $() is a synonym of jQuery() function. So in case you are using any
other JavaScript library where $ sign is conflicting with some thing else then you can replace $ sign
by jQuery name and you can use function jQuery() instead of $(). The factory function $() makes
use of following three building blocks while selecting elements in a given document:
1. Tag Name
2. Tag ID
3. Tag Class

1. $("p > *"): This selector selects all elements that are children of a paragraph
element.
2. $("#specialID"): This selector function gets the element with id="specialID".
3. $(".specialClass"): This selector gets all the elements that have the class of
specialClass.
4. $("li:not(.myclass)"): Selects all elements matched by <li> that do not
have class="myclass".
5. $("a#specialID.specialClass"): This selector matches links with an id of specialID
and a class of specialClass.
6. $('*'): This selector selects all elements in the document.
1. $("p a.specialClass"): This selector matches links with a class of specialClass
declared within <p> elements.
2. $("ul li:first"): This selector gets only the first <li> element of the <ul>.
3. $("#container p"): Selects all elements matched by <p> that are
descendants of an element that has an id of container.
4. $("li > ul"): Selects all elements matched by <ul> that are children of
an element matched by <li>
5. $("strong + em"): Selects all elements matched by <em> that immediately
follow a sibling element matched by <strong>.$("p ~ ul"): Selects all
elements matched by <ul> that follow a sibling element matched by <p>.
6. $("code, em, strong"): Selects all elements matched by <code> or <em> or
<strong>.
7. $("p strong, .myclass"): Selects all elements matched by <strong> that are
descendants of an element matched by <p> as well as all elements that
have a class of myclass.
8. $(":empty"): Selects all elements that have no children.
9. $("p:empty"): Selects all elements matched by <p> that have no children.
10. $("div[p]"): Selects all elements matched by <div> that contain an element
matched by
<p>.

11. $("p[.myclass]"): Selects all elements matched by <p> that contain an


element with a class of myclass.
12. $("a[@rel]"): Selects all elements matched by <a> that have a rel attribute.
13. $("input[@name=myname]"): Selects all elements matched by <input> that
have a name value exactly equal to myname.
14. $("input[@name^=myname]"): Selects all elements matched by <input> that
have a name value beginning with myname.
15. $("a[@rel$=self]"): Selects all elements matched by <p> that have a class
value ending with bar
16. $("a[@href*=domain.com]"): Selects all elements matched by <a> that have
an href value containing domain.com.
17. $("li:even"): Selects all elements matched by <li> that have an even index
value.
18. $("tr:odd"): Selects all elements matched by <tr> that have an odd index
value.
19. $("li:first"): Selects the first <li> element.
20. $("li:last"): Selects the last <li> element.
21. $("li:visible"): Selects all elements matched by <li> that are visible.
22. $("li:hidden"): Selects all elements matched by <li> that are hidden.
23.

You might also like