• jQuery Video Tutorials

jQuery - Selectors Reference



The jQuery Selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values, etc. jQuery provides set of selectors, including basic selectors, attribute selectors, etc.

These selectors simplifies the process of identifying and interacting with specific elements, reducing the complexity of JavaScript code.

jQuery Selectors Reference

In the following table, we have listed all the jQuery Selectors −

Sr.No. Methods & Description
1 *

Selects all elements.

2 #id

Selects an element with the specified id.

3 .class

Selects all elements with the specified class.

4 .class,.class

Selects all elements with any of the specified classes.

5 element

Selects all elements with the specified tag name.

6 el1,el2,el3

Selects all elements with any of the specified tag names.

7 :first

Selects the first element in the set of matched elements.

8 :last

Selects the last element in the set of matched elements.

9 :even

Selects even elements (based on zero-index).

10 :odd

Selects odd elements (based on zero-index).

11 :first-child

Selects every element that is the first child of its parent.

12 :first-of-type

Selects every element that is the first of its type among its siblings.

13 :last-child

Selects every element that is the last child of its parent.

14 :last-of-type

Selects every element that is the last of its type among its siblings.

15 :nth-child(n)

Selects every element that is the nth child of its parent.

16 :nth-last-child(n)

Selects every element that is the nth child of its parent, counting from the last child.

17 :nth-of-type(n)

Selects every element that is the nth of its type among its siblings.

18 :nth-last-of-type(n)

Selects every element that is the nth of its type among its siblings, counting from the last.

19 :only-child

Selects every element that is the only child of its parent.

20 :only-of-type

Selects every element that is the only one of its type among its siblings.

21 parent > child

Selects all child elements that are a direct child of the parent.

22 parent descendant

Selects all descendant elements that are a descendant of the parent.

23 element + next

Selects the next element that is immediately preceded by the element.

24 element ~ siblings

Selects all siblings elements that are preceded by the element.

25 :eq(index)

Selects the element with the specified index.

26 :gt(no)

Selects all elements with an index greater than the specified number.

27 :lt(no)

Selects all elements with an index less than the specified number.

28 :not(selector)

Selects all elements that do not match the given selector.

29 :header

Selects all header elements (<h1> to <h6&g;).

30 :animated

Selects all elements that are currently being animated.

31 :focus

Selects the element that currently has focus.

32 :contains(text)

Selects all elements that contain the specified text.

33 :has(selector)

Selects all elements that have at least one element matching the specified selector as a descendant.

34 :empty

Selects all elements that have no children (including text nodes).

35 :parent

Selects all elements that have at least one child node (either an element or text).

36 :hidden

Selects all elements that are hidden.

37 :visible

Selects all elements that are visible.

38 :root

Selects the document's root element.

39 :lang(language)

Selects all elements with the specified language attribute.

40 [attribute]

Selects all elements with the specified attribute.

41 [attribute=value]

Selects all elements with the specified attribute and value.

42 [attribute!=value]

Selects all elements with the specified attribute and not the specified value.

43 [attribute$=value]

Selects all elements with the specified attribute ending with the specified value.

44 [attribute|=value]

Selects all elements with an attribute value that either exactly matches the specified value or starts with the specified value followed by a hyphen (-).

45 [attribute^=value]

Selects all elements with the specified attribute beginning with the specified value.

46 [attribute~=value]

Selects all elements with the specified attribute containing the specified value (space-separated list).

47 [attribute*=value]

Selects all elements with the specified attribute containing the specified value.

48 :input

Selects all input, textarea, select, and button elements.

49 :text

Selects all input elements with type "text".

50 :password

Selects all input elements with type "password".

51 :radio

Selects all input elements with type "radio".

52 :checkbox

Selects all input elements with type "checkbox".

53 :submit

Selects all input elements with type "submit".

54 :reset

Selects all input elements with type "reset".

55 :button

Selects all button elements and input elements with type "button".

56 :image

Selects all input elements with type "image".

57 :file

Selects all input elements with type "file".

58 :enabled

Selects all enabled elements.

59 :disabled

Selects all disabled elements.

60 :selected

Selects all selected options in a dropdown.

61 :checked

Selects all checked checkboxes or radio buttons.

Advertisements