jQuery basic selectors example

jQuery basic element selectors with simple example. Basic selectors use for select all element, select element based on class name, select element based on id value, select element based on element name and select multiple element using specified selector.

Class Selector (“.class”)

Selects all elements with the given class.

Paragraph element for class selector.
$('.myClass').text('You just test Class Selector');

ID Selector (“#id”)

Selects a single element with the given id attribute.

Paragraph element for id selector.
$('#myId').text('You just test ID selector');

Element Selector (“element”)

Selects all elements with the given tag name.

Strong element for element selector.
$('strong').text('You just test Element Selector');

Multiple Selector (“selector1, selector2, selectorN”)

Selects the combined results of all the specified selectors.

$('.myClass, #myId, strong').text('You just test Multiple Selector');

All Selector (“*”)

Selects all elements.

Strong element.
Emphasized text.

div element.
$('*').text('You just test All Selector');