jQuery Home

Selectors

The element Selector

The jQuery element selector selects elements based on the element name.

You can select all <p> elements on a page like this.


The id Selector

The jQuery #id selector uses the id attribute of an HTML tag to find the specific element.


The class Selector

When a user clicks on a button, the elements with class="test" will be hidden.


Elements with an assigned class Selector

When a user clicks on a button, the paragraph elements with the assigned class will be hidden.


The multiple classes Selector

Select all elements with class "intro", "demo" or "end".


Selects all elements

When a user clicks on a button, all elements will be hidden.


Selects multiple elements

Select all <h2>, <div> and <span> elements.


Selects the current HTML element

When a user clicks on a button, the element with the focus, the button, will be hidden.


Send the focus to an eligible element: input box, textarea, button, etc.

Programmable event occurs upon receiving focus.



Selects the first <p> element

When a user clicks on a button, the first paragraph element will be hidden.


Selects the last <p> element

Selects the first <li> element of the first <ul>

When a user clicks on a button, the first list element of the first unordered list will be hidden.


first-child-item Selector

Selects the first <li> child element of each <ul>

When a user clicks on a button, the first list element of each unordered list will be hidden.


last-child-item Selector

Selects every <p> element that is the last child of its parent


only-child Selector

Select each <p> element that is the only child of its parent


first-of-type Selector

Selects all <p> elements that are the first <p> element of their parent


last-of-type Selector

Selects every <p> element that is the last <p> element of its parent


only-of-type Selector

Selects all <p> elements that are the only <p> element of their parent


nth-of-type Selector

Select each <p> element that is the third <p> element of its parent


nth-last-of-type Selector

Select each <p> element that is the third <p> element of its parent, counting from the last child


nth-child Selector

Selects every <p> element that is the third child of its parent


nth-last-child Selector

Selects every <p> element that is the third child of its parent, counting from the last child


Selects all elements with an href attribute

When a user clicks on a button, all elements with an href attribute will be hidden.


parent > child Selector

Select all <span> elements that are a direct child of a <div> element. They will appear with a yellow background.


parent descendant Selector

Select all <span> elements that are descendants of a <div> element. They will appear with a yellow background.


element + next Selector

Select all <p> elements that are next to and following each <div> element. They will appear with a yellow background.


element ~ siblings Selector

Select all <p> elements that are siblings and appear after the <div> element. They will appear with a yellow background.


header Selector

Select all header elements (h1 to h6).


animated Selector

Select any element that is currently animated.


contains Selector

Select all <p> elements containing "is".


has Selector

Select all <p> elements that have a <span> element inside of them.


empty Selector

Select all empty elements.


hidden Selector

Show hidden <p> elements.



visible Selector

Select all visible <p> elements.


root Selector

Set the background color for the HTML document to yellow.


lang Selector

Select and style every <p> element with a lang attribute value equal to "it" (Italian).


[attribute=value] Selector

Select every element containing an id attribute with the value "choose".


[attribute!=value] Selector

Select every paragraph element without a class attribute of "intro".


[attribute$=value] Selector

Select all <a> elements with a href attribute that ends with ".org".


[attribute|=value] Selector

Select all <p> elements with a title attribute that starts with the value "Tomorrow".


[attribute^=value] Selector

Select all <input> elements with a name attribute that starts with the value "nation".


[attribute~=value] Selector

Select all <input> elements with a name attribute that contains the specific word "nation".


[attribute*=value] Selector

Select all <input> elements with a name attribute that contains the word "nation".


:input Selector

The :input selector selects form elements.

This selector also works with the button element.


:text Selector

The :text selector selects input elements with type=text.


:password Selector

The :text selector selects input elements with type=password.


:radio Selector

The :text selector selects input elements with type=radio.


:checkbox Selector

The :checkbox selector selects input elements with type=checkbox.


:checked Selector

Select all checked elements (checkboxes or radio buttons).


:submit Selector

The :submit selector selects button and input elements with type=submit.


:reset Selector

The :reset selector selects button and input elements with type=reset.


:button Selector

The :button selector selects button and input elements with type=button.


:image Selector

The :image selector selects input elements with type=image.


:file Selector

The :file selector selects input elements with type=file.


:enabled Selector

The :enabled selector selects all enabled form elements.


:disabled Selector

The :disabled selector selects all disabled form elements.


:selected Selector

Select the pre-selected item(s) in a drop-down list.


parent Selector

Select all <td> elements with children, including text.


Selects all <a> elements with a target attribute value equal to "_blank"

When a user clicks on a button, all anchor elements with a blank target attribute will be hidden.


Selects all <a> elements with a target attribute value NOT equal to "_blank"

When a user clicks on a button, all anchor elements with a non-blank target attribute will be hidden.


Selects all even <tr> elements

All even table rows will be highlighted yellow.


Selects all odd <tr> elements

All odd table rows will be highlighted yellow.