([{"url":"http:\/\/api.jquery.com\/add\/","title":".add()","type":"method","signatures":[{"added":"1.0","params":[{"name":"selector","type":"Selector","optional":"","desc":"A string containing a selector expression to match additional elements against."}]},{"added":"1.0","params":[{"name":"elements","type":"Elements","optional":"","desc":"one or more elements to add to the set of matched elements."}]},{"added":"1.0","params":[{"name":"html","type":"HTML","optional":"","desc":"An HTML fragment to add to the set of matched elements."}]},{"added":"1.4","params":[{"name":"selector","type":"Selector","optional":"","desc":"A string containing a selector expression to match additional elements against."},{"name":"context","type":"Element","optional":"","desc":"Add some elements rooted against the specified context."}]}],"desc":"Add elements to the set of matched elements.","longdesc":"

Given a jQuery object that represents a set of DOM elements, the .add()<\/code> method constructs a new jQuery object from the union of those elements and the ones passed into the method. The argument to .add()<\/code> can be pretty much anything that $()<\/code> accepts, including a jQuery selector expression, references to DOM elements, or an HTML snippet.<\/p>\n

Consider a page with a simple list and a paragraph following it:<\/p>\n

<ul>\n  <li>list item 1<\/li>\n  <li>list item 2<\/li>\n  <li>list item 3<\/li>\n<\/ul>\n<p>a paragraph<\/p><\/pre>\n

We can select the list items and then the paragraph by using either a selector or a reference to the DOM element itself as the .add()<\/code> method's argument:<\/p>\n

$('li').add('p').css('background-color', 'red');<\/pre>\n

Or:<\/p>\n

$('li').add(document.getElementsByTagName('p')[0])\n  .css('background-color', 'red');<\/pre>\n

The result of this call is a red background behind all four elements.\nUsing an HTML snippet as the .add()<\/code> method's argument (as in the third version), we can create additional elements on the fly and add those elements to the matched set of elements. Let's say, for example, that we want to alter the background of the list items along with a newly created paragraph:<\/p>\n

$('li').add('<p id=\"new\">new paragraph<\/p>')\n  .css('background-color', 'red');<\/pre>\n

Although the new paragraph has been created and its background color changed, it still does not appear on the page. To place it on the page, we could add one of the insertion methods to the chain.<\/p>\n

As of jQuery 1.4 the results from .add() will always be returned in document order (rather than a simple concatenation).<\/p>\n","return":"jQuery"},{"url":"http:\/\/api.jquery.com\/addClass\/","title":".addClass()","type":"method","signatures":[{"added":"1.0","params":[{"name":"className","type":"String","optional":"","desc":"One or more class names to be added to the class attribute of each matched element."}]},{"added":"1.4","params":[{"name":"function(index, class)","type":"Function","optional":"","desc":"A function returning one or more space-separated class names to be added. Receives the index position of the element in the set and the old class value as arguments."}]}],"desc":"Adds the specified class(es) to each of the set of matched elements.","longdesc":"

It's important to note that this method does not replace a class. It simply adds the class, appending it to any which may already be assigned to the elements.<\/p>\n

More than one class may be added at a time, separated by a space, to the set of matched elements, like so:<\/p>\n

$('p').addClass('myClass yourClass');<\/pre>\n  

This method is often used with .removeClass()<\/code> to switch elements' classes from one to another, like so:<\/p>\n

$('p').removeClass('myClass noClass').addClass('yourClass');<\/pre>\n  

Here, the myClass<\/code> and noClass<\/code> classes are removed from all paragraphs, while yourClass<\/code> is added.<\/p>\n

As of jQuery 1.4, the .addClass()<\/code> method allows us to set the class name by passing in a function.<\/p>\n

$('ul li:last').addClass(function() {\n  return 'item-' + $(this).index();\n});<\/pre>\n

Given an unordered list with five <li><\/code> elements, this example adds the class \"item-4\" to the last <li><\/code>.<\/p>\n\n\n","return":"jQuery"},{"url":"http:\/\/api.jquery.com\/after\/","title":".after()","type":"method","signatures":[{"added":"1.0","params":[{"name":"content","type":"String, Element, jQuery","optional":"","desc":"An element, HTML string, or jQuery object to insert after each element in the set of matched elements."}]},{"added":"1.4","params":[{"name":"function(index)","type":"Function","optional":"","desc":"A function that returns an HTML string to insert after each element in the set of matched elements."}]}],"desc":"Insert content, specified by the parameter, after each element in the set of matched elements.","longdesc":"

The .after()<\/code> and .insertAfter()<\/a><\/code> methods perform the same task. The major difference is in the syntax\u2014specifically, in the placement of the content and target. With .after()<\/code>, the selector expression preceding the method is the container after which the content is inserted. With .insertAfter()<\/code>, on the other hand, the content precedes the method, either as a selector expression or as markup created on the fly, and it is inserted after the target container.<\/p>\n\t\t\t\t

Consider the following HTML:<\/p>\n\t\t\t\t

<div class=\"container\">\n  <h2>Greetings<\/h2>\n  <div class=\"inner\">Hello<\/div>\n  <div class=\"inner\">Goodbye<\/div>\n<\/div><\/pre>\n\t\t\t\t

We can create content and insert it after several elements at once:<\/p>\n\t\t\t\t

$('.inner').after('<p>Test<\/p>');<\/pre>\n\t\t\t\t

Each inner <div><\/code> element gets this new content:<\/p>\n\t\t\t\t

<div class=\"container\">\n  <h2>Greetings<\/h2>\n  <div class=\"inner\">Hello<\/div>\n  <p>Test<\/p>\n  <div class=\"inner\">Goodbye<\/div>\n  <p>Test<\/p>\n<\/div><\/pre>\n\t\t\t\t

We can also select an element on the page and insert it after another:<\/p>\n\t\t\t\t

$('.container').after($('h2'));<\/pre>\n\t\t\t\t

If an element selected this way is inserted elsewhere, it will be moved after the target (not cloned):<\/p>\n\t\t\t\t

<div class=\"container\">\n  <div class=\"inner\">Hello<\/div>\n  <div class=\"inner\">Goodbye<\/div>\n<\/div>\n<h2>Greetings<\/h2><\/pre>\n\t\t\t\t

If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first.<\/p>\n

Inserting Disconnected DOM nodes<\/h4>\n

As of jQuery 1.4, .before()<\/code> and .after()<\/code> will also work on disconnected DOM nodes. For example, given the following code:<\/p>\n

$('<div\/>').after('<p><\/p>');<\/pre>\n

The result is a jQuery set containing a div and a paragraph, in that order. We can further manipulate that set, even before inserting it in the document.<\/p>\n

$('<div\/>').after('<p><\/p>').addClass('foo')\n  .filter('p').attr('id', 'bar').html('hello')\n.end()\n.appendTo('body');<\/pre>\n

This results in the following elements inserted just before the closing <\/body><\/code> tag:<\/p>\n

\n<div class=\"foo\"><\/div>\n<p class=\"foo\" id=\"bar\">hello<\/p>\n<\/pre>\n

As of jQuery 1.4, .after()<\/code> allows us to pass a function that returns the elements to insert.<\/p>\n

$('p').after(function() {\n  return '<div>' + this.className + '<\/div>';\n});<\/pre>\n

This inserts a <div><\/code> after each paragraph, containing the class name(s) of each paragraph in turn.<\/p>\n","return":"jQuery"},{"url":"http:\/\/api.jquery.com\/ajaxComplete\/","title":".ajaxComplete()","type":"method","signatures":[{"added":"1.0","params":[{"name":"handler(event, XMLHttpRequest, ajaxOptions)","type":"Function","optional":"","desc":"The function to be invoked."}]}],"desc":"Register a handler to be called when Ajax requests complete. This is an Ajax Event<\/a>.","longdesc":"

Whenever an Ajax request completes, jQuery triggers the ajaxComplete<\/code> event. Any and all handlers that have been registered with the .ajaxComplete()<\/code> method are executed at this time.<\/p>\n\t\t\t\t

To observe this method in action, we can set up a basic Ajax load request:<\/p>\n\t\t\t\t

<div class=\"trigger\">Trigger<\/div>\n<div class=\"result\"><\/div>\n<div class=\"log\"><\/div>\n<\/pre>\n\t\t\t\t

We can attach our event handler to any element:<\/p>\n\t\t\t\t

$('.log').ajaxComplete(function() {\n  $(this).text('Triggered ajaxComplete handler.');\n});\n<\/pre>\n\t\t\t\t

Now, we can make an Ajax request using any jQuery method:<\/p>\n\t\t\t\t

$('.trigger').click(function() {\n  $('.result').load('ajax\/test.html');\n});<\/pre>\n\t\t\t\t

When the user clicks the button and the Ajax request completes, the log message is displayed.<\/p>\n\n\t\t\t\t

Note:<\/strong> Because .ajaxComplete()<\/code> is implemented as a method of jQuery object instances, we can use the this<\/code> keyword as we do here to refer to the selected elements within the callback function.<\/p>\n\n\t\t\t\t

All ajaxComplete<\/code> handlers are invoked, regardless of what Ajax request was completed. If we must differentiate between the requests, we can use the parameters passed to the handler. Each time an ajaxComplete<\/code> handler is executed, it is passed the event object, the XMLHttpRequest<\/code> object, and the settings object that was used in the creation of the request. For example, we can restrict our callback to only handling events dealing with a particular URL:<\/p>\n\t\t\t\t

$('.log').ajaxComplete(function(e, xhr, settings) {\n  if (settings.url == 'ajax\/test.html') {\n    $(this).text('Triggered ajaxComplete handler.');\n  }\n});<\/pre>","return":"jQuery"},{"url":"http:\/\/api.jquery.com\/ajaxError\/","title":".ajaxError()","type":"method","signatures":[{"added":"1.0","params":[{"name":"handler(event, XMLHttpRequest, ajaxOptions, thrownError)","type":"Function","optional":"","desc":"The function to be invoked."}]}],"desc":"Register a handler to be called when Ajax requests complete with an error. This is an Ajax Event<\/a>.","longdesc":"

Whenever an Ajax request completes with an error, jQuery triggers the ajaxError<\/code> event. Any and all handlers that have been registered with the .ajaxError()<\/code> method are executed at this time.<\/p>\n\t\t\t\t

To observe this method in action, we can set up a basic Ajax load request:<\/p>\n\t\t\t\t

<div class=\"trigger\">Trigger<\/div>\n<div class=\"result\"><\/div>\n<div class=\"log\"><\/div><\/pre>\n\t\t\t\t

We can attach our event handler to any element:<\/p>\n\t\t\t\t

$('.log').ajaxError(function() {\n  $(this).text('Triggered ajaxError handler.');\n});<\/pre>\n\t\t\t\t

Now, we can make an Ajax request using any jQuery method:<\/p>\n\t\t\t\t

$('.trigger').click(function() {\n  $('.result').load('ajax\/missing.html');\n});<\/pre>\n\t\t\t\t

When the user clicks the button and the Ajax request fails, because the requested file is missing, the log message is displayed.<\/p>\n\n\t\t\t\t

Note:<\/strong> Because .ajaxError()<\/code> is implemented as a method of jQuery object instances, we can use the this<\/code> keyword as we do here to refer to the selected elements within the callback function.<\/p>\n\n\t\t\t\t

All ajaxError<\/code> handlers are invoked, regardless of what Ajax request was completed. If we must differentiate between the requests, we can use the parameters passed to the handler. Each time an ajaxError<\/code> handler is executed, it is passed the event object, the XMLHttpRequest<\/code> object, and the settings object that was used in the creation of the request. If the request failed because JavaScript raised an exception, the exception object is passed to the handler as a fourth parameter. For example, we can restrict our callback to only handling events dealing with a particular URL:<\/p>\n\t\t\t\t

$('.log').ajaxError(function(e, xhr, settings, exception) {\n  if (settings.url == 'ajax\/missing.html') {\n    $(this).text('Triggered ajaxError handler.');\n  }\n});<\/pre>","return":"jQuery"},{"url":"http:\/\/api.jquery.com\/ajaxSend\/","title":".ajaxSend()","type":"method","signatures":[{"added":"1.0","params":[{"name":"handler(event, XMLHttpRequest, ajaxOptions)","type":"Function","optional":"","desc":"The function to be invoked."}]}],"desc":"","longdesc":"\n    

Whenever an Ajax request is about to be sent, jQuery triggers the ajaxSend<\/code> event. Any and all handlers that have been registered with the .ajaxSend()<\/code> method are executed at this time.<\/p>\n

To observe this method in action, we can set up a basic Ajax load request:<\/p>\n

<div class=\"trigger\">Trigger<\/div>\n<div class=\"result\"><\/div>\n<div class=\"log\"><\/div><\/pre>\n    

We can attach our event handler to any element:<\/p>\n

$('.log').ajaxSend(function() {\n  $(this).text('Triggered ajaxSend handler.');\n});<\/pre>\n    

Now, we can make an Ajax request using any jQuery method:<\/p>\n

$('.trigger').click(function() {\n  $('.result').load('ajax\/test.html');\n});<\/pre>\n    

When the user clicks the button and the Ajax request is about to begin, the log message is displayed.<\/p>\n\n

Note:<\/strong> Because .ajaxSend()<\/code> is implemented as a method of jQuery instances, we can use the this<\/code> keyword as we do here to refer to the selected elements within the callback function.<\/p>\n\n

All ajaxSend<\/code> handlers are invoked, regardless of what Ajax request is to be sent. If we must differentiate between the requests, we can use the parameters passed to the handler. Each time an ajaxSend<\/code> handler is executed, it is passed the event object, the XMLHttpRequest<\/code> object, and the settings object<\/a> that was used in the creation of the Ajax request. For example, we can restrict our callback to only handling events dealing with a particular URL:<\/p>\n

$('.log').ajaxSend(function(e, xhr, settings) {\n  if (settings.url == 'ajax\/test.html') {\n    $(this).text('Triggered ajaxSend handler.');\n  }\n});<\/pre>\n    ","return":"jQuery"},{"url":"http:\/\/api.jquery.com\/ajaxStart\/","title":".ajaxStart()","type":"method","signatures":[{"added":"1.0","params":[{"name":"handler()","type":"Function","optional":"","desc":"The function to be invoked."}]}],"desc":"Register a handler to be called when the first Ajax request begins. This is an Ajax Event<\/a>.","longdesc":"

Whenever an Ajax request is about to be sent, jQuery checks whether there are any other outstanding Ajax requests. If none are in progress, jQuery triggers the ajaxStart<\/code> event. Any and all handlers that have been registered with the .ajaxStart()<\/code> method are executed at this time.<\/p>\n\t\t\t\t

To observe this method in action, we can set up a basic Ajax load request:<\/p>\n\t\t\t\t

<div class=\"trigger\">Trigger<\/div>\n<div class=\"result\"><\/div>\n<div class=\"log\"><\/div><\/pre>\n\t\t\t\t

We can attach our event handler to any element:<\/p>\n\t\t\t\t

$('.log').ajaxStart(function() {\n  $(this).text('Triggered ajaxStart handler.');\n});<\/pre>\n\t\t\t\t

Now, we can make an Ajax request using any jQuery method:<\/p>\n\t\t\t\t

$('.trigger').click(function() {\n  $('.result').load('ajax\/test.html');\n});<\/pre>\n\t\t\t\t

When the user clicks the button and the Ajax request is sent, the log message is displayed.<\/p>\n\n\t\t\t\t

Note:<\/strong> Because .ajaxStart()<\/code> is implemented as a method of jQuery object instances, we can use the this<\/code> keyword as we do here to refer to the selected elements within the callback function.<\/p>\n","return":"jQuery"},{"url":"http:\/\/api.jquery.com\/ajaxStop\/","title":".ajaxStop()","type":"method","signatures":[{"added":"1.0","params":[{"name":"handler()","type":"Function","optional":"","desc":"The function to be invoked."}]}],"desc":"Register a handler to be called when all Ajax requests have completed. This is an Ajax Event<\/a>.","longdesc":"\n

Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the ajaxStop<\/code> event. Any and all handlers that have been registered with the .ajaxStop()<\/code> method are executed at this time.<\/p>\n

To observe this method in action, we can set up a basic Ajax load request:<\/p>\n

<div class=\"trigger\">Trigger<\/div>\n<div class=\"result\"><\/div>\n<div class=\"log\"><\/div><\/pre>\n    

We can attach our event handler to any element:<\/p>\n

$('.log').ajaxStop(function() {\n  $(this).text('Triggered ajaxStop handler.');\n});<\/pre>\n    

Now, we can make an Ajax request using any jQuery method:<\/p>\n

$('.trigger').click(function() {\n  $('.result').load('ajax\/test.html');\n});<\/pre>\n    

When the user clicks the button and the Ajax request completes, the log message is displayed.<\/p>\n \t

Because .ajaxStop()<\/code> is implemented as a method of jQuery object instances, we can use the this<\/code> keyword as we do here to refer to the selected elements within the callback function.<\/p>\n ","return":"jQuery"},{"url":"http:\/\/api.jquery.com\/ajaxSuccess\/","title":".ajaxSuccess()","type":"method","signatures":[{"added":"1.0","params":[{"name":"handler(event, XMLHttpRequest, ajaxOptions)","type":"Function","optional":"","desc":"The function to be invoked."}]}],"desc":"","longdesc":"\n

Whenever an Ajax request completes successfully, jQuery triggers the ajaxSuccess<\/code> event. Any and all handlers that have been registered with the .ajaxSuccess()<\/code> method are executed at this time.<\/p>\n

To observe this method in action, we can set up a basic Ajax load request:<\/p>\n\t\t

<div class=\"trigger\">Trigger<\/div>\n<div class=\"result\"><\/div>\n<div class=\"log\"><\/div><\/pre>\n    

We can attach our event handler to any element:<\/p>\n

$('.log').ajaxSuccess(function() {\n  $(this).text('Triggered ajaxSuccess handler.');\n});<\/pre>\n    

Now, we can make an Ajax request using any jQuery method:<\/p>\n

$('.trigger').click(function() {\n  $('.result').load('ajax\/test.html');\n});<\/pre>\n\t\t

When the user clicks the button and the Ajax request completes successfully, the log message is displayed.<\/p>\n\n\n

Note:<\/strong> Because .ajaxSuccess()<\/code> is implemented as a method of jQuery object instances, we can use the this<\/code> keyword as we do here to refer to the selected elements within the callback function.<\/p>\n\n\t\t

All ajaxSuccess<\/code> handlers are invoked, regardless of what Ajax request was completed. If we must differentiate between the requests, we can use the parameters passed to the handler. Each time an ajaxSuccess<\/code> handler is executed, it is passed the event object, the XMLHttpRequest<\/code> object, and the settings object that was used in the creation of the request. For example, we can restrict our callback to only handling events dealing with a particular URL:<\/p>\n\t

$('.log').ajaxSuccess(function(e, xhr, settings) {\n  if (settings.url == 'ajax\/test.html') {\n    $(this).text('Triggered ajaxSuccess handler.');\n  }\n});<\/pre>\n  ","return":"jQuery"},{"url":"http:\/\/api.jquery.com\/all-selector\/","title":"All Selector (\"*\")","type":"selector","signatures":[{"added":"1.0"}],"desc":"Selects all elements.","longdesc":"

Caution: The all, or universal, selector is extremely slow, except when used by itself.<\/p> "},{"url":"http:\/\/api.jquery.com\/andSelf\/","title":".andSelf()","type":"method","signatures":[{"added":"1.2"}],"desc":"Add the previous set of elements on the stack to the current set.","longdesc":"

As described in the discussion for .end()<\/code> above, jQuery objects maintain an internal stack that keeps track of changes to the matched set of elements. When one of the DOM traversal methods is called, the new set of elements is pushed onto the stack. If the previous set of elements is desired as well, .andSelf()<\/code> can help.<\/p>\n

Consider a page with a simple list on it:<\/p>\n

\n<ul>\n   <li>list item 1<\/li>\n   <li>list item 2<\/li>\n   <li class=\"third-item\">list item 3<\/li>\n   <li>list item 4<\/li>\n   <li>list item 5<\/li>\n<\/ul>\n<\/pre>\n

If we begin at the third item, we can find the elements which come after it:<\/p>\n

$('li.third-item').nextAll().andSelf()\n  .css('background-color', 'red');\n<\/pre>\n

The result of this call is a red background behind items 3, 4 and 5. First, the initial selector locates item 3, initializing the stack with the set containing just this item. The call to .nextAll()<\/code> then pushes the set of items 4 and 5 onto the stack. Finally, the .andSelf()<\/code> invocation merges these two sets together, creating a jQuery object that points to all three items.<\/p>","return":"jQuery"},{"url":"http:\/\/api.jquery.com\/animate\/","title":".animate()","type":"method","signatures":[{"added":"1.0","params":[{"name":"properties","type":"Options","optional":"","desc":"A map of CSS properties that the animation will move toward."},{"name":"duration","type":"String,Number","optional":"optional","desc":"A string or number determining how long the animation will run."},{"name":"easing","type":"String","optional":"optional","desc":"A string indicating which easing function to use for the transition."},{"name":"callback","type":"Callback","optional":"optional","desc":"A function to call once the animation is complete."}]},{"added":"1.0","params":[{"name":"properties","type":"Options","optional":"","desc":"A map of CSS properties that the animation will move toward."},{"name":"options","type":"Options","optional":"","desc":"A map of additional options to pass to the method. Supported keys:\n