- Rapid development.
- A lot of browser incompatibility worries are alleviated.
- Plugins - cool stuff and features you need are already written.
- HTML element selections
- HTML element manipulation
- HTML event functions
- HTML DOM traversal and modification
- CSS manipulation
The jQuery library consists of methods where you select an HTML element and then perform an action on it. To call a jQuery method, the general syntax is:Syntax
- A $ sign to define/access jQuery
- A (selector) to "query (or find)" HTML elements
- A jQuery action() to be performed on the element(s)
|$("*")||Selects all elements|
|$("p")||Selects all elements with that name|
|$("#id")||Selects only that element having that unique id|
|$(".class")||Selects all elements having that class|
|$(this)||Selects the current HTML element|
|$("[href]")||Selects all elements with an href attribute|
Selectors by Relationship
|$("p:first")||The first p element|
|$("p:last")||The last p element|
|$("tr:even")||All even tr elements|
|$("tr:odd")||All odd tr elements|
|$("p:first-child")||All p elements that are the first child of their parent|
|$("p:last-child")||All p elements that are the last child of their parent|
|$("div > p")||All p elements that are a direct child of a div element|
|$("div p")||All p elements that are descendants of a div element|
|$("h2 + div")||All div elements that are adjacent siblings of h2 elements|
|$("ul ~ p")||All p elements that are siblings of ul elements|
The jQuery syntax is tailor made for selecting HTML elements and performing some action on the element(s).examples
jQuery and CSS
You can use jQuery to return the value of a CSS property or set the value of a CSS property.