Class Selector


The class selector is used to select multiple HTML elements that share the same class name.

It is commonly used when applying styles or actions to a group of elements.

In jQuery, the class selector uses the dot (.) symbol followed by the class name.

All three div elements have the same class name.

jQuery can select all of them at once using the class selector.

This code applies the same style to all elements with class box.

Class selectors are very useful for bulk operations.

This example attaches a click event to all elements having the same class.

All selected elements respond to the same event.

Class Selector Rules:

  • Use . before class name
  • Can select multiple elements
  • Best for repeated elements
  • Very common in UI development