How to loop each from bottom to top jquery năm 2024

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. If you're new to jQuery, we recommend that you check out the jQuery Learning Center.

If you're updating to a newer version of jQuery, be sure to read the release notes published on our blog. If you're coming from a version prior 1.9, you should check out the 1.9 Upgrade Guide as well.

Note that this is the API documentation for jQuery core. Other projects have API docs in other locations:

  • jQuery UI API docs
  • jQuery Mobile API docs
  • QUnit API docs

Create a new jQuery object with elements added to the set of matched elements.

Add the previous set of elements on the stack to the current set, optionally filtered by a selector.

Adds the specified class(es) to each element in the set of matched elements.

Insert content, specified by the parameter, after each element in the set of matched elements.

Register a handler to be called when Ajax requests complete. This is an AjaxEvent.

Register a handler to be called when Ajax requests complete. This is an AjaxEvent.

Register a handler to be called when Ajax requests complete with an error. This is an Ajax Event.

Register a handler to be called when Ajax requests complete with an error. This is an Ajax Event.

Attach a function to be executed before an Ajax request is sent. This is an Ajax Event.

Attach a function to be executed before an Ajax request is sent. This is an Ajax Event.

Register a handler to be called when the first Ajax request begins. This is an Ajax Event.

Register a handler to be called when the first Ajax request begins. This is an Ajax Event.

Register a handler to be called when all Ajax requests have completed. This is an Ajax Event.

Register a handler to be called when all Ajax requests have completed. This is an Ajax Event.

Attach a function to be executed whenever an Ajax request completes successfully. This is an Ajax Event.

Attach a function to be executed whenever an Ajax request completes successfully. This is an Ajax Event.

Selects all elements.

Add the previous set of elements on the stack to the current set.

Perform a custom animation of a set of CSS properties.

Select all elements that are in the progress of an animation at the time the selector is run.

Insert content, specified by the parameter, to the end of each element in the set of matched elements.

Insert every element in the set of matched elements to the end of the target.

Get the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element.

Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-).

Selects elements that have the specified attribute with a value containing a given substring.

Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.

Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.

Selects elements that have the specified attribute with a value exactly equal to a certain value.

Select elements that either don’t have the specified attribute, or do have the specified attribute but not with a certain value.

Selects elements that have the specified attribute with a value beginning exactly with a given string.

Insert content, specified by the parameter, before each element in the set of matched elements.

Attach a handler to an event for the elements.

Bind an event handler to the “blur” event, or trigger that event on an element.

Bind an event handler to the “blur” event, or trigger that event on an element.

Selects all button elements and elements of type button.

Add a callback or a collection of callbacks to a callback list.

Disable a callback list from doing anything more.

Determine if the callbacks list has been disabled.

Remove all of the callbacks from a list.

Call all of the callbacks with the given arguments.

Determine if the callbacks have already been called at least once.

Call all callbacks in a list with the given context and arguments.

Determine whether or not the list has any callbacks attached. If a callback is provided as an argument, determine whether it is in a list.

Lock a callback list in its current state.

Determine if the callbacks list has been locked.

Remove a callback or a collection of callbacks from a callback list.

Bind an event handler to the “change” event, or trigger that event on an element.

Bind an event handler to the “change” event, or trigger that event on an element.

Selects all elements of type checkbox.

Matches all elements that are checked or selected.

Selects all direct child elements specified by “child” of elements specified by “parent”.

Get the children of each element in the set of matched elements, optionally filtered by a selector.

Selects all elements with the given class.

Remove from the queue all items that have not yet been run.

Bind an event handler to the “click” event, or trigger that event on an element.

Bind an event handler to the “click” event, or trigger that event on an element.

Create a deep copy of the set of matched elements.

For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.

Select all elements that contain the specified text.

Get the children of each element in the set of matched elements, including text and comment nodes.

The DOM node context originally passed to jQuery(); if none was passed then context will likely be the document.

Bind an event handler to the “contextmenu” event, or trigger that event on an element.

Bind an event handler to the “contextmenu” event, or trigger that event on an element.

Get the value of a computed style property for the first element in the set of matched elements or set one or more CSS properties for every matched element.

Store arbitrary data associated with the matched elements or return the value at the named data store for the first element in the set of matched elements.

Bind an event handler to the “dblclick” event, or trigger that event on an element.

Bind an event handler to the “dblclick” event, or trigger that event on an element.

Add handlers to be called when the Deferred object is either resolved or rejected.

