How to use jQuery class selector with example

Selecting elements by class name

Syntax of jQuery class selector

$(“.classname”);

Selecting elements by class names requires calling by ‘.’ (period) followed by the class name of the element. The jQuery selector will search for the given class in the document and perform given action.

Example of Selector by Class name

In the example below, Div with class=text will be shown and Show button is made hidden when the document is ready. As you click on “Hide text” button div will be hidden and “Show text” button will be shown.


In real time development, your class name specifications may be specified in an outer CSS file.

Was this article helpful?

Related Articles

Leave A Comment?