Getting Started
Including jQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
Official CDN
<script src="https://code.jquery.com/jquery-3.5.1.min.js" crossorigin="anonymous"></script>
jQuery syntax
$(selector).methodOrFunction();
Example:
$('#menu').on('click', () =>{
$(this).hide();
});
$("body").css("background", "red");
jQuery document ready
$(document).ready(function() {
// Runs after the DOM is loaded.
alert('DOM fully loaded!');
});
$(function(){
// Runs after the DOM is loaded.
alert('DOM fully loaded!');
});
jQuery Selectors
Examples {.secondary}
$("button").click(() => {
$(":button").css("color", "red");
});
Combining selectors
$("selector1, selector2 ...selectorn")
Basics
- * (opens in a new tab){data-tooltip="Selects all elements."}
- .class (opens in a new tab){data-tooltip="Selects all elements with the given class. "}
- element (opens in a new tab){data-tooltip="Selects all elements with the given tag name."}
- #id (opens in a new tab){data-tooltip="Selects a single element with the given id attribute. "}
- :hidden (opens in a new tab){data-tooltip="Selects all elements that are hidden."}
- :visible (opens in a new tab){data-tooltip="Selects all elements that are visible."}
- :contains() (opens in a new tab){data-tooltip="Select all elements that contain the specified text."}
- :empty (opens in a new tab){data-tooltip="Select all elements that have no children (including text nodes)."}
- :has() (opens in a new tab){data-tooltip="Selects elements which contain at least one element that matches the specified selector."}
- :parent (opens in a new tab){data-tooltip="Select all elements that have at least one child node (either an element or text)."}
- parent > child (opens in a new tab){data-tooltip="Selects all direct child elements specified by child of elements specified by parent."}
- ancestor descendant (opens in a new tab){data-tooltip="Selects all elements that are descendants of a given ancestor."}
- prev + next (opens in a new tab){data-tooltip="Selects all next elements matching next that are immediately preceded by a sibling prev."}
- prev ~ siblings (opens in a new tab){data-tooltip="Selects all sibling elements that follow after the prev element, have the same parent, and match the filtering siblings selector."} {.col-span-2} {.marker-none .cols-3}
Basic Filters
- :animated (opens in a new tab){data-tooltip="Select all elements that are in the progress of an animation at the time the selector is run."}
- :eq() (opens in a new tab){data-tooltip="Select the element at index n within the matched set."}
- :even (opens in a new tab){data-tooltip="Selects even elements, zero-indexed. See also :odd."}
- :first (opens in a new tab){data-tooltip="Selects the first matched DOM element."}
- :gt() (opens in a new tab){data-tooltip="Select all elements at an index greater than index within the matched set."}
- :header (opens in a new tab){data-tooltip="Selects all elements that are headers, like h1, h2, h3 and so on."}
- :lang() (opens in a new tab){data-tooltip="Selects all elements of the specified language."}
- :last (opens in a new tab){data-tooltip="Selects the last matched element."}
- :lt() (opens in a new tab){data-tooltip="Select all elements at an index less than index within the matched set."}
- :not() (opens in a new tab){data-tooltip="Selects all elements that do not match the given selector."}
- :odd (opens in a new tab){data-tooltip="Selects odd elements, zero-indexed. See also :even."}
- :root (opens in a new tab){data-tooltip="Selects the element that is the root of the document."}
- :target (opens in a new tab){data-tooltip="Selects the target element indicated by the fragment identifier of the document's URI."} {.marker-none .cols-3}
Attribute
- [name|="value"] (opens in a new tab){data-tooltip="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 (-)."}
- [name*="value"] (opens in a new tab){data-tooltip="Selects elements that have the specified attribute with a value containing a given substring."}
- [name~="value"] (opens in a new tab){data-tooltip="Selects elements that have the specified attribute with a value containing a given word, delimited by spaces."}
- [name$="value"] (opens in a new tab){data-tooltip="Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive."}
- [name="value"] (opens in a new tab){data-tooltip="Selects elements that have the specified attribute with a value exactly equal to a certain value."}
- [name!="value"] (opens in a new tab){data-tooltip="Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value."}
- [name^="value"] (opens in a new tab){data-tooltip="Selects elements that have the specified attribute with a value beginning exactly with a given string."}
- [name] (opens in a new tab){data-tooltip="Selects elements that have the specified attribute, with any value. "}
- [name="value"][name2="value2"] (opens in a new tab){data-tooltip="Matches elements that match all of the specified attribute filters."} {.col-span-2} {.marker-none .cols-2}
Child Filters
- :first-child (opens in a new tab){data-tooltip="Selects all elements that are the first child of their parent."}
- :first-of-type (opens in a new tab){data-tooltip="Selects all elements that are the first among siblings of the same element name."}
- :last-child (opens in a new tab){data-tooltip="Selects all elements that are the last child of their parent."}
- :last-of-type (opens in a new tab){data-tooltip="Selects all elements that are the last among siblings of the same element name."}
- :nth-child() (opens in a new tab){data-tooltip="Selects all elements that are the nth-child of their parent."}
- :nth-last-child() (opens in a new tab){data-tooltip="Selects all elements that are the nth-child of their parent, counting from the last element to the first."}
- :nth-last-of-type() (opens in a new tab){data-tooltip="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."}
- :nth-of-type() (opens in a new tab){data-tooltip="Selects all elements that are the nth child of their parent in relation to siblings with the same element name."}
- :only-child (opens in a new tab){data-tooltip="Selects all elements that are the only child of their parent."}
- :only-of-type() (opens in a new tab){data-tooltip="Selects all elements that have no siblings with the same element name."} {.marker-none .cols-2}
Forms
- :button (opens in a new tab){data-tooltip="Selects all button elements and elements of type button."}
- :checkbox (opens in a new tab){data-tooltip="Selects all elements of type checkbox."}
- :checked (opens in a new tab){data-tooltip="Matches all elements that are checked or selected."}
- :disabled (opens in a new tab){data-tooltip="Selects all elements that are disabled."}
- :enabled (opens in a new tab){data-tooltip="Selects all elements that are enabled."}
- :focus (opens in a new tab){data-tooltip="Selects element if it is currently focused."}
- :file (opens in a new tab){data-tooltip="Selects all elements of type file."}
- :image (opens in a new tab){data-tooltip="Selects all elements of type image."}
- :input (opens in a new tab){data-tooltip="Selects all input, textarea, select and button elements."}
- :password (opens in a new tab){data-tooltip="Selects all elements of type password."}
- :radio (opens in a new tab){data-tooltip="Selects all elements of type radio."}
- :reset (opens in a new tab){data-tooltip="Selects all elements of type reset."}
- :selected (opens in a new tab){data-tooltip="Selects all elements that are selected."}
- :submit (opens in a new tab){data-tooltip="Selects all elements of type submit."}
- :text (opens in a new tab){data-tooltip="Selects all input elements of type text."} {.marker-none .cols-3}
jQuery Attributes
Examples {.secondary .row-span-2}
$('h2').css({
color: 'blue',
backgroundColor: 'gray',
fontSize: '24px'
});
jQuery addClass
$('.button').addClass('active');
jQuery removeClass
$('.button').on('mouseleave', evt => {
let e = evt.currentTarget;
$(e).removeClass('active');
});
jQuery .toggleClass
$('.choice').toggleClass('highlighted');
Attributes
- .attr() (opens in a new tab){data-tooltip="Get the value of an attribute for the first element in the set of matched elements."}
- .prop() (opens in a new tab){data-tooltip="Get the value of a property for the first element in the set of matched elements."}
- .removeAttr() (opens in a new tab){data-tooltip="Remove an attribute from each element in the set of matched elements."}
- .removeProp() (opens in a new tab){data-tooltip="Remove a property for the set of matched elements."}
- .val() (opens in a new tab){data-tooltip="Get the current value of the first element in the set of matched elements."} {.marker-none .cols-2}
Data
- jQuery.data() (opens in a new tab){data-tooltip="Store arbitrary data associated with the specified element. Returns the value that was set."}
- .data() (opens in a new tab){data-tooltip="Store arbitrary data associated with the matched elements."}
- jQuery.hasData() (opens in a new tab){data-tooltip="Determine whether an element has any jQuery data associated with it."}
- jQuery.removeData() (opens in a new tab){data-tooltip="Remove a previously-stored piece of data."}
- .removeData() (opens in a new tab){data-tooltip="Remove a previously-stored piece of data."} {.marker-none .cols-2}
CSS
- .addClass() (opens in a new tab){data-tooltip="Adds the specified class(es) to each element in the set of matched elements."}
- .hasClass() (opens in a new tab){data-tooltip="Determine whether any of the matched elements are assigned the given class."}
- .removeClass() (opens in a new tab){data-tooltip="Remove a single class, multiple classes, or all classes from each element in the set of matched elements."}
- .toggleClass() (opens in a new tab){data-tooltip="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."}
- .css() (opens in a new tab){data-tooltip="Get the computed style properties for the first element in the set of matched elements."}
- jQuery.cssHooks (opens in a new tab){data-tooltip="Hook directly into jQuery to override how particular CSS properties are retrieved or set, normalize CSS property naming, or create custom properties."}
- jQuery.cssNumber (opens in a new tab){data-tooltip="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."}
- jQuery.escapeSelector() (opens in a new tab){data-tooltip="Escapes any character that has a special meaning in a CSS selector."} {.marker-none .cols-2}
Dimensions
- .height() (opens in a new tab){data-tooltip="Get the current computed height for the first element in the set of matched elements."}
- .innerHeight() (opens in a new tab){data-tooltip="Get the current computed height for the first element in the set of matched elements, including padding but not border."}
- .innerWidth() (opens in a new tab){data-tooltip="Get the current computed inner width for the first element in the set of matched elements, including padding but not border."}
- .outerHeight() (opens in a new tab){data-tooltip="Get the current computed outer height (including padding, border, and optionally margin) for the first element in the set of matched elements."}
- .outerWidth() (opens in a new tab){data-tooltip="Get the current computed outer width (including padding, border, and optionally margin) for the first element in the set of matched elements."}
- .width() (opens in a new tab){data-tooltip="Get the current computed width for the first element in the set of matched elements."} {.marker-none .cols-2}
Offset
- .offset() (opens in a new tab){data-tooltip="Get the current coordinates of the first element in the set of matched elements, relative to the document."}
- .offsetParent() (opens in a new tab){data-tooltip="Get the closest ancestor element that is positioned."}
- .position() (opens in a new tab){data-tooltip="Get the current coordinates of the first element in the set of matched elements, relative to the offset parent."}
- .scrollLeft() (opens in a new tab){data-tooltip="Get the current horizontal position of the scroll bar for the first element in the set of matched elements."}
- .scrollTop() (opens in a new tab){data-tooltip="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."} {.marker-none .cols-2}
jQuery Manipulation
Examples {.secondary .row-span-3}
/*<span>Span.</span>*/
$('span').after('<p>Paragraph.</p>');
/*<span>Span.</span><p>Paragraph.</p>*/
/*<span>Span.</span>*/
$('<span>Span.</span>').replaceAll('p');
/*<p>Span.</p>*/
/*<span>This is span.</span>*/
$('span').wrap('<p></p>');
/*<p><span>This is span.</span></p>*/
Copying
- .clone() (opens in a new tab){data-tooltip="Create a deep copy of the set of matched elements."} {.marker-none .cols-3}
DOM Insertion, Around
- .wrap() (opens in a new tab){data-tooltip="Wrap an HTML structure around each element in the set of matched elements."}
- .wrapAll() (opens in a new tab){data-tooltip="Wrap an HTML structure around all elements in the set of matched elements."}
- .wrapInner() (opens in a new tab){data-tooltip="Wrap an HTML structure around the content of each element in the set of matched elements."} {.marker-none .cols-3}
DOM Insertion, Inside
- .append() (opens in a new tab){data-tooltip="Insert content, specified by the parameter, to the end of each element in the set of matched elements."}
- .appendTo() (opens in a new tab){data-tooltip="Insert every element in the set of matched elements to the end of the target."}
- .html() (opens in a new tab){data-tooltip="Get the HTML contents of the first element in the set of matched elements."}
- .prepend() (opens in a new tab){data-tooltip="Insert content, specified by the parameter, to the beginning of each element in the set of matched elements."}
- .prependTo() (opens in a new tab){data-tooltip="Insert every element in the set of matched elements to the beginning of the target."}
- .text() (opens in a new tab){data-tooltip="Get the combined text contents of each element in the set of matched elements, including their descendants."} {.marker-none .cols-3}
DOM Insertion, Outside
- .after() (opens in a new tab){data-tooltip="Insert content, specified by the parameter, after each element in the set of matched elements."}
- .before() (opens in a new tab){data-tooltip="Insert content, specified by the parameter, before each element in the set of matched elements."}
- .insertAfter() (opens in a new tab){data-tooltip="Insert every element in the set of matched elements after the target."}
- .insertBefore() (opens in a new tab){data-tooltip="Insert every element in the set of matched elements before the target."} {.marker-none .cols-3}
DOM Removal
- .detach() (opens in a new tab){data-tooltip="Remove the set of matched elements from the DOM."}
- .empty() (opens in a new tab){data-tooltip="Remove all child nodes of the set of matched elements from the DOM."}
- .remove() (opens in a new tab){data-tooltip="Remove the set of matched elements from the DOM."}
- .unwrap() (opens in a new tab){data-tooltip="Remove the parents of the set of matched elements from the DOM, leaving the matched elements in their place."} {.marker-none .cols-3}
DOM Replacement
- .replaceAll() (opens in a new tab){data-tooltip="Replace each target element with the set of matched elements."}
- .replaceWith() (opens in a new tab){data-tooltip="Replace each element in the set of matched elements with the provided new content and return the set of elements that was removed."} {.marker-none .cols-3}
jQuery Traversing
Filtering
- .eq() (opens in a new tab){data-tooltip="Reduce the set of matched elements to the one at the specified index."}
- .filter() (opens in a new tab){data-tooltip="Reduce the set of matched elements to those that match the selector or pass the function's test. "}
- .first() (opens in a new tab){data-tooltip="Reduce the set of matched elements to the first in the set."}
- .has() (opens in a new tab){data-tooltip="Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element."}
- .is() (opens in a new tab){data-tooltip="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."}
- .last() (opens in a new tab){data-tooltip="Reduce the set of matched elements to the final one in the set."}
- .map() (opens in a new tab){data-tooltip="Pass each element in the current matched set through a function, producing a new jQuery object containing the return values."}
- .not() (opens in a new tab){data-tooltip="Remove elements from the set of matched elements."}
- .slice() (opens in a new tab){data-tooltip="Reduce the set of matched elements to a subset specified by a range of indices."} {.marker-none .cols-3}
Miscellaneous Traversing
- .add() (opens in a new tab){data-tooltip="Create a new jQuery object with elements added to the set of matched elements."}
- .addBack() (opens in a new tab){data-tooltip="Add the previous set of elements on the stack to the current set, optionally filtered by a selector."}
- .andSelf() (opens in a new tab){data-tooltip="Add the previous set of elements on the stack to the current set."}
- .contents() (opens in a new tab){data-tooltip="Get the children of each element in the set of matched elements, including text and comment nodes."}
- .each() (opens in a new tab){data-tooltip="Iterate over a jQuery object, executing a function for each matched element. "}
- .end() (opens in a new tab){data-tooltip="End the most recent filtering operation in the current chain and return the set of matched elements to its previous state."} {.marker-none .cols-3}
Tree Traversal
- .children() (opens in a new tab){data-tooltip="Get the children of each element in the set of matched elements, optionally filtered by a selector."}
- .closest() (opens in a new tab){data-tooltip="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."}
- .find() (opens in a new tab){data-tooltip="Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element."}
- .next() (opens in a new tab){data-tooltip="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."}
- .nextAll() (opens in a new tab){data-tooltip="Get all following siblings of each element in the set of matched elements, optionally filtered by a selector."}
- .nextUntil() (opens in a new tab){data-tooltip="Get all following siblings of each element up to but not including the element matched by the selector, DOM node, or jQuery object passed."}
- .parent() (opens in a new tab){data-tooltip="Get the parent of each element in the current set of matched elements, optionally filtered by a selector."}
- .parents() (opens in a new tab){data-tooltip="Get the ancestors of each element in the current set of matched elements, optionally filtered by a selector."}
- .parentsUntil() (opens in a new tab){data-tooltip="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."}
- .prev() (opens in a new tab){data-tooltip="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."}
- .prevAll() (opens in a new tab){data-tooltip="Get all preceding siblings of each element in the set of matched elements, optionally filtered by a selector."}
- .prevUntil() (opens in a new tab){data-tooltip="Get all preceding siblings of each element up to but not including the element matched by the selector, DOM node, or jQuery object."}
- .siblings() (opens in a new tab){data-tooltip="Get the siblings of each element in the set of matched elements, optionally filtered by a selector."} {.marker-none .cols-3}
jQuery Events
Examples {.secondary .row-span-6}
// A mouse event 'click'
$('#menu-button').on('click', () => {
$('#menu').show();
});
// A keyboard event 'keyup'
$('#textbox').on('keyup', () => {
$('#menu').show();
});
// A scroll event 'scroll'
$('#menu-button').on('scroll', () => {
$('#menu').show();
});
Event object
$('#menu').on('click', event => {
$(event.currentTarget).hide();
});
Method chaining
$('#menu-btn').on('mouseenter', () => {
$('#menu').show();
}).on('mouseleave', () => {
$('#menu').hide();
});
Prevents the event
$( "p" ).click(function( event ) {
event.stopPropagation();
// Do something
});
Browser Events
- .error() (opens in a new tab){data-tooltip="Bind an event handler to the error JavaScript event."}
- .resize() (opens in a new tab){data-tooltip="Bind an event handler to the resize JavaScript event, or trigger that event on an element."}
- .scroll() (opens in a new tab){data-tooltip="Bind an event handler to the scroll JavaScript event, or trigger that event on an element."} {.marker-none .cols-3}
Event Object {.row-span-6}
- event.currentTarget (opens in a new tab){data-tooltip=" The current DOM element within the event bubbling phase. "}
- event.delegateTarget (opens in a new tab){data-tooltip="The element where the currently-called jQuery event handler was attached."}
- event.data (opens in a new tab){data-tooltip="An optional object of data passed to an event method when the current executing handler is bound. "}
- event.isDefaultPrevented() (opens in a new tab){data-tooltip="Returns whether event.preventDefault() was ever called on this event object. "}
- event.isImmediatePropagationStopped() (opens in a new tab){data-tooltip=" Returns whether event.stopImmediatePropagation() was ever called on this event object. "}
- event.isPropagationStopped() (opens in a new tab){data-tooltip=" Returns whether event.stopPropagation() was ever called on this event object. "}
- event.metaKey (opens in a new tab){data-tooltip="Indicates whether the META key was pressed when the event fired."}
- event.namespace (opens in a new tab){data-tooltip="The namespace specified when the event was triggered."}
- event.pageX (opens in a new tab){data-tooltip="The mouse position relative to the left edge of the document."}
- event.pageY (opens in a new tab){data-tooltip="The mouse position relative to the top edge of the document."}
- event.preventDefault() (opens in a new tab){data-tooltip="If this method is called, the default action of the event will not be triggered."}
- event.relatedTarget (opens in a new tab){data-tooltip="The other DOM element involved in the event, if any."}
- event.result (opens in a new tab){data-tooltip="The last value returned by an event handler that was triggered by this event, unless the value was undefined."}
- event.stopImmediatePropagation() (opens in a new tab){data-tooltip="Keeps the rest of the handlers from being executed and prevents the event from bubbling up the DOM tree."}
- event.stopPropagation() (opens in a new tab){data-tooltip="Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event."}
- event.target (opens in a new tab){data-tooltip=" The DOM element that initiated the event. "}
- event.timeStamp (opens in a new tab){data-tooltip="The difference in milliseconds between the time the browser created the event and January 1, 1970."}
- event.type (opens in a new tab){data-tooltip="Describes the nature of the event."}
- event.which (opens in a new tab){data-tooltip="For key or mouse events, this property indicates the specific key or button that was pressed."} {.marker-none .cols-1}
Document Loading
- .load() (opens in a new tab){data-tooltip="Bind an event handler to the load JavaScript event."}
- .ready() (opens in a new tab){data-tooltip="Specify a function to execute when the DOM is fully loaded."}
- .unload() (opens in a new tab){data-tooltip="Bind an event handler to the unload JavaScript event."} {.marker-none .cols-3}
Event Handler Attachment
- .bind() (opens in a new tab){data-tooltip="Attach a handler to an event for the elements."}
- .delegate() (opens in a new tab){data-tooltip="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."}
- .die() (opens in a new tab){data-tooltip="Remove event handlers previously attached using .live() from the elements."}
- .live() (opens in a new tab){data-tooltip="Attach an event handler for all elements which match the current selector, now and in the future."}
- .off() (opens in a new tab){data-tooltip="Remove an event handler."}
- .on() (opens in a new tab){data-tooltip="Attach an event handler function for one or more events to the selected elements."}
- .one() (opens in a new tab){data-tooltip="Attach a handler to an event for the elements. The handler is executed at most once per element per event type."}
- .trigger() (opens in a new tab){data-tooltip="Execute all handlers and behaviors attached to the matched elements for the given event type."}
- .triggerHandler() (opens in a new tab){data-tooltip="Execute all handlers attached to an element for an event."}
- .unbind() (opens in a new tab){data-tooltip="Remove a previously-attached event handler from the elements."}
- .undelegate() (opens in a new tab){data-tooltip="Remove a handler from the event for all elements which match the current selector, based upon a specific set of root elements."} {.marker-none .cols-3}
Form Events
- .blur() (opens in a new tab){data-tooltip="Bind an event handler to the blur JavaScript event, or trigger that event on an element."}
- .change() (opens in a new tab){data-tooltip="Bind an event handler to the change JavaScript event, or trigger that event on an element."}
- .focus() (opens in a new tab){data-tooltip="Bind an event handler to the focus JavaScript event, or trigger that event on an element."}
- .focusin() (opens in a new tab){data-tooltip="Bind an event handler to the focusin event."}
- .focusout() (opens in a new tab){data-tooltip="Bind an event handler to the focusout JavaScript event."}
- .select() (opens in a new tab){data-tooltip="Bind an event handler to the select JavaScript event, or trigger that event on an element."}
- .submit() (opens in a new tab){data-tooltip="Bind an event handler to the submit JavaScript event, or trigger that event on an element."} {.marker-none .cols-3}
Keyboard Events
- .keydown() (opens in a new tab){data-tooltip="Bind an event handler to the keydown JavaScript event, or trigger that event on an element."}
- .keypress() (opens in a new tab){data-tooltip="Bind an event handler to the keypress JavaScript event, or trigger that event on an element."}
- .keyup() (opens in a new tab){data-tooltip="Bind an event handler to the keyup JavaScript event, or trigger that event on an element."} {.marker-none .cols-3}
Mouse Events
- .click() (opens in a new tab){data-tooltip="Bind an event handler to the click JavaScript event, or trigger that event on an element."}
- .contextMenu() (opens in a new tab){data-tooltip="Bind an event handler to the contextmenu JavaScript event, or trigger that event on an element."}
- .dblclick() (opens in a new tab){data-tooltip="Bind an event handler to the dblclick JavaScript event, or trigger that event on an element."}
- .hover() (opens in a new tab){data-tooltip="Bind two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements."}
- .mousedown() (opens in a new tab){data-tooltip="Bind an event handler to the mousedown JavaScript event, or trigger that event on an element."}
- .mouseenter() (opens in a new tab){data-tooltip="Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element."}
- .mouseleave() (opens in a new tab){data-tooltip="Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element."}
- .mousemove() (opens in a new tab){data-tooltip="Bind an event handler to the mousemove JavaScript event, or trigger that event on an element."}
- .mouseout() (opens in a new tab){data-tooltip="Bind an event handler to the mouseout JavaScript event, or trigger that event on an element."}
- .mouseover() (opens in a new tab){data-tooltip="Bind an event handler to the mouseover JavaScript event, or trigger that event on an element."}
- .mouseup() (opens in a new tab){data-tooltip="Bind an event handler to the mouseup JavaScript event, or trigger that event on an element."}
- .toggle() (opens in a new tab){data-tooltip="Bind two or more handlers to the matched elements, to be executed on alternate clicks."} {.marker-none .cols-3}
jQuery Effects
Examples {.secondary .row-span-2}
$('#menu-button').on('click', () => {
// $('#menu').fadeIn(400, 'swing')
$('#menu').fadeIn();
});
fadeOut effect
$('#menu-button').on('click', () => {
// $('#menu').fadeOut(400, 'swing')
$('#menu').fadeOut();
});
Basics
- .hide() (opens in a new tab){data-tooltip="Hide the matched elements."}
- .show() (opens in a new tab){data-tooltip="Display the matched elements."}
- .toggle() (opens in a new tab){data-tooltip="Display or hide the matched elements."} {.marker-none .cols-3}
Sliding
- .slideDown() (opens in a new tab){data-tooltip="Display the matched elements with a sliding motion."}
- .slideToggle() (opens in a new tab){data-tooltip="Display or hide the matched elements with a sliding motion."}
- .slideUp() (opens in a new tab){data-tooltip="Hide the matched elements with a sliding motion."} {.marker-none .cols-3}
Custom
- .animate() (opens in a new tab){data-tooltip="Perform a custom animation of a set of CSS properties."}
- .clearQueue() (opens in a new tab){data-tooltip="Remove from the queue all items that have not yet been run."}
- .delay() (opens in a new tab){data-tooltip="Set a timer to delay execution of subsequent items in the queue."}
- .dequeue() (opens in a new tab){data-tooltip="Execute the next function on the queue for the matched elements."}
- jQuery.dequeue() (opens in a new tab){data-tooltip="Execute the next function on the queue for the matched element."}
- .finish() (opens in a new tab){data-tooltip="Stop the currently-running animation, remove all queued animations, and complete all animations for the matched elements."}
- jQuery.fx.interval (opens in a new tab){data-tooltip="The rate (in milliseconds) at which animations fire."}
- jQuery.fx.off (opens in a new tab){data-tooltip="Globally disable all animations."}
- jQuery.speed (opens in a new tab){data-tooltip="Creates an object containing a set of properties ready to be used in the definition of custom animations."}
- .queue() (opens in a new tab){data-tooltip="Show the queue of functions to be executed on the matched elements."}
- jQuery.queue() (opens in a new tab){data-tooltip="Show the queue of functions to be executed on the matched element."}
- .stop() (opens in a new tab){data-tooltip="Stop the currently-running animation on the matched elements."} {.marker-none .cols-3}
Fading
- .fadeIn() (opens in a new tab){data-tooltip="Display the matched elements by fading them to opaque."}
- .fadeOut() (opens in a new tab){data-tooltip="Hide the matched elements by fading them to transparent."}
- .fadeTo() (opens in a new tab){data-tooltip="Adjust the opacity of the matched elements."}
- .fadeToggle() (opens in a new tab){data-tooltip="Display or hide the matched elements by animating their opacity."} {.marker-none .cols-3}
jQuery Ajax
Examples {.secondary .row-span-2}
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize()
}).done(function(server_data){
console.log("success" + server_data);
}).fail(function(jqXHR, status, err){
console.log("fail" + err);
});
Global Ajax Event Handlers
- .ajaxComplete() (opens in a new tab){data-tooltip="Register a handler to be called when Ajax requests complete. This is an AjaxEvent."}
- .ajaxError() (opens in a new tab){data-tooltip="Register a handler to be called when Ajax requests complete with an error. This is an Ajax Event."}
- .ajaxSend() (opens in a new tab){data-tooltip="Attach a function to be executed before an Ajax request is sent. This is an Ajax Event."}
- .ajaxStart() (opens in a new tab){data-tooltip="Register a handler to be called when the first Ajax request begins. This is an Ajax Event."}
- .ajaxStop() (opens in a new tab){data-tooltip="Register a handler to be called when all Ajax requests have completed. This is an Ajax Event."}
- .ajaxSuccess() (opens in a new tab){data-tooltip="Attach a function to be executed whenever an Ajax request completes successfully. This is an Ajax Event."} {.marker-none .cols-2}
Helper Functions
- jQuery.param() (opens in a new tab){data-tooltip="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."}
- .serialize() (opens in a new tab){data-tooltip="Encode a set of form elements as a string for submission."}
- .serializeArray() (opens in a new tab){data-tooltip="Encode a set of form elements as an array of names and values."} {.marker-none .cols-2}
Low-Level Interface
- jQuery.ajax() (opens in a new tab){data-tooltip="Perform an asynchronous HTTP (Ajax) request."}
- jQuery.prefilter() (opens in a new tab){data-tooltip="Handle custom Ajax options or modify existing options before each request is sent and before they are processed by $.ajax()."}
- jQuery.ajaxSetup() (opens in a new tab){data-tooltip="Set default values for future Ajax requests. Its use is not recommended."}
- jQuery.ajaxTransport() (opens in a new tab){data-tooltip="Creates an object that handles the actual transmission of Ajax data."} {.marker-none .cols-2}
Shorthand Methods
- jQuery.get() (opens in a new tab){data-tooltip="Load data from the server using a HTTP GET request."}
- jQuery.getJSON() (opens in a new tab){data-tooltip="Load JSON-encoded data from the server using a GET HTTP request."}
- jQuery.getScript() (opens in a new tab){data-tooltip="Load a JavaScript file from the server using a GET HTTP request, then execute it."}
- jQuery.post() (opens in a new tab){data-tooltip="Send data to the server using a HTTP POST request."}
- .load() (opens in a new tab){data-tooltip="Load data from the server and place the returned HTML into the matched elements."} {.marker-none .cols-2}
Miscellaneous
jQuery Object
- jQuery() (opens in a new tab){data-tooltip="Accepts a string containing a CSS selector which is then used to match a set of elements."}
- jQuery.noConflict() (opens in a new tab){data-tooltip="Relinquish jQuery's control of the $ variable."}
- jQuery.sub() (opens in a new tab){data-tooltip="Creates a new copy of jQuery whose properties and methods can be modified without affecting the original jQuery object."}
- jQuery.holdReady() (opens in a new tab){data-tooltip="Holds or releases the execution of jQuery's ready event."}
- jQuery.when() (opens in a new tab){data-tooltip="Provides a way to execute callback functions based on zero or more Thenable objects, usually Deferred objects that represent asynchronous events."} {.marker-none .cols-2}
Deferred Object {.row-span-2}
- jQuery.Deferred() (opens in a new tab){data-tooltip=" 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."}
- deferred.always() (opens in a new tab){data-tooltip=" Add handlers to be called when the Deferred object is either resolved or rejected. "}
- deferred.done() (opens in a new tab){data-tooltip=" Add handlers to be called when the Deferred object is resolved. "}
- deferred.fail() (opens in a new tab){data-tooltip=" Add handlers to be called when the Deferred object is rejected. "}
- deferred.isRejected() (opens in a new tab){data-tooltip=" Determine whether a Deferred object has been rejected. "}
- deferred.isResolved() (opens in a new tab){data-tooltip=" Determine whether a Deferred object has been resolved. "}
- deferred.notify() (opens in a new tab){data-tooltip=" Call the progressCallbacks on a Deferred object with the given args. "}
- deferred.notifyWith() (opens in a new tab){data-tooltip=" Call the progressCallbacks on a Deferred object with the given context and args. "}
- deferred.pipe() (opens in a new tab){data-tooltip=" Utility method to filter and/or chain Deferreds. "}
- deferred.progress() (opens in a new tab){data-tooltip=" Add handlers to be called when the Deferred object generates progress notifications."}
- deferred.promise() (opens in a new tab){data-tooltip=" Return a Deferred's Promise object. "}
- deferred.reject() (opens in a new tab){data-tooltip=" Reject a Deferred object and call any failCallbacks with the given args. "}
- deferred.rejectWith() (opens in a new tab){data-tooltip=" Reject a Deferred object and call any failCallbacks with the given context and args. "}
- deferred.resolve() (opens in a new tab){data-tooltip=" Resolve a Deferred object and call any doneCallbacks with the given args. "}
- deferred.resolveWith() (opens in a new tab){data-tooltip=" Resolve a Deferred object and call any doneCallbacks with the given context and args. "}
- deferred.state() (opens in a new tab){data-tooltip="Determine the current state of a Deferred object. "}
- deferred.then() (opens in a new tab){data-tooltip="Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. "}
- .promise() (opens in a new tab){data-tooltip=" Return a Promise object to observe when all actions of a certain type bound to the collection, queued or not, have finished. "} {.marker-none .cols-2}
Utilities {.row-span-3}
- jQuery.boxModel (opens in a new tab){data-tooltip="States if the current page, in the user's browser, is being rendered using the W3C CSS Box Model."}
- jQuery.browser (opens in a new tab){data-tooltip="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."}
- jQuery.contains() (opens in a new tab){data-tooltip="Check to see if a DOM element is a descendant of another DOM element."}
- jQuery.each() (opens in a new tab){data-tooltip="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."}
- jQuery.extend() (opens in a new tab){data-tooltip="Merge the contents of two or more objects together into the first object."}
- jQuery.globalEval() (opens in a new tab){data-tooltip="Execute some JavaScript code globally."}
- jQuery.grep() (opens in a new tab){data-tooltip="Finds the elements of an array which satisfy a filter function. The original array is not affected."}
- jQuery.inArray() (opens in a new tab){data-tooltip="Search for a specified value within an array and return its index (or -1 if not found)."}
- jQuery.isArray() (opens in a new tab){data-tooltip="Determine whether the argument is an array."}
- jQuery.isEmptyObject() (opens in a new tab){data-tooltip="Check to see if an object is empty (contains no enumerable properties)."}
- jQuery.isFunction() (opens in a new tab){data-tooltip="Determines if its argument is callable as a function."}
- jQuery.isNumeric() (opens in a new tab){data-tooltip="Determines whether its argument represents a JavaScript number."}
- jQuery.isPlainObject() (opens in a new tab){data-tooltip="Check to see if an object is a plain object."}
- jQuery.isWindow() (opens in a new tab){data-tooltip="Determine whether the argument is a window."}
- jQuery.isXMLDoc() (opens in a new tab){data-tooltip="Check to see if a DOM node is within an XML document (or is an XML document)."}
- jQuery.makeArray() (opens in a new tab){data-tooltip="Convert an array-like object into a true JavaScript array."}
- jQuery.map() (opens in a new tab){data-tooltip="Translate all items in an array or object to new array of items."}
- jQuery.merge() (opens in a new tab){data-tooltip="Merge the contents of two arrays together into the first array. "}
- jQuery.noop() (opens in a new tab){data-tooltip="An empty function."}
- jQuery.now() (opens in a new tab){data-tooltip="Return a number representing the current time."}
- jQuery.parseHTML() (opens in a new tab){data-tooltip="Parses a string into an array of DOM nodes."}
- jQuery.parseJSON() (opens in a new tab){data-tooltip="Takes a well-formed JSON string and returns the resulting JavaScript value."}
- jQuery.parseXML() (opens in a new tab){data-tooltip="Parses a string into an XML document."}
- jQuery.proxy() (opens in a new tab){data-tooltip="Takes a function and returns a new one that will always have a particular context."}
- jQuery.support (opens in a new tab){data-tooltip="A collection of properties that represent the presence of different browser features or bugs. Intended for jQuery's internal use; specific properties may be removed when they are no longer needed internally to improve page startup performance. For your own project's feature-detection needs, we strongly recommend the use of an external library such as Modernizr instead of dependency on properties in jQuery.support."}
- jQuery.trim() (opens in a new tab){data-tooltip="Remove the whitespace from the beginning and end of a string."}
- jQuery.type() (opens in a new tab){data-tooltip="Determine the internal JavaScript [[Class]] of an object."}
- jQuery.unique() (opens in a new tab){data-tooltip="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."}
- jQuery.uniqueSort() (opens in a new tab){data-tooltip="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."} {.marker-none .cols-2}
DOM Element Methods
- .get() (opens in a new tab){data-tooltip="Retrieve one of the elements matched by the jQuery object."}
- .index() (opens in a new tab){data-tooltip="Search for a given element from among the matched elements."}
- .size() (opens in a new tab){data-tooltip="Return the number of elements in the jQuery object."}
- .toArray() (opens in a new tab){data-tooltip="Retrieve all the elements contained in the jQuery set, as an array."} {.marker-none .cols-2}
Internals
- .jquery (opens in a new tab){data-tooltip="A string containing the jQuery version number."}
- .context (opens in a new tab){data-tooltip="The DOM node context originally passed to jQuery(); if none was passed then context will likely be the document."}
- jQuery.error() (opens in a new tab){data-tooltip="Takes a string and throws an exception containing it."}
- .length (opens in a new tab){data-tooltip="The number of elements in the jQuery object."}
- .pushStack() (opens in a new tab){data-tooltip="Add a collection of DOM elements onto the jQuery stack."}
- .selector (opens in a new tab){data-tooltip="A selector representing selector passed to jQuery(), if any, when creating the original set."} {.marker-none .cols-2}
Callbacks Object
- jQuery.Callbacks() (opens in a new tab){data-tooltip="A multi-purpose callbacks list object that provides a powerful way to manage callback lists."}
- callbacks.add() (opens in a new tab){data-tooltip="Add a callback or a collection of callbacks to a callback list."}
- callbacks.disable() (opens in a new tab){data-tooltip="Disable a callback list from doing anything more."}
- callbacks.disabled() (opens in a new tab){data-tooltip="Determine if the callbacks list has been disabled."}
- callbacks.empty() (opens in a new tab){data-tooltip="Remove all of the callbacks from a list."}
- callbacks.fire() (opens in a new tab){data-tooltip="Call all of the callbacks with the given arguments."}
- callbacks.fired() (opens in a new tab){data-tooltip="Determine if the callbacks have already been called at least once."}
- callbacks.fireWith() (opens in a new tab){data-tooltip="Call all callbacks in a list with the given context and arguments."}
- callbacks.has() (opens in a new tab){data-tooltip="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."}
- callbacks.lock() (opens in a new tab){data-tooltip="Lock a callback list in its current state."}
- callbacks.locked() (opens in a new tab){data-tooltip="Determine if the callbacks list has been locked."}
- callbacks.remove() (opens in a new tab){data-tooltip="Remove a callback or a collection of callbacks from a callback list."} {.marker-none .cols-2}