Add handlers to be called when the Deferred object is rejected.

Add handlers to be called when the Deferred object is resolved.

Add handlers to be called when the Deferred object is rejected.

Determine whether a Deferred object has been rejected.

Determine whether a Deferred object has been resolved.

Call the progressCallbacks on a Deferred object with the given args.

Call the progressCallbacks on a Deferred object with the given context and args.

Utility method to filter and/or chain Deferreds.

Add handlers to be called when the Deferred object generates progress notifications.

Return a Deferred’s Promise object.

Reject a Deferred object and call any failCallbacks with the given args.

Reject a Deferred object and call any failCallbacks with the given context and args.

Resolve a Deferred object and call any doneCallbacks with the given args.

Resolve a Deferred object and call any doneCallbacks with the given context and args.

Determine the current state of a Deferred object.

Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.

Set a timer to delay execution of subsequent items in the queue.

Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.

Execute the next function on the queue for the matched elements.

Selects all elements that are descendants of a given ancestor.

Remove the set of matched elements from the DOM.

Remove event handlers previously attached using .live() from the elements.

Selects all elements that are disabled.

Iterate over a jQuery object, executing a function for each matched element.

Selects all elements with the given tag name.

Remove all child nodes of the set of matched elements from the DOM.

Select all elements that have no children (including text nodes).

Selects all elements that are enabled.

End the most recent filtering operation in the current chain and return the set of matched elements to its previous state.

Reduce the set of matched elements to the one at the specified index.

Select the element at index n within the matched set.

Bind an event handler to the “error” event, or trigger that event on an element.

Bind an event handler to the “error” event, or trigger that event on an element.

Reduce the set of matched elements to the even ones in the set, numbered from zero.

Selects even elements, zero-indexed. See also :odd.

The current DOM element within the event bubbling phase.

An optional object of data passed to an event method when the current executing handler is bound.

The element where the currently-called jQuery event handler was attached.

Returns whether event.preventDefault() was ever called on this event object.

Returns whether event.stopImmediatePropagation() was ever called on this event object.

Returns whether event.stopPropagation() was ever called on this event object.

Indicates whether the META key was pressed when the event fired.

The namespace specified when the event was triggered.

The mouse position relative to the left edge of the document.

The mouse position relative to the top edge of the document.

If this method is called, the default action of the event will not be triggered.

The other DOM element involved in the event, if any.

The last value returned by an event handler that was triggered by this event, unless the value was undefined.

Keeps the rest of the handlers from being executed and prevents the event from bubbling up the DOM tree.

Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.

The DOM element that initiated the event.

The difference in milliseconds between the time the browser created the event and January 1, 1970.

Describes the nature of the event.

For key or mouse events, this property indicates the specific key or button that was pressed.

Display the matched elements by fading them to opaque.

Hide the matched elements by fading them to transparent.

Adjust the opacity of the matched elements.

Display or hide the matched elements by animating their opacity.

Selects all elements of type file.

Reduce the set of matched elements to those that match the selector or pass the function’s test.

Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.

Stop the currently-running animation, remove all queued animations, and complete all animations for the matched elements.

Reduce the set of matched elements to the first in the set.

Selects all elements that are the first child of their parent.

Selects all elements that are the first among siblings of the same element name.

Selects the first matched DOM element.

Bind an event handler to the “focus” event, or trigger that event on an element.

Selects element if it is currently focused.

Bind an event handler to the “focus” event, or trigger that event on an element.

Bind an event handler to the “focusin” event, or trigger that event on an element.

Bind an event handler to the “focusin” event, or trigger that event on an element.

Bind an event handler to the “focusout” event, or trigger that event on an element.

Bind an event handler to the “focusout” event, or trigger that event on an element.

Retrieve the DOM elements matched by the jQuery object.

Select all elements at an index greater than index within the matched set.

Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.

Selects elements that have the specified attribute, with any value.

Selects elements which contain at least one element that matches the specified selector.

Determine whether any of the matched elements are assigned the given class.

Selects all elements that are headers, like h1, h2, h3 and so on.

Get the current computed height for the first element in the set of matched elements or set the height of every matched element.

Selects all elements that are hidden.

Hide the matched elements.

Bind one or two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements.

Get the HTML contents of the first element in the set of matched elements or set the HTML contents of every matched element.

Selects a single element with the given id attribute.

Selects all elements of type image.

Search for a given element from among the matched elements.

