- Home
- Core Functions
Nine core functions
The library is efficient and lightweight, and it grew quickly after its introduction in 2006. These are the functions that explain most of what it does.
jQuery is an efficient, lightweight JavaScript library designed to easily manipulate HTML documents and manage events. Since its introduction in 2006, it has grown immensely in popularity. These nine functions cover the parts most teams touch every day.
01DOM manipulation
With jQuery it is simple and efficient to select and manipulate HTML elements with CSS selectors. Developers can change content, structure and style on a page with minimal hassle, and the same selection can receive several changes in one chain.
$('#notice')
.text('Saved to your account')
.addClass('isReady');
Reference jQuery manipulation documentation jQuery selectors
02Event handling
jQuery provides a straightforward approach and a consistent interface for attaching event handlers to elements. Clicks, hovering and key presses all follow the same model, and delegation lets a parent listen for events from children that arrive later.
$('.card').on('click', function () {
$(this).toggleClass('isOpen');
});
Reference jQuery events documentation
03Animations
jQuery offers an easy yet powerful method for animating page elements, including fading, sliding and toggling. The methods accept a duration and an optional callback, so a sequence can finish before the next step begins.
$('.panel').slideToggle(240);
Reference jQuery effects documentation
04AJAX
With jQuery it is simple to make AJAX requests that load data from a server without refreshing an entire page. Dynamic applications can update a region, refresh a list or validate a field while the rest of the interface stays in place.
$.get('/notes.json', function (data) {
$('#notes').text(data.summary);
});
Reference jQuery AJAX documentation
05Utility functions
jQuery includes several useful utility functions for manipulating strings, arrays and cookies. They handle common loops and checks without extra code, and they keep the same style as the rest of the library.
$.each(['html', 'css', 'js'], function (index, value) {
$('#stack').append('<li>' + value + '</li>');
});
Reference jQuery utilities documentation jQuery.each documentation
06Plugin architecture
jQuery features an extensible plugin architecture that lets developers add custom behavior. That design led to a large ecosystem of plugins offering image sliders, form validators, charts and many other features.
$.fn.highlight = function () {
return this.addClass('isBright');
};
Reference Guide to authoring plugins
07Cross browser compatibility
jQuery provides cross browser compatibility, which makes development simpler for modern browsers and makes code more readable by chaining multiple functions together. Chaining groups related operations into one expression, so the sequence is easier to read and maintain.
Reference jQuery browser support
08Traversing
jQuery provides functions to traverse the DOM, making it easy to select related elements and perform operations on them. Moving from a container to its children, siblings or parents becomes a short chain rather than a manual walk through nodes.
$('.list')
.find('.item')
.first()
.addClass('isFirst');
Reference jQuery traversing documentation
09Effects
jQuery offers various visual effects such as slide, fade and toggle that can be applied to HTML elements for enhanced usability. Effects can draw attention to a change, soften a reveal or hide detail until it is needed.
$('.notice').fadeIn(200);
Reference jQuery .animate() documentation jQuery .fadeIn() documentation
The functions above overlap in practice. A single chain can select an element, change its content, attach a handler and animate the result. The next chapter shows how to load the library before writing that chain.
Load it and try a chain
The getting started chapter covers delivery, the document ready pattern and a first working script.