CSS Manipulation
jQuery selectors allow selection and manipulation of HTML elements as a group or as a single element.
Element Selectors
jQuery uses CSS selectors to select HTML elements.
| Selector / Description |
|---|
*Example: $("*") |
elementExample: $("p") |
.classExample: $(".intro") |
#idExample: $("#demo") |
Attribute Selectors
jQuery uses XPath expressions to select elements with given attributes.
| Selector / Description |
|---|
[attribute]Example: $("[href]") |
[attribute=value]Example: $("[href='#']") |
[attribute!=value]Example: $("[href!='#']") |
[attribute$=value]Example: $("[href$='.jpg']") |
CSS Selectors
jQuery CSS selectors can be used to change CSS properties for HTML elements.
he following example changes the background-color of all p elements to yellow:
$("p").css("background-color","yellow");