Get the current computed inner height (including padding but not border) for the first element in the set of matched elements or set the inner height of every matched element.

Get the current computed inner width (including padding but not border) for the first element in the set of matched elements or set the inner width of every matched element.

Selects all input, textarea, select and button elements.

Insert every element in the set of matched elements after the target.

Insert every element in the set of matched elements before the target.

Check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments.

Return a collection of matched elements either found in the DOM based on passed argument(s) or created by passing an HTML string.

A string containing the jQuery version number.

Perform an asynchronous HTTP (Ajax) request.

Handle custom Ajax options or modify existing options before each request is sent and before they are processed by $.ajax().

Set default values for future Ajax requests. Its use is not recommended.

Creates an object that handles the actual transmission of Ajax data.

States if the current page, in the user’s browser, is being rendered using the W3C CSS Box Model.

Contains flags for the useragent, read from navigator.userAgent. This property was removed in jQuery 1.9 and is available only through the jQuery.migrate plugin. Please try to use feature detection instead.

A multi-purpose callbacks list object that provides a powerful way to manage callback lists.

Check to see if a DOM element is a descendant of another DOM element.

Hook directly into jQuery to override how particular CSS properties are retrieved or set, normalize CSS property naming, or create custom properties.

An object containing all CSS properties that may be used without a unit. The .css() method uses this object to see if it may append px to unitless values.

Store arbitrary data associated with the specified element and/or return the value that was set.

A factory function that returns a chainable utility object with methods to register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.

Execute the next function on the queue for the matched element.

A generic iterator function, which can be used to seamlessly iterate over both objects and arrays. Arrays and array-like objects with a length property (such as a function’s arguments object) are iterated by numeric index, from 0 to length-1. Other objects are iterated via their named properties.

Takes a string and throws an exception containing it.

Escapes any character that has a special meaning in a CSS selector.

Merge the contents of two or more objects together into the first object.

Merge the contents of an object onto the jQuery prototype to provide new jQuery instance methods.

The rate (in milliseconds) at which animations fire.

Globally disable all animations.

Load data from the server using a HTTP GET request.

Load JSON-encoded data from the server using a GET HTTP request.

Load a JavaScript file from the server using a GET HTTP request, then execute it.

Execute some JavaScript code globally.

Finds the elements of an array which satisfy a filter function. The original array is not affected.

Determine whether an element has any jQuery data associated with it.

Holds or releases the execution of jQuery’s ready event.

Modify and filter HTML strings passed through jQuery manipulation methods.

Search for a specified value within an array and return its index (or -1 if not found).

Determine whether the argument is an array.

Check to see if an object is empty (contains no enumerable properties).

Determines if its argument is callable as a function.

Determines whether its argument represents a JavaScript number.

Check to see if an object is a plain object (created using “{}” or “new Object”).

Determine whether the argument is a window.

Check to see if a DOM node is within an XML document (or is an XML document).

Convert an array-like object into a true JavaScript array.

Translate all items in an array or object to new array of items.

Merge the contents of two arrays together into the first array.

Relinquish jQuery’s control of the $ variable.

An empty function.

Return a number representing the current time.

Create a serialized representation of an array, a plain object, or a jQuery object suitable for use in a URL query string or Ajax request. In case a jQuery object is passed, it should contain input elements with name/value properties.

Parses a string into an array of DOM nodes.

Takes a well-formed JSON string and returns the resulting JavaScript value.

Parses a string into an XML document.

Send data to the server using a HTTP POST request.

Takes a function and returns a new one that will always have a particular context.

Show or manipulate the queue of functions to be executed on the matched element.

A Promise-like object (or “thenable”) that resolves when the document is ready.

Handles errors thrown synchronously in functions wrapped in jQuery().

Remove a previously-stored piece of data.

Creates an object containing a set of properties ready to be used in the definition of custom animations.

Creates a new copy of jQuery whose properties and methods can be modified without affecting the original jQuery object.

A collection of properties that represent the presence of different browser features or bugs; intended for jQuery’s internal use.

Remove the whitespace from the beginning and end of a string.

Determine the internal JavaScript [[Class]] of an object.

Sorts an array of DOM elements, in place, with the duplicates removed. Note that this only works on arrays of DOM elements, not strings or numbers.

Sorts an array or an array-like object of DOM elements, in place, with the duplicates removed. Note that this only works on arrays/array-likes of DOM elements, not strings or numbers.

