Difference between revisions of "Small jQuery Cheat Sheet"

From PaskvilWiki
Jump to: navigation, search
(Created page with "I always forget this stuff... is it <tt>click()</tt> or <tt>onclick()</tt>? Hope this will be helpful to others too. This is by no means definite or complete guide... well, it's...")
 
Line 5: Line 5:
 
Most of the stuff here is just DOM and events related. AJAX etc. is best described in [http://api.jquery.com/ jQuery docs].
 
Most of the stuff here is just DOM and events related. AJAX etc. is best described in [http://api.jquery.com/ jQuery docs].
  
* '''.add()'''
+
==== .add() ====
 
Add elements to the set of matched elements.
 
Add elements to the set of matched elements.
* '''.addClass()'''
+
==== .addClass() ====
 
Adds the specified class(es) to each of the set of matched elements.
 
Adds the specified class(es) to each of the set of matched elements.
* '''.after()'''
+
==== .after() ====
 
Insert content, specified by the parameter, after each element in the set of matched elements.
 
Insert content, specified by the parameter, after each element in the set of matched elements.
* '''.animate()'''
+
==== .animate() ====
 
Perform a custom animation of a set of CSS properties.
 
Perform a custom animation of a set of CSS properties.
* '''.append()'''
+
==== .append() ====
 
Insert content, specified by the parameter, to the end of each element in the set of matched elements.
 
Insert content, specified by the parameter, to the end of each element in the set of matched elements.
* '''.attr()'''
+
==== .attr() ====
 
Get the value of an attribute for the first element in the set of matched elements.
 
Get the value of an attribute for the first element in the set of matched elements.
* '''.before()'''
+
==== .before() ====
 
Insert content, specified by the parameter, before each element in the set of matched elements.
 
Insert content, specified by the parameter, before each element in the set of matched elements.
* '''.children()'''
+
==== .children() ====
 
Get the children of each element in the set of matched elements, optionally filtered by a selector.
 
Get the children of each element in the set of matched elements, optionally filtered by a selector.
* '''.clearQueue()'''
+
==== .clearQueue() ====
 
Remove from the queue all items that have not yet been run.
 
Remove from the queue all items that have not yet been run.
* '''.click()'''
+
==== .click() ====
 
Bind an event handler to the "click" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "click" JavaScript event, or trigger that event on an element.
* '''.css()'''
+
==== .css() ====
 
Get the value of a style property for the first element in the set of matched elements.
 
Get the value of a style property for the first element in the set of matched elements.
* '''.delay()'''
+
==== .delay() ====
 
Set a timer to delay execution of subsequent items in the queue.
 
Set a timer to delay execution of subsequent items in the queue.
* '''.each()'''
+
==== .each() ====
 
Iterate over a jQuery object, executing a function for each matched element.
 
Iterate over a jQuery object, executing a function for each matched element.
* '''.fadeIn()'''
+
==== .fadeIn() ====
 
Display the matched elements by fading them to opaque.
 
Display the matched elements by fading them to opaque.
* '''.fadeOut()'''
+
==== .fadeOut() ====
 
Hide the matched elements by fading them to transparent.
 
Hide the matched elements by fading them to transparent.
* '''.fadeTo()'''
+
==== .fadeTo() ====
 
Adjust the opacity of the matched elements.
 
Adjust the opacity of the matched elements.
* '''.fadeToggle()'''
+
==== .fadeToggle() ====
 
Display or hide the matched elements by animating their opacity.
 
Display or hide the matched elements by animating their opacity.
* '''.filter()'''
+
==== .filter() ====
 
Reduce the set of matched elements to those that match the selector or pass the function's test.
 
Reduce the set of matched elements to those that match the selector or pass the function's test.
* '''.find()'''
+
==== .find() ====
 
Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.
 
Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.
* '''.first()'''
+
==== .first() ====
 
Reduce the set of matched elements to the first in the set.
 
Reduce the set of matched elements to the first in the set.
* '''.focus()'''
+
==== .focus() ====
 
Bind an event handler to the "focus" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "focus" JavaScript event, or trigger that event on an element.
* '''.focusin()'''
+
==== .focusin() ====
 
Bind an event handler to the "focusin" event.
 
Bind an event handler to the "focusin" event.
* '''.focusout()'''
+
==== .focusout() ====
 
Bind an event handler to the "focusout" JavaScript event.
 
Bind an event handler to the "focusout" JavaScript event.
* '''.height()'''
+
==== .height() ====
 
Get the current computed height for the first element in the set of matched elements.
 
Get the current computed height for the first element in the set of matched elements.
* '''.hide()'''
+
==== .hide() ====
 
Hide the matched elements.
 
Hide the matched elements.
* '''.hover()'''
+
==== .hover() ====
 
Bind two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements.
 
Bind two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements.
* '''.html()'''
+
==== .html() ====
 
Get the HTML contents of the first element in the set of matched elements.
 
Get the HTML contents of the first element in the set of matched elements.
* '''.innerHeight()'''
+
==== .innerHeight() ====
 
Get the current computed height for the first element in the set of matched elements, including padding but not border.
 
Get the current computed height for the first element in the set of matched elements, including padding but not border.
* '''.innerWidth()'''
+
==== .innerWidth() ====
 
Get the current computed width for the first element in the set of matched elements, including padding but not border.
 
Get the current computed width for the first element in the set of matched elements, including padding but not border.
* '''.insertAfter()'''
+
==== .insertAfter() ====
 
Insert every element in the set of matched elements after the target.
 
Insert every element in the set of matched elements after the target.
* '''.insertBefore()'''
+
==== .insertBefore() ====
 
Insert every element in the set of matched elements before the target.
 
Insert every element in the set of matched elements before the target.
* '''.keydown()'''
+
==== .keydown() ====
 
Bind an event handler to the "keydown" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "keydown" JavaScript event, or trigger that event on an element.
* '''.keypress()'''
+
==== .keypress() ====
 
Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element.
* '''.keyup()'''
+
==== .keyup() ====
 
Bind an event handler to the "keyup" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "keyup" JavaScript event, or trigger that event on an element.
* '''.last()'''
+
==== .last() ====
 
Reduce the set of matched elements to the final one in the set.
 
Reduce the set of matched elements to the final one in the set.
* '''.map()'''
+
==== .map() ====
 
Pass each element in the current matched set through a function, producing a new jQuery object containing the return values.
 
Pass each element in the current matched set through a function, producing a new jQuery object containing the return values.
* '''.mousedown()'''
+
==== .mousedown() ====
 
Bind an event handler to the "mousedown" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "mousedown" JavaScript event, or trigger that event on an element.
* '''.mouseenter()'''
+
==== .mouseenter() ====
 
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 be fired when the mouse enters an element, or trigger that handler on an element.
* '''.mouseleave()'''
+
==== .mouseleave() ====
 
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 be fired when the mouse leaves an element, or trigger that handler on an element.
* '''.mousemove()'''
+
==== .mousemove() ====
 
Bind an event handler to the "mousemove" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "mousemove" JavaScript event, or trigger that event on an element.
* '''.mouseout()'''
+
==== .mouseout() ====
 
Bind an event handler to the "mouseout" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "mouseout" JavaScript event, or trigger that event on an element.
* '''.mouseover()'''
+
==== .mouseover() ====
 
Bind an event handler to the "mouseover" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "mouseover" JavaScript event, or trigger that event on an element.
* '''.mouseup()'''
+
==== .mouseup() ====
 
Bind an event handler to the "mouseup" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "mouseup" JavaScript event, or trigger that event on an element.
* '''.next()'''
+
==== .next() ====
 
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.
 
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()'''
+
==== .nextAll() ====
 
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 in the set of matched elements, optionally filtered by a selector.
* '''.nextUntil()'''
+
==== .nextUntil() ====
 
Get all following siblings of each element up to but not including the element matched by the selector, DOM node, or jQuery object passed.
 
Get all following siblings of each element up to but not including the element matched by the selector, DOM node, or jQuery object passed.
* '''.outerHeight()'''
+
==== .outerHeight() ====
 
Get the current computed height for the first element in the set of matched elements, including padding, border, and optionally margin. Returns an integer (without "px") representation of the value or null if called on an empty set of elements.
 
Get the current computed height for the first element in the set of matched elements, including padding, border, and optionally margin. Returns an integer (without "px") representation of the value or null if called on an empty set of elements.
* '''.outerWidth()'''
+
==== .outerWidth() ====
 
Get the current computed width for the first element in the set of matched elements, including padding and border.
 
Get the current computed width for the first element in the set of matched elements, including padding and border.
* '''.parent()'''
+
==== .parent() ====
 
Get the parent of each element in the current set of matched elements, optionally filtered by a selector.
 
Get the parent of each element in the current set of matched elements, optionally filtered by a selector.
* '''.parents()'''
+
==== .parents() ====
 
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, optionally filtered by a selector.
* '''.position()'''
+
==== .position() ====
 
Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.
 
Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.
* '''.prepend()'''
+
==== .prepend() ====
 
Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.
 
Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.
* '''.prependTo()'''
+
==== .prependTo() ====
 
Insert every element in the set of matched elements to the beginning of the target.
 
Insert every element in the set of matched elements to the beginning of the target.
* '''.prev()'''
+
==== .prev() ====
 
Get the immediately preceding sibling of each element in the set of matched elements, optionally filtered by a selector.
 
Get the immediately preceding sibling of each element in the set of matched elements, optionally filtered by a selector.
* '''.remove()'''
+
==== .remove() ====
 
Remove the set of matched elements from the DOM.
 
Remove the set of matched elements from the DOM.
* '''.removeAttr()'''
+
==== .removeAttr() ====
 
Remove an attribute from each element in the set of matched elements.
 
Remove an attribute from each element in the set of matched elements.
* '''.removeClass()'''
+
==== .removeClass() ====
 
Remove a single class, multiple classes, or all classes 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.
* '''.resize()'''
+
==== .resize() ====
 
Bind an event handler to the "resize" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "resize" JavaScript event, or trigger that event on an element.
* '''.scroll()'''
+
==== .scroll() ====
 
Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element.
* '''.scrollLeft()'''
+
==== .scrollLeft() ====
 
Get the current horizontal position of the scroll bar for the first element in the set of matched elements.
 
Get the current horizontal position of the scroll bar for the first element in the set of matched elements.
* '''.scrollTop()'''
+
==== .scrollTop() ====
 
Get the current vertical position of the scroll bar for the first element in the set of matched elements.
 
Get the current vertical position of the scroll bar for the first element in the set of matched elements.
* '''.select()'''
+
==== .select() ====
 
Bind an event handler to the "select" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "select" JavaScript event, or trigger that event on an element.
* '''.show()'''
+
==== .show() ====
 
Display the matched elements.
 
Display the matched elements.
* '''.siblings()'''
+
==== .siblings() ====
 
Get the siblings of each element in the set of matched elements, optionally filtered by a selector.
 
Get the siblings of each element in the set of matched elements, optionally filtered by a selector.
* '''.slideDown()'''
+
==== .slideDown() ====
 
Display the matched elements with a sliding motion.
 
Display the matched elements with a sliding motion.
* '''.slideToggle()'''
+
==== .slideToggle() ====
 
Display or hide the matched elements with a sliding motion.
 
Display or hide the matched elements with a sliding motion.
* '''.slideUp()'''
+
==== .slideUp() ====
 
Hide the matched elements with a sliding motion.
 
Hide the matched elements with a sliding motion.
* '''.stop()'''
+
==== .stop() ====
 
Stop the currently-running animation on the matched elements.
 
Stop the currently-running animation on the matched elements.
* '''.submit()'''
+
==== .submit() ====
 
Bind an event handler to the "submit" JavaScript event, or trigger that event on an element.
 
Bind an event handler to the "submit" JavaScript event, or trigger that event on an element.
* '''.text()'''
+
==== .text() ====
 
Get the combined text contents of each element in the set of matched elements, including their descendants.
 
Get the combined text contents of each element in the set of matched elements, including their descendants.
* '''.toggle()'''
+
==== .toggle() ====
 
Display or hide the matched elements.
 
Display or hide the matched elements.
* '''.toggle()'''
+
==== .toggle() ====
 
Bind two or more handlers to the matched elements, to be executed on alternate clicks.
 
Bind two or more handlers to the matched elements, to be executed on alternate clicks.
* '''.toggleClass()'''
+
==== .toggleClass() ====
 
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 switch argument.
 
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 switch argument.
* '''.val()'''
+
==== .val() ====
 
Get the current value of the first element in the set of matched elements.
 
Get the current value of the first element in the set of matched elements.
* '''.width()'''
+
==== .width() ====
 
Get the current computed width for the first element in the set of matched elements.
 
Get the current computed width for the first element in the set of matched elements.
* '''.wrap()'''
+
==== .wrap() ====
 
Wrap an HTML structure around each element in the set of matched elements.
 
Wrap an HTML structure around each element in the set of matched elements.
* '''.wrapAll()'''
+
==== .wrapAll() ====
 
Wrap an HTML structure around all elements in the set of matched elements.
 
Wrap an HTML structure around all elements in the set of matched elements.
* '''.wrapInner()'''
+
==== .wrapInner() ====
 
Wrap an HTML structure around the content of each element in the set of matched elements.
 
Wrap an HTML structure around the content of each element in the set of matched elements.

Revision as of 21:55, 8 April 2012

I always forget this stuff... is it click() or onclick()? Hope this will be helpful to others too.

This is by no means definite or complete guide... well, it's a cheat sheet. Most of the stuff here is just DOM and events related. AJAX etc. is best described in jQuery docs.

.add()

Add elements to the set of matched elements.

.addClass()

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

.after()

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

.animate()

Perform a custom animation of a set of CSS properties.

.append()

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

.attr()

Get the value of an attribute for the first element in the set of matched elements.

.before()

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

.children()

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

.clearQueue()

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

.click()

Bind an event handler to the "click" JavaScript event, or trigger that event on an element.

.css()

Get the value of a style property for the first element in the set of matched elements.

.delay()

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

.each()

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

.fadeIn()

Display the matched elements by fading them to opaque.

.fadeOut()

Hide the matched elements by fading them to transparent.

.fadeTo()

Adjust the opacity of the matched elements.

.fadeToggle()

Display or hide the matched elements by animating their opacity.

.filter()

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

.find()

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

.first()

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

.focus()

Bind an event handler to the "focus" JavaScript event, or trigger that event on an element.

.focusin()

Bind an event handler to the "focusin" event.

.focusout()

Bind an event handler to the "focusout" JavaScript event.

.height()

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

.hide()

Hide the matched elements.

.hover()

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

.html()

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

.innerHeight()

Get the current computed height for the first element in the set of matched elements, including padding but not border.

.innerWidth()

Get the current computed width for the first element in the set of matched elements, including padding but not border.

.insertAfter()

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

.insertBefore()

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

.keydown()

Bind an event handler to the "keydown" JavaScript event, or trigger that event on an element.

.keypress()

Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element.

.keyup()

Bind an event handler to the "keyup" JavaScript event, or trigger that event on an element.

.last()

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

.map()

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

.mousedown()

Bind an event handler to the "mousedown" JavaScript event, or trigger that event on an element.

.mouseenter()

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

.mouseleave()

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

.mousemove()

Bind an event handler to the "mousemove" JavaScript event, or trigger that event on an element.

.mouseout()

Bind an event handler to the "mouseout" JavaScript event, or trigger that event on an element.

.mouseover()

Bind an event handler to the "mouseover" JavaScript event, or trigger that event on an element.

.mouseup()

Bind an event handler to the "mouseup" JavaScript event, or trigger that event on an element.

.next()

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()

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

.nextUntil()

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

.outerHeight()

Get the current computed height for the first element in the set of matched elements, including padding, border, and optionally margin. Returns an integer (without "px") representation of the value or null if called on an empty set of elements.

.outerWidth()

Get the current computed width for the first element in the set of matched elements, including padding and border.

.parent()

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

.parents()

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

.position()

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

.prepend()

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

.prependTo()

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

.prev()

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

.remove()

Remove the set of matched elements from the DOM.

.removeAttr()

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

.removeClass()

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

.resize()

Bind an event handler to the "resize" JavaScript event, or trigger that event on an element.

.scroll()

Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element.

.scrollLeft()

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

.scrollTop()

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

.select()

Bind an event handler to the "select" JavaScript event, or trigger that event on an element.

.show()

Display the matched elements.

.siblings()

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

.slideDown()

Display the matched elements with a sliding motion.

.slideToggle()

Display or hide the matched elements with a sliding motion.

.slideUp()

Hide the matched elements with a sliding motion.

.stop()

Stop the currently-running animation on the matched elements.

.submit()

Bind an event handler to the "submit" JavaScript event, or trigger that event on an element.

.text()

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

.toggle()

Display or hide the matched elements.

.toggle()

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

.toggleClass()

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 switch argument.

.val()

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

.width()

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

.wrap()

Wrap an HTML structure around each element in the set of matched elements.

.wrapAll()

Wrap an HTML structure around all elements in the set of matched elements.

.wrapInner()

Wrap an HTML structure around the content of each element in the set of matched elements.