Selectors in jQuery:

Selectors in jQuery allow you to select and manipulate the HTML elements. The jQuery selector is use to select of find the HTML elements based on the element name, id, class or attributes.

You should always start selector with dollar sign “$” and write the selector in parentheses “()”.

Type of Selectors:

In this tutorial we will learn three type of selector as we learn in CSS.

  • Element selector
  • Id selector
  • Class selector

Note:

In all our selectors example we are using “$document().ready()” event which will we cover in our next topic “Events in jQuery”.

The jQuery element selector:

The element selector in jQuery selects the element as per the name of element.

If you want to select a paragraph than you have to write like this:

$(“p”)

Example:

The id (#) jQuery Selector:

The id selector selects the element which is specified with the id (#) selector.

Example:

In following example we will assign “id “to one paragraph element

The class(.) jQuery selector:

The class selector selects the element which is specified with the id (.) selector.

Example:

 

Leave a Reply

Your email address will not be published. Required fields are marked *