Provides a way to execute callback functions based on zero or more Thenable objects, usually Deferred objects that represent asynchronous events.

Bind an event handler to the “keydown” event, or trigger that event on an element.

Bind an event handler to the “keydown” event, or trigger that event on an element.

Bind an event handler to the “keypress” event, or trigger that event on an element.

Bind an event handler to the “keypress” event, or trigger that event on an element.

Bind an event handler to the “keyup” event, or trigger that event on an element.

Bind an event handler to the “keyup” event, or trigger that event on an element.

Selects all elements of the specified language.

Reduce the set of matched elements to the final one in the set.

Selects all elements that are the last child of their parent.

Selects all elements that are the last among siblings of the same element name.

Selects the last matched element.

The number of elements in the jQuery object.

Attach an event handler for all elements which match the current selector, now and in the future.

Load data from the server and place the returned HTML into the matched elements.

Bind an event handler to the “load” event, or trigger that event on an element.

Bind an event handler to the “load” event, or trigger that event on an element.

Select all elements at an index less than index within the matched set.

Pass each element in the current matched set through a function, producing a new jQuery object containing the return values.

Bind an event handler to the “mousedown” event, or trigger that event on an element.

Bind an event handler to the “mousedown” event, or trigger that event on an element.

Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element.

Bind an event handler to the “mouseenter” event, or trigger that event on an element.

Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element.

Bind an event handler to the “mouseleave” event, or trigger that event on an element.

Bind an event handler to the “mousemove” event, or trigger that event on an element.

Bind an event handler to the “mousemove” event, or trigger that event on an element.

Bind an event handler to the “mouseout” event, or trigger that event on an element.

Bind an event handler to the “mouseout” event, or trigger that event on an element.

Bind an event handler to the “mouseover” event, or trigger that event on an element.

Bind an event handler to the “mouseover” event, or trigger that event on an element.

Bind an event handler to the “mouseup” event, or trigger that event on an element.

Bind an event handler to the “mouseup” event, or trigger that event on an element.

Matches elements that match all of the specified attribute filters.

Selects the combined results of all the specified selectors.

Get the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling only if it matches that selector.

Selects all next elements matching “next” that are immediately preceded by a sibling “prev”.

Selects all sibling elements that follow after the “prev” element, have the same parent, and match the filtering “siblings” selector.

Get all following siblings of each element in the set of matched elements, optionally filtered by a selector.

Get all following siblings of each element up to but not including the element matched by the selector, DOM node, or jQuery object passed.

Remove elements from the set of matched elements.

Selects all elements that do not match the given selector.

Selects all elements that are the nth-child of their parent.

Selects all elements that are the nth-child of their parent, counting from the last element to the first.

Selects all the elements that are the nth-child of their parent in relation to siblings with the same element name, counting from the last element to the first.

Selects all elements that are the nth child of their parent in relation to siblings with the same element name.

Reduce the set of matched elements to the odd ones in the set, numbered from zero.

Selects odd elements, zero-indexed. See also :even.

Remove an event handler.

Get the current coordinates of the first element, or set the coordinates of every element, in the set of matched elements, relative to the document.

Get the closest ancestor element that is positioned.

Attach an event handler function for one or more events to the selected elements.

Attach a handler to an event for the elements. The handler is executed at most once per element per event type.

Selects all elements that are the only child of their parent.

Selects all elements that have no siblings with the same element name.

Get the current computed outer height (including padding, border, and optionally margin) for the first element in the set of matched elements or set the outer height of every matched element.

Get the current computed outer width (including padding, border, and optionally margin) for the first element in the set of matched elements or set the outer width of every matched element.

Get the parent of each element in the current set of matched elements, optionally filtered by a selector.

Select all elements that have at least one child node (either an element or text).

Get the ancestors of each element in the current set of matched elements, optionally filtered by a selector.

Get the ancestors of each element in the current set of matched elements, up to but not including the element matched by the selector, DOM node, or jQuery object.

Selects all elements of type password.

Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.

Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.

Insert every element in the set of matched elements to the beginning of the target.

Get the immediately preceding sibling of each element in the set of matched elements. If a selector is provided, it retrieves the previous sibling only if it matches that selector.

Get all preceding siblings of each element in the set of matched elements, optionally filtered by a selector, in the reverse document order.

Get all preceding siblings of each element up to but not including the element matched by the selector, DOM node, or jQuery object.

Return a Promise object to observe when all actions of a certain type bound to the collection, queued or not, have finished.

