jQuery ID and Class selectors are used to select HTML elements based on their id or class attributes. They are among the most commonly used selectors because they are simple, fast, and easy to understand.
# and targets a unique element. and targets multiple elements$()$("#id") → Select element by ID$(".class") → Select elements by class
// Select element using ID and change its text
$("#title").text("ID Selector Applied");
// Select all elements with class and apply CSS
$(".box").css("background-color","lightblue");
The ID selector updates only one specific element, while the class selector applies changes to all elements sharing the same class name.
Clicking a button can trigger jQuery to style elements dynamically using ID or class selectors.
// Button click applies styles using both selectors
$("#btn").click(function(){
$("#demo").css("color","red");
$(".group").css("font-weight","bold");
});