![]() |
VOOZH | about |
jQuery is an open-source, feature-rich JavaScript library, designed to simplify the HTML document traversal and manipulation, event handling, animation, and Ajax with an easy-to-use API that supports the multiple browsers. It makes the easy interaction between the HTML & CSS document, Document Object Model (DOM), and JavaScript. With the help of jQuery, the multiple lines of code can be wrapped into methods, which in turn, can be called with a single line of code to perform a particular task. This, in turn, jQuery makes it easier to use Javascript on the website, along with enhancing the overall performance of the website.
The jQuery Cheat Sheet will give quick ideas related to the topics like Selectors, Attributes, Manipulation, Traversing, Events, Effects & many more, which will provide you a gist of jQuery with basic implementation. The purpose of the Cheat Sheet is to provide you with the content at a glance with some quick accurate ready-to-use code snippets that will help you to build a fully-functional webpage.
jQuery Basics: jQuery is a lightweight, feature-rich Javascript library that helps to simplify the overall complexity of the code by implementing the Selectors, Attributes, Events, Effects, etc, with the use of the required API to perform the particular task.
CDN Link:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
jQuery Selectors: The selector in jQuery is a function that selects nodes i.e. elements from the Document Object Model. In simple words, it is a function, that is used to select/manipulate one or more HTML elements using jQuery. The list of selectors with their basic description & syntax is given below:
Selectors | Description | Syntax |
|---|---|---|
Selects all the elements in the document | $("*") | |
Specifies the class for an element to be selected. | $(".class") | |
Select and modify HTML elements | $("element_name") | |
Specifies an id for an element to be selected. | $("#id") | |
Selects hidden elements to work upon. | $(":hidden") | |
Selects all the elements that are currently visible | $(":visible") | |
Select all elements that are the direct child of parent. | ("parent > child") | |
Selects every descendant of a parent element. | $("parent descendant") | |
Change the state of the element with CSS style. | (selector).animate({styles}, para1, para2, para3); | |
Selects the first element of the specified type. | $(":first") | |
Selects the last element of the specified type. | $(":last") | |
Selects even number index from the elements. | $(":even") | |
Selects odd number index from the elements. | $(":odd") | |
Used to select input elements and button | $(":input") | |
Selects button elements and input elements with type=”button”. | $(":button") | |
Selects elements that are parent of another element. | $(":parent") | |
Elements containing the specified string are selected. | $(":contains(text)") | |
Every element that is the first child of its parent is selected. | $(":first-child") | |
Selects all elements that are the nth-child of their parent. | $("Element:nth-child(Index/even/odd/equation)") | |
Selects element that doesn’t have the specified value. | $("[attribute!='value']") | |
| Selects siblings of specified element | ("element ~ siblings") | |
Selects the just “next” element | $("element + next") |
jQuery Methods: The methods in jQuery can be utilized to set or return the DOM attributes for the specific elements. The list of methods with their description & syntax is given below:
Methods | Descriptions | Syntax |
|---|---|---|
| .prop() | Sets or return properties and values for selected elements. | $(selector).prop(parameters) |
| .removeAttr() | Used to remove attributes from the selected elements. | $(selector).removeAttr(attribute) |
| .removeProp() | Used to remove the property set by prop() method. | $(selector).removeProp(property) |
| .val() | Return or set the value of attribute for selected elements. | $(selector).val() |
| .removeData() | Removes data which was previously set. | $(selector).removeData(args); |
| jQuery.data() | Attaches or gets data for the selected elements. | $(selector).data(parameters); |
| jQuery.hasData() | Checks if an element has any data associated with it. | jQuery.hasData(element) |
| .height() | Checks the height of an element | $("param").height() |
| .innerHeight() | Checks inner height of the element including padding. | $("param").innerHeight() |
| .outerHeight() | Finds total height of element including padding and border | $(selector).outerHeight(includeMargin) |
| .width() | Check the width of an element. | $("param").width() |
| .innerWidth() | Returns the inner width of the element include padding. | $("param").innerWidth() |
| .outerWidth() | Finds total width of element including border & padding. | $(selector).outerWidth( includemargin ) |
| .css() | Changes the style property of the selected element. | $(selector).css(property) |
| .addClass() | Adds more property to each selected element. | $(selector).addClass(className); |
| .removeClass() | Remove class names from the selected element. | $(selector).removeClass(class_name, function(index, current_class_name)) |
| .hasClass() | Check if the elements with specified class name exists | $(selector).hasClass(className); |
| .toggleClass() | Changes the class attached with selected element. | $(selector).toggleClass(class, function, switch) |
| .scrollTop() | Returns the vertical top position of the scrollbar. | $(selector).scrollTop(position) |
| .scrollLeft() | Returns or sets the horizontal position of the scroll bar. | $(selector).scrollLeft(position) |
jQuery Manipulation: The different kinds of methods in jQuery can be used to manipulate the DOM. These methods can be categorized in 2 ways, namely:
The list of methods used for manipulates the DOM is given below:
Methods | Descriptions | Syntax |
|---|---|---|
| .append() | Inserts content at the end of selected elements. | $(selector).append( content, function(index, html) ) |
| .appendTo() | Inserts an HTML element at the end of selected element. | $(content).appendTo(selector) |
| .html() | Sets or returns the innerHTML content of selected element. | $(selector).html(function(index, currentcontent)) |
| .prependTo() | Insert HTML elements or content at the beginning of selected element. | $(content).prepend(selector) |
| .text() | Sets or returns the text content of the element. | $(selector).text(function(index, currentcontent)) |
| .clone() | Makes a copy of selected elements including its child | $(selector).clone() |
| .insertBefore() | Inserts HTML content before a specified element. | $(content).insertBefore(target) |
| .insertAfter() | Inserts some HTML content after specified element. | $(content).insertAfter(target) |
| .detach() | Removes the selected elements from the DOM tree | $(selector).detach() |
| .empty() | Remove all child nodes and their content for selected elements. | $(selector).empty() |
| .remove() | Removes all the selected elements including the text. | $(selector).remove() |
| .replaceWith() | Replaces the selected element with the new one. | $(selector).replaceWith(content, function) |
| .wrapAll() | Used to wrap specified element against all selected elements | $(selector).wrapAll(wrap_element) |
jQuery Traversing: In jQuery, traversing means moving through or over the HTML elements to find, filter, or select a particular or entire element. Based on the traversing, the list of following methods is given below:
Methods | Descriptions | Syntax |
|---|---|---|
| .children() | Finds all the child element related to selected element. | $(selector).children() |
| .next() | Returns the next sibling of the selected element. | $(selector).next() |
| .closest() | Returns the first ancestor of the selected element in DOM tree. | $(selector).closest(parameters); |
| .parent() | Finds the parent element related to the selected element. | $(selector).parent() |
| .prevUntil() | Finds all the previous sibling elements between two elements. | $(selector1).nextUntil(selector2) |
| .siblings() | Finds all siblings elements of the selected element. | $(selector).siblings(function) |
| .first() | Selects the first element from the specified elements. | $(selector).first() |
| .last() | Finds the last element of the specified elements. | $(selector).last() |
| .is() | Checks if one of the selected elements matches selectorElement. | $(selector).is(selectorElement, function(index, element)) |
| .map() | Translates all items in an array or object to a new array. | jQuery.map( array/object, callback ) |
| .filter() | Returns the element which match the criteria. | $(selector).filter(criteria, function(index)) |
| .not() | Returns all element which do not match with selected element | $(selector).not(A) |
| .andSelf() | Adds the previous set of elements to current set. | andSelf( )(selector); |
| .each() | Specifies the function to run for each matched element. | $(selector).each(function(index, element)) |
| .find() | Finds all the descendant elements of selected element. | $(selector).find() |
jQuery Events: Event refers to the actions performed by the site visitor during their interactivity with the website (or webpage). An event can be any of the types which may include the button clicks, mouse pointer movement over the image, any key pressed from the keyboard, etc. The list of the following events with their descriptions is given below:
Events | Descriptions | Syntax |
|---|---|---|
| .error() | Attaches a function to run when an error event occurs | $(selector).error() |
| .resize() | Triggers when the browser window change its size. | $(selector).resize(function) |
| .scroll() | Used to scroll in specified element. | $(selector).scroll(function) |
| .ready() | Loads the whole page then execute the rest code. | $(document).ready(function) |
| .unload() | Performs unload event when user navigates away from current webpage. | $(selector).unload(function) |
| .load() | Loads data from the server and returned it to the selected element. | $(selector).load(URL, data, callback); |
| .die() | Used to removes one or more event handlers, for selected elements. | $(selector).die(event, function) |
| .bind() | Attachs event handlers to selected elements | $(selector).bind(event, data, function); |
| .trigger() | Triggers a specified event handler on selected element. | $(selector).trigger(event,parameters) |
| .triggerHandler() | Used to trigger a specified event for the selected element. | $(selector).triggerHandler(event, param1, param2, ...) |
| .on() | Attaches one or more event handlers for the selected elements and child elements. | $(selector).on(event, childSelector, data, function) |
| .off() | Removes event handlers attached with the on() method. | $(selector).off(event, selector, function(eventObj), map) |
| .one() | Attaches one or more event handlers to the selected element. | $(selector).one(event, data, function) |
| .unbind() | Used to remove any selected event handlers. | $(selector).unbind(event, function, eventObj) |
| .blur() | Used to remove focus from the selected element. | $(selector).blur(function) |
| .focus() | Used to focus on an element. | $(selector).focus(function) |
| .focusin() | Focuses on the selected element. | $(selector).focusin(function); |
| .focusout() | Removes focus from the selected element. | $(selector).focusout(function); |
| .change() | Used to detect the change in value of input fields. | $(selector).change(function) |
| .keydown() | Triggers the keydown event whenever the User presses a key on the keyboard. | $(selector).keydown(function) |
| .keypress() | Triggers the keypress event whenever browser registers a keyboard input. | $(selector).keypress() |
| .keyup() | Used to trigger the keyup event whenever User releases a key from the keyboard. | $(selector).keyup(function) |
| .click() | Starts the click event or attach a function to run when a click event occurs. | $(selector).click(function); |
| .hover() | Specifies functions to start when mouse pointer moves over selected element. | $(selector).hover(Function_in, Function_out); |
| .toggle() | Checks the visibility of selected elements to toggle. | $(selector).toggle(speed, easing, callback) |
| .mouseover() | Works when mouse pointer moves over the selected elements. | $(selector).mouseover(function) |
| event.stopPropagation() | Used to stop the windows propagation. | event.stopPropagation() |
| event.preventDefault() | Used to stop the default action of the selected element to occur. | event.preventDefault() |
jQuery Effects: There are several techniques through which the animation can be implemented on a web page, which are facilitated by the jQuery library. These may include simple or standard animations to customize with sophisticated custom effects. There are various jQuery Effects that can be implemented to customize the effect, which is listed below:
Effects | Descriptions | Syntax |
|---|---|---|
| .hide() | Used to hide the selected element. | $(selector).hide(duration, easing, call_function); |
| .show() | Used to display the hidden and selected elements. | $(selector).show( speed, easing, callback ) |
| .toggle() | Check the visibility of selected elements to toggle | $(selector).toggle(speed, easing, callback) |
| .animate() | Used to change the state of the element with CSS style. | (selector).animate({styles}, para1, para2, para3); |
| .delay() | Sets a timer to delay the execution in the queue. | $(selector).delay(para1, para2); |
| .finish() | Used to stop the animations running at the present time. | $(selector).finish(); |
| .clearQueue() | Removes all items from the queue that have not yet been run. | $(selector).clearQueue(name); |
| .dequeue() | Removes the next function from the queue and executes it. | $(selector).dequeue(name); |
| .fadeIn() | Used to change the opacity of selected elements. | $(selector).fadeIn( speed, easing, callback ) |
| .fadeOut() | Changes the level of opacity for selected element | $(selector).fadeOut( speed, easing, callback ) |
| .fadeTo() | Changes the opacity of the selected element. | $(selector).fadeTo(speed, opacity, easing, call_function) |
| .fadeToggle() | Toggles between the fadeIn() and fadeOut() methods. | $(selector).fadeToggle(speed, easing, callback) |
| .queue() | Used to show the queue of functions to be executed | $(selector).queue(queue_name) |
| .stop() | Used to stop the currently running animations. | $(selector).stop(stopAll, goToEnd); |
jQuery AJAX: The jQuery library provides various methods & functions for AJAX functionality that allows the loading of the data from the server without refreshing the browser page. AJAX operates on the client-side for creating asynchronous web applications. There are some of the jQuery AJAX methods that are used to request text, HTML, XML, or JSON from a remote server using both HTTP Get and HTTP Post, which are listed below:
Methods | Descriptions | Syntax |
|---|---|---|
| jQuery.ajax() | Performs an AJAX request or asynchronous HTTP request. | $.ajax({name:value, name:value, ... }) |
| jQuery.ajaxSetup() | Sets the default values for future AJAX requests. | $.ajaxSetup( {name:value, name:value, ... } ) |
| jQuery.get() | Loads data from the server by using the GET HTTP request. | $.get( url, [data], [callback], [type] ) |
| jQuery.getJSON() | Fetches JSON-encoded data from the server using GET HTTP request. | $(selector).getJSON(url,data,success(data,status,xhr)) |
| jQuery.getScript() | Runs JavaScript using AJAX HTTP GET request. | $(selector).getScript(url, success(response, status)) |
| jQuery.param() | Creates a serialized representation of an object. | $.param( object, trad ) |
| jQuery.post() | Loads the page from the server using a POST HTTP. | $.post( url, data, callback_function, data_type ) |
| .ajaxComplete() | Specifies the functions to run when an AJAX request completes. | $(document).ajaxComplete(function(event, xhr, options)) |
| .ajaxError() | Specifies functions to run when an AJAX request fails. | $(document).ajaxError( function(event, xhr, options, exc) ) |
| .ajaxStart() | Specifies functions to run when an AJAX request starts. | $(document).ajaxStart(function()) |
| .ajaxStop() | Specifies functions to run when AJAX requests have been completed. | $(document).ajaxStop(function()) |
| .load() | Loads data from server and returned into selected element | $(selector).load(URL, data, callback); |
| .serialize() | Creates a text string in standard URL-encoded notation. | $(selector).serialize() |
| .serializeArray() | Create a JavaScript array of objects to be encod as a JSON string. | $(selector).serializeArray() |
jQuery Core: jQuery facilitates the DOM Element Methods, properties, utilities, jQuery Object, Deferred Object, Callbacks Object, etc, to add the functionalities with customization options that help to enhance the overall interactivity of the website. The list of various methods and properties with their descriptions is given below:
Methods/Properties | Descriptions | Syntax |
|---|---|---|
| jQuery.Deferred() | Returns the utility object with methods to register multiple callbacks to queues. | jQuery.Deferred([beforeStart]) |
| deferred.then() | Adds handlers which are called on the Deferred object | deferred.then(doneCallbacks[, failCallbacks][, progressCallbacks]) |
| deferred.done() | Adds handlers which are called when deferred object is resolved. | deferred.done(Callbacks [, Callbacks]) |
| .promise() | Returns a Promise object to be observed when certain actions are ended. | .promise([type][, target]) |
| deferred.always() | Add handlers which are called when Deferred object is resolved or rejected. | deferred.always( alwaysCallbacks [, alwaysCallbacks] ) |
| deferred.fail() | Adds handlers which are to be called when Deferred object is rejected. | deferred.fail(failedCallbacks, failedCallbacks ) |
| .get() | Loads data from the server by using the GET HTTP request. | $.get( url, [data], [callback], [type] ) |
| .index() | Returns the index of the specified elements with respect to selector. | $(selector).index(element) |
| jQuery.when() | Executes callback functions depending on zero or more Thenable objects. | jQuery.when(deferreds) |
| .length | Counts the number of elements of the jQuery object. | $(selector).length |
| jQuery.each() | Specifies the function to run for each matched element. | $(selector).each(function(index, element)) |
| callbacks.fire() | Returns the Callbacks object onto which it is attached (this). | callbacks.fire( arguments ) |
| callbacks.lock() | Locks a callback list in the state. | callbacks.lock() |
jQuery is an open source JavaScript library that simplifies the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript. You can learn JavaScript from the ground up by following this jQuery Tutorial and jQuery Examples.
We have a similar cheat sheet to help you with HTML, CSS & JavaScript concepts as well. Check it out here HTML Cheat Sheet, CSS Cheat Sheet & JavaScript Cheat Sheet.