Get the value of a property for the first element in the set of matched elements or set one or more properties for every matched element.

Add a collection of DOM elements onto the jQuery stack.

Show or manipulate the queue of functions to be executed on the matched elements.

Selects all elements of type radio.

Specify a function to execute when the DOM is fully loaded.

Remove the set of matched elements from the DOM.

Remove an attribute from each element in the set of matched elements.

Remove a single class, multiple classes, or all classes from each element in the set of matched elements.

Remove a previously-stored piece of data.

Remove a property for the set of matched elements.

Replace each target element with the set of matched elements.

Replace each element in the set of matched elements with the provided new content and return the set of elements that was removed.

Selects all elements of type reset.

Bind an event handler to the “resize” event, or trigger that event on an element.

Bind an event handler to the “resize” event, or trigger that event on an element.

Selects the element that is the root of the document.

Bind an event handler to the “scroll” event, or trigger that event on an element.

Bind an event handler to the “scroll” event, or trigger that event on an element.

Get the current horizontal position of the scroll bar for the first element in the set of matched elements or set the horizontal position of the scroll bar for every matched element.

Get the current vertical position of the scroll bar for the first element in the set of matched elements or set the vertical position of the scroll bar for every matched element.

Bind an event handler to the “select” event, or trigger that event on an element.

Bind an event handler to the “select” event, or trigger that event on an element.

Selects all elements that are selected.

A selector representing selector passed to jQuery(), if any, when creating the original set.

Encode a set of form elements as a string for submission.

Encode a set of form elements as an array of names and values.

Display the matched elements.

Get the siblings of each element in the set of matched elements, optionally filtered by a selector.

Return the number of elements in the jQuery object.

Reduce the set of matched elements to a subset specified by a range of indices.

Display the matched elements with a sliding motion.

Display or hide the matched elements with a sliding motion.

Hide the matched elements with a sliding motion.

Stop the currently-running animation on the matched elements.

Bind an event handler to the “submit” event, or trigger that event on an element.

Selects all elements of type submit.

Bind an event handler to the “submit” event, or trigger that event on an element.

Selects the target element indicated by the fragment identifier of the document’s URI.

Get the combined text contents of each element in the set of matched elements, including their descendants, or set the text contents of the matched elements.

Selects all input elements of type text.

Retrieve all the elements contained in the jQuery set, as an array.

Display or hide the matched elements.

Bind two or more handlers to the matched elements, to be executed on alternate clicks.

Add or remove one or more classes from each element in the set of matched elements, depending on either the class’s presence or the value of the state argument.

Execute all handlers and behaviors attached to the matched elements for the given event type.

Execute all handlers attached to an element for an event.

Remove a previously-attached event handler from the elements.

Remove a handler from the event for all elements which match the current selector, based upon a specific set of root elements.

Sorts a jQuery object of DOM elements, in place, with the duplicates removed. Note that this only works on jQuery objects consisting of DOM elements, not strings or numbers.

Bind an event handler to the “unload” event, or trigger that event on an element.

Bind an event handler to the “unload” event, or trigger that event on an element.

Remove the parents of the set of matched elements from the DOM, leaving the matched elements in their place.

Get the current value of the first element in the set of matched elements or set the value of every matched element.

Selects all elements that are visible.

Get the current computed width for the first element in the set of matched elements or set the width of every matched element.

How to loop through a list of elements in jQuery?

jQuery.each() eg. var numbers = [1, 2, 3, 4]; $.each(numbers,function(index, value) ... .

for loop. eg. var numbers = [1, 2, 3, 4]; for(var i = 0; i < numbers.length; i++) ... .

for in. eg. var numbers = [1, 2, 3, 4]; ... .

for of. eg. var numbers = [1, 2, 3, 4]; ... .

forEach. eg. var numbers = [1, 2, 3, 4]; ... .

$.grep().

How to run each function in jQuery?

jQuery each() method. The each() method in jQuery specifies a function that runs for every matched element. It is one of the widely used traversing methods in JQuery. Using this method, we can iterate over the DOM elements of the jQuery object and can execute a function for every matched element.

How to break a loop in JQ?

To break a $. each or $(selector). each loop, you have to return false in the loop callback. Returning true skips to the next iteration, equivalent to a continue in a normal loop.

How do you exit a function in jQuery?

The proper way to exit a function is to use 'return'. If you want the . each() loop to stop immediately, you should 'return false'.