jQuery element selectors allow you to select HTML elements based on their tag names such as p, div, span, ul, etc. Once selected, you can apply styles, events, animations, or manipulate content easily.
The basic syntax for element selectors in jQuery is:
$("element") — selects all matching elements of that type.
You can also select multiple distinct elements at the same time by separating them with a comma:
$("h1, div, p") — selects all h1, div, and p elements.
// Select all paragraph elements and change text color
$("p").css("color","blue");
// Hide all div elements on button click
$("button").click(function(){
$("div").hide();
});
// Select multiple elements using group selector
$("h2, p, span").css("background-color","yellow");
In the first example, all <p> elements become blue instantly. In the second example, clicking the button hides all <div> elements on the page.
Use the buttons below to select specific HTML elements inside the canvas box. Watch how jQuery finds them!
I am a <p> paragraph inside a div.
I am a standalone <p> paragraph.
// Toggle highlight on all list items
$("li").click(function(){
$(this).css("background","yellow");
});
div unless required