jQuery Examples
jQuery is a cross-browser JavaScript library introduced in January 2006 by John Resig, aimed at streamlining the scripting of HTML on the client side. It streamlines tasks such as traversing and modifying the HTML DOM tree, managing events, implementing CSS animations, and facilitating Ajax interactions. Emphasizing its querying capabilities, jQuery employs CSS selectors to retrieve a group of elements within the document, enabling efficient batch operations on the selected elements.
jQuery is fundamentally composed of JavaScript code, yet it abstracts numerous frequently-repeated tasks into methods. By doing so, it eliminates the need to rewrite these tasks for every program. This exemplifies the principles of abstraction and modularity inherent in computing, making jQuery a prime illustration of these foundational concepts.
Why Use a JavaScript Library?
- Rapid development.
- Lightweight.
- A lot of browser incompatibility worries are alleviated.
- Plugins - cool stuff and features you need are already written.
jQuery Features
- HTML element selections
- HTML element manipulation
- HTML event functions
- HTML DOM traversal and modification
- CSS manipulation
- JavaScript Effects and animations
- AJAX
- Utilities

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)
Selectors
Selector | Description |
---|---|
$("*") | 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 |
Magic Selectors
- :first
- :last
- :header
- :hidden
- :contains
- :radio
- :input
Selectors by Relationship
Selector | Description |
---|---|
$("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).
examplesjQuery and CSS
You can use jQuery to return the value of a CSS property or set the value of a CSS property.
Conclusion
Utilizing a JavaScript library like jQuery streamlines development by encapsulating common tasks into pre-built methods, sparing developers from repetitive coding. This abstraction enhances code efficiency and modularity, exemplifying key computing principles.
- How to get input textbox value using jQuery
- JQuery Get Selected Dropdown Value on Change Event
- How to submit a form using ajax in jQuery
- How can I get the ID of an element using jQuery
- Open Bootstrap modal window on Button Click Using jQuery
- How to select an element with its name attribute | jQuery
- How to get the data-id attribute using jQuery
- How to disable/enable submit button after clicked | jQuery
- How to replace innerHTML of a div using jQuery
- How to get the value of a CheckBox with jQuery
- How to wait 'X' seconds with jQuery?
- How to check if an enter key is pressed with jQuery
- How to allow numbers only in a Text Box using jQuery
- How to dynamically create a div in jQuery?