Selectors

As the name suggests, selector attributes are used to select various elements of HTML. The selector attributes basically support the CSS selectors.

Selectors begin with a $ sign followed by parentheses: $()

Element selectors

Element selectors select elements using their name. For example, if a paragraph is written in the tags <p>, you can select this paragraph using its name, that is, p:

$("p")

Parameters

The name of the element to be chosen is passed as a parameter.

Returns

The element selectors returns the element.

Description

The element selectors select elements using their name. For example, if a paragraph is written in the tags <p>, you can select this paragraph using its name.

ID selectors

ID selectors select elements using their ID. Each element of the HTML can have its own identifying ID and it can be accessed using #. For example, to access the element with the ID text, we can use the following syntax:

$("#text")

Parameters

The pound sign (or number sign) or a hash sign followed by the ID name is passed as a parameter.

Returns

This returns the element using the ID passed as a parameter.

Description

This selects elements using their ID. IDs are usually used to uniquely identify DOM elements that are accessed through the pound symbol in Javascript or the hash sign.

Class selectors

Class selectors select the elements using the class name. For example, a class named sample can be accessed by the following syntax:

$(".sample")

Parameters

A dot/period followed by the name of the class is passed as a parameter.

Returns

This returns the elements using the Class name passed as parameter.

Description

This selects the elements using the class name.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.70.101