ID Selector


The ID selector is used to select a single unique HTML element.

Each ID must be unique on a web page, meaning it should not be repeated.

In jQuery, the ID selector uses the # symbol followed by the ID name.

This HTML element has an ID named saveBtn.

jQuery can target this element using the ID selector.

This code selects the button using its ID and attaches a click event.

ID selectors are commonly used for buttons and unique elements.

This example changes the style of a specific element using its ID.

Only one element will be affected.

ID Selector Rules:

  • Use # before ID name
  • ID must be unique
  • Best for single elements
  • Commonly used for buttons and forms