Functions
JavaScript Functions
Selecting
Selecting DOM elements
- Select an element by ID
$('#foo') - Select DOM elements by CSS selector
$(selector), $(selector, context) - Select elements by class name
$('.foo') - Select elements by tag name
$('div')
Traversing
DOM traversing
- Get closest element by selector
$.closest() - Get parent element node
$.parent(), $.parents() - Get siblings of an element
$.siblings(), $.next(), $.nextAll(), $.prev, $.prevAll() - Match element selector
$.is() - Select the children of an element
$.children()
Manipulation
Manipulating DOM elements
- Append or prepend to an element
$.append(), $.appendTo(), $.prepend(), $.prependTo() - Clone an element
$.clone() - Create a DOM element
$(string) - Empty an element’s content
$.empty() - Insert an element after or before another
$.after(), $.before(), $.insertAfter(), $.insertBefore - Removing an element
$.remove(), $.detach() - Replace a DOM element
$.replaceAll(), $.replaceWith() - Unwrap a DOM element
$.unwrap() - Wrap an HTML structure around an element
$.wrap(), $.wrapAll()
Attributes
Element attributes
- Adding, removing, and testing for classes
$.addClass(), $.removeClass(), $.hasClass(), $.toggleClass()
Styles
Element styles, dimensions and positions
- Get and set scroll position of an element
$.scrollLeft(), $.scrollTop() - Getting width and height of an element
$.width(), $.height(), $.outerWidth(), $.outerHeight(), $.innerWidth(), $.innerHeight()
Ajax
Requests without a page load
- Load a script file asynchronously
$.getScript() - Making CORS Ajax GET requests
$.ajax() - Send Ajax GET and POST requests
$.ajax(), $.get(), $.post(), $.getJSON() - Serialize form data into a query string
$.serialize() - Serialize form data into an array
$.serializeArray()
Events
Binding and unbinding events
- Binding and unbinding of event handlers
$.on(), $.bind(), $.live(), $.click(), $.focus(), $.submit(), etc. - Getting the current mouse position
$.mousedown(), $.click(), $.mouse... - Getting the keycode from keyboard events
$.keypress(), $.keyup(), $.keydown() - Live binding event handlers
$.live(), $.on(), $.bind() - Preventing the default action or bubbling of events
e.preventDefault(), e.stopPropagation() - Running code when the document is ready
$(document).ready() - Trigger an event
$.trigger(), $.click(), $.focus(), $.submit(), etc.
Effects
Showing, hiding, fading, animating
- Animate an element property
$.animate(), $.slideUp(), $.slideDown(), $.fadeIn(), $.fadeOut() - Hide or show an element
$.show(), $.hide(), $.toggle()
Utilities
Objects, strings, cookies, timing
- Merge two JavaScript objects
$.extend() - Parsing a JSON string
$.parseJSON() - Test if a certain value exists in an array
$.inArray()