Powerful jQuery Tag Selectors

Here are a few examples of tag selectors that go between the ‘magic’ jQuery $();….. * Matches any element E Matches all elements with tag name E i.e. $(‘img’); E...

Here are a few examples of tag selectors that go between the ‘magic’ jQuery $();…..

* Matches any element

E Matches all elements with tag name E i.e. $(‘img’);

E F Matches all elements with tag name F That are descendents of E i.e. $(‘li a’);

E>F Matches all elements with tag name F That are direct children of E i.e. $(‘li>a’);

E+F Matches all elements F immediately preceeded by sibling E

E~F Matches all elements F preceeded by any sibling E

E:has(F) Matches all elements with tag name E that have at least one descendentn with tag name F

E.C Matches all elements E with class name C. Omitting E is the same as *.C

E#I Matches all elements E with the ID of I. Omitting E is the same as *#I

E[A] Matches all elements E with attribute A of any value.

E[A=V] Matches all elements E with attribute A whose value is exactly V. i.e. $(‘input[type=text]‘);

E[A^=V] Matches all elements E with attribute A whose value begins with V. i.e. $(‘a[href^=http://]‘);

E[A$=V] Matches all elements E with attribute A whose value ends with V. i.e. $(‘a[href$=.pdf]‘);

E[A*=V] Matches all elements E with attribute A whose value contains V. i.e. $(‘a[href*=jquery.com]‘);

Info from jQuery in Action by Bibeault Katz

Related posts:

  1. Adding jQuery to your page
  2. jQuery Photo Reflections
  3. To ‘Get’ an element in jQuery

This post has had 14 views