Thursday, April 18, 2013

jQuery Selectors


1. $(‘p.note’) returns all <p> elements whose class name is note;
2. $(‘p#note’) returns the <p> element whose id is note;
3. $(‘p’) returns all <p> elements
4. To select a child or children, we use the right angle bracket (>), as in $(‘p>a’) (returns all of the hyper links within the <p> element);
5. To select element(s) with certain attributes, we use [], as in input[type=text] (returns all text input element);
6. To select a container of some other elements, we use has keyword, for example: $(‘p:has(a)’) (returns all <p> elements that contains an hyperlink);
7. jQuery also has a position-based selector for us to select elements by position, for example $(‘p:first’)

No comments:

Post a Comment