jQuery selectors allow you to select and manipulate HTML elements as a group or as a single element.
jQuery Selectors
In the previous chapter we looked at some examples of how to select different HTML elements.
It is a key point to learn how jQuery selects exactly the elements you want to apply an effect to.
jQuery selectors allow you to select HTML elements (or groups of elements) by element name, attribute name or by content.
In HTML DOM terms: Selectors allow you to manipulate DOM elements as a group or as a single node. |
jQuery Element Selectors
jQuery uses CSS selectors to select HTML elements.
$("p") selects all <p> elements.
$("p.intro") selects all <p> elements with class="intro".
$("p#demo") selects all <p> elements with id="demo".
jQuery Attribute Selectors
jQuery uses XPath expressions to select elements with given attributes.
$("[href]") select all elements with an href attribute.
$("[href='#']") select all elements with an href value equal to "#".
$("[href!='#']") select all elements with an href attribute NOT equal to "#".
$("[href$='.jpg']") select all elements with an href attribute that ends with ".jpg".
No comments:
Post a Comment