Skip to content

Instantly share code, notes, and snippets.

@abdul-alhasany
Created March 13, 2020 01:14
Show Gist options
  • Save abdul-alhasany/3172707596af7fbac2cab1ee499fc777 to your computer and use it in GitHub Desktop.
Save abdul-alhasany/3172707596af7fbac2cab1ee499fc777 to your computer and use it in GitHub Desktop.
This file has been truncated, but you can view the full file.
let typesList = [
{
"slug": "Anything",
"name": "Anything"
},
{
"slug": "String",
"name": "String",
"children": [
{
"slug": "Quoting",
"name": "Quoting"
},
{
"slug": "Built-in_Methods",
"name": "Built-in Methods"
},
{
"slug": "Length_Property",
"name": "Length Property"
},
{
"slug": "Boolean_Default",
"name": "Boolean Default"
}
]
},
{
"slug": "htmlString",
"name": "htmlString"
},
{
"slug": "Number",
"name": "Number",
"children": [
{
"slug": "Boolean_Default_2",
"name": "Boolean Default"
},
{
"slug": "Math",
"name": "Math"
},
{
"slug": "Parsing_Numbers",
"name": "Parsing Numbers"
},
{
"slug": "Numbers_to_Strings",
"name": "Numbers to Strings"
},
{
"slug": "NaN_and_Infinity",
"name": "NaN and Infinity"
},
{
"slug": "Integer",
"name": "Integer"
},
{
"slug": "Float",
"name": "Float"
}
]
},
{
"slug": "Boolean",
"name": "Boolean"
},
{
"slug": "Object",
"name": "Object",
"children": [
{
"slug": "Dot_Notation",
"name": "Dot Notation"
},
{
"slug": "Array_Notation",
"name": "Array Notation"
},
{
"slug": "Iteration",
"name": "Iteration"
},
{
"slug": "Boolean_default_3",
"name": "Boolean default"
},
{
"slug": "Prototype",
"name": "Prototype"
}
]
},
{
"slug": "Array",
"name": "Array",
"children": [
{
"slug": "Iteration_2",
"name": "Iteration"
},
{
"slug": "Boolean_Default_4",
"name": "Boolean Default"
},
{
"slug": "Array.3CType.3E_Notation",
"name": "Array<Type>\n Notation"
}
]
},
{
"slug": "ArrayLikeObject",
"name": "Array-Like Object"
},
{
"slug": "PlainObject",
"name": "PlainObject"
},
{
"slug": "Date",
"name": "Date"
},
{
"slug": "Function",
"name": "Function",
"children": [
{
"slug": "Arguments",
"name": "Arguments"
},
{
"slug": "Context.2C_Call_and_Apply",
"name": "Context, Call and\n Apply"
},
{
"slug": "Scope",
"name": "Scope"
},
{
"slug": "Closures",
"name": "Closures"
},
{
"slug": "Proxy_Pattern",
"name": "Proxy Pattern"
}
]
},
{
"slug": "Error",
"name": "Error"
},
{
"slug": "Selector",
"name": "Selector"
},
{
"slug": "Event",
"name": "Event"
},
{
"slug": "Element",
"name": "Element"
},
{
"slug": "Text",
"name": "Text"
},
{
"slug": "jQuery",
"name": "jQuery"
},
{
"slug": "XMLHttpRequest",
"name": "XMLHttpRequest"
},
{
"slug": "jqXHR",
"name": "jqXHR"
},
{
"slug": "Thenable",
"name": "Thenable"
},
{
"slug": "Deferred",
"name": "Deferred Object"
},
{
"slug": "Promise",
"name": "Promise Object"
},
{
"slug": "Callbacks",
"name": "Callbacks Object"
},
{
"slug": "XMLDocument",
"name": "XML Document"
},
{
"slug": "Assert",
"name": "Qunit's Assert Object"
}
];
let typesContent = `<p>This page documents data types appearing in jQuery function signatures, whether defined by JavaScript itself or
further restricted by jQuery. Unless explicitly stated otherwise, jQuery functions require primitive values where
applicable, and do not accept their Object-wrapped forms. If you want to study these concepts in depth, take a look at
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript">MDN</a>.
</p>
<p>You should be able to try out most of the examples below by just copying them to your browser's JavaScript Console.
</p>
<p>Whenever an example mentions that a type defaults to a boolean value, the result is good to know when using that type
in a boolean context:
</p>
<pre><code>var x = "";
if ( x ) {
console.log( "x defaulted to true" );
} else {
console.log( "x defaulted to false" );
}
</code></pre>
<p>In this case, <code>"x defaulted to false"</code> is printed.
</p>
<p>To keep the examples short, the invert ("not") operator and double-negation are used to show a boolean context:
</p>
<pre><code data-lang="javascript">
var x = "";
!x // true
!!x // false (Double negation: Since "not (empty string)" is true, negating that makes it false)
</code></pre>
<p>On to the actual types.
</p>
<h2 id="Anything"> Anything </h2>
<p>The <strong>Anything</strong> virtual type is used in jQuery documentation to indicate that any type can be used or
should be expected.
</p>
<h2 id="String"> String </h2>
<p>A string in JavaScript is an immutable primitive value that contains none, one or many characters.
</p>
<pre><code data-lang="javascript">"I'm a String in JavaScript!"
'So am I!'
</code></pre>
<p>The type of a string is "string".
</p>
<pre><code data-lang="javascript">typeof "some string"; // "string"
</code></pre>
<h3 id="Quoting"> Quoting </h3>
<p>A string can be defined using single or double quotes. You can nest single quotes inside of double quotes, and the
other way around. To mix double quotes with double quotes (or single with single), the nested ones have to be escaped
with a backslash.
</p>
<pre><code data-lang="javascript">"You make 'me' sad."
'That\'s "cranking" good fun!'
"&lt;a href=\"home\"&gt;Home&lt;/a&gt;"
</code></pre>
<h3 id="Built-in_Methods"> Built-in Methods </h3>
<p>A string in JavaScript has some built-in methods to manipulate the string, though the result is always a new string -
or something else, eg. split returns an <a href="/Types/#Array" title="Types">array</a>.
</p>
<pre><code data-lang="javascript">"hello".charAt( 0 ) // "h"
"hello".toUpperCase() // "HELLO"
"Hello".toLowerCase() // "hello"
"hello".replace( /e|o/g, "x" ) // "hxllx"
"1,2,3".split( "," ) // [ "1", "2", "3" ]
</code></pre>
<h3 id="Length_Property"> Length Property </h3>
<p>All strings have a length property.
</p>
<pre><code data-lang="javascript">"Hello".length // 5
"".length // 0
</code></pre>
<h3 id="Boolean_Default"> Boolean Default </h3>
<p>An empty string defaults to false:
</p>
<pre><code data-lang="javascript">!"" // true
!!"" // false
!"hello" // false
!"true" // false
!new Boolean( false ) // false
</code></pre>
<h2 id="htmlString"> htmlString </h2>
<p>A string is designated <strong>htmlString</strong> in jQuery documentation when it is used to represent one or more
DOM elements, typically to be created and inserted in the document. When passed as an argument of the
<code>jQuery()</code> function, the string is identified as HTML if it starts with <code>&lt;tag ... &gt;</code>) and
is parsed as such until the final <code>&gt;</code> character. Prior to jQuery 1.9, a string was considered to be HTML
if it contained <code>&lt;tag ... &gt;</code> <em>anywhere within the string</em>.</p>
<p>When a string is passed as an argument to a manipulation method such as <code>.append()</code>, it is always
considered to be HTML since jQuery's other common interpretation of a string (CSS selectors) does not apply in those
contexts.</p>
<p>For explicit parsing of a string to HTML, the <code><a href="/jQuery.parseHTML/">$.parseHTML()</a></code> method is
available as of jQuery 1.8.</p>
<pre><code data-lang="javascript">// Appends <b>hello</b>:
$( "<b>hello</b>" ).appendTo( "body" );
// Appends <b>hello</b>:
$( "<b>hello</b>bye" ).appendTo( "body" );
// Syntax error, unrecognized expression: bye<b>hello</b>
$( "bye<b>hello</b>" ).appendTo( "body" );
// Appends bye<b>hello</b>:
$( $.parseHTML( "bye<b>hello</b>" ) ).appendTo( "body" );
// Appends <b>hello</b>wait<b>bye</b>:
$( "<b>hello</b>wait<b>bye</b>" ).appendTo( "body" );
</code></pre>
<h2 id="Number"> Number </h2>
<p>Numbers in JavaScript are double-precision 64-bit format IEEE 754 values. They are immutable primitive values, just
like <a href="#String" title="">strings</a>. All operators common in c-based languages are available to work with
numbers (+, -, *, /, %, =, +=, -=, *=, /=, ++, --).
</p>
<pre><code data-lang="javascript">12
3.543
</code></pre>
<p>The type of a number is "number".
</p>
<pre><code data-lang="javascript">typeof 12 // "number"
typeof 3.543 // "number"
</code></pre>
<h3 id="Boolean_Default_2"> Boolean Default </h3>
<p>If a number is zero, it defaults to false:
</p>
<pre><code data-lang="javascript">!0 // true
!!0 // false
!1 // false
!-1 // false
</code></pre>
<p>Due to the implementation of numbers as double-precision values, the following result is not an error:
</p>
<pre><code data-lang="javascript">0.1 + 0.2 // 0.30000000000000004
</code></pre>
<p><br>
</p>
<h3 id="Math"> Math </h3>
<p>JavaScript provides utilities to work with numbers in the Math object:
</p>
<pre><code data-lang="javascript">Math.PI // 3.141592653589793
Math.cos( Math.PI ) // -1
</code></pre>
<h3 id="Parsing_Numbers"> Parsing Numbers </h3>
<p>parseInt and parseFloat help parsing strings into numbers. Both do some implicit conversion if the base isn't
specified:
</p>
<pre><code data-lang="javascript">parseInt( "123" ) = 123 // (implicit decimal)
parseInt( "010" ) = 8 // (implicit octal)
parseInt( "0xCAFE" ) = 51966 // (implicit hexadecimal)
parseInt( "010", 10 ) = 10 // (explicit decimal)
parseInt( "11", 2 ) = 3 // (explicit binary)
parseFloat( "10.10" ) = 10.1
</code></pre>
<h3 id="Numbers_to_Strings"> Numbers to Strings </h3>
<p>When appending numbers to string, the result is always a string. The operator is the same, so be careful: If you want
to add numbers and then append them to a string, put parentheses around the numbers:
</p>
<pre><code data-lang="javascript">"" + 1 + 2; // "12"
"" + ( 1 + 2 ); // "3"
"" + 0.0000001; // "1e-7"
parseInt( 0.0000001 ); // 1 (!)
</code></pre>
<p>Or you use the String class provided by javascript, which try to parse a value as string:
</p>
<pre><code data-lang="javascript">String( 1 ) + String( 2 ); // "12"
String( 1 + 2 ); // "3"
</code></pre>
<h3 id="NaN_and_Infinity"> NaN and Infinity </h3>
<p>Parsing something that isn't a number results in NaN. isNaN helps to detect those cases:
</p>
<pre><code data-lang="javascript">parseInt( "hello", 10 ) // NaN
isNaN( parseInt("hello", 10) ) // true
</code></pre>
<p>Division by zero results in Infinity:
</p>
<pre><code data-lang="javascript">1 / 0 // Infinity
</code></pre>
<p>Both NaN and Infinity are of type "number":
</p>
<pre><code data-lang="javascript">typeof NaN // "number"
typeof Infinity // "number"
</code></pre>
<p>Note that NaN compares in a strange way:
</p>
<pre><code data-lang="javascript">NaN === NaN // false (!)
</code></pre>
<p>But:
</p>
<pre><code data-lang="javascript">Infinity === Infinity // true
</code></pre>
<h3 id="Integer"> Integer </h3>
<p>An integer is a plain Number type, but whenever explicitly mentioned, indicates that a non-floating-point number is
expected.
</p>
<h3 id="Float"> Float </h3>
<p>A float is a plain Number type, just as Integer, but whenever explicitly mentioned, indicates that a floating-point
number is expected.
</p>
<p><br>
</p>
<h2 id="Boolean"> Boolean </h2>
<p>A boolean in JavaScript can be either true or false:
</p>
<pre><code data-lang="javascript">if ( true ) console.log( "always!" );
if ( false ) console.log( "never!" );
</code></pre>
<h2 id="Object"> Object </h2>
<p>Everything in JavaScript is an object, though some are more objective (haha). The easiest way to create an object is
the object literal:
</p>
<pre><code data-lang="javascript">var x = {};
var y = {
name: "Pete",
age: 15
};
</code></pre>
<p>The type of an object is "object":
</p>
<pre><code data-lang="javascript">typeof {} // "object"
</code></pre>
<h3 id="Dot_Notation"> Dot Notation </h3>
<p>You can write and read properties of an object using the dot notation:
</p>
<pre><code data-lang="javascript">y.name // "Pete"
y.age // 15
x.name = y.name + " Pan" // "Pete Pan"
x.age = y.age + 1 // 16
</code></pre>
<h3 id="Array_Notation"> Array Notation </h3>
<p>Or you write and read properties using the array notation, which allows you to dynamically choose the property:
</p>
<pre><code data-lang="javascript">var operations = {
increase: "++",
decrease: "--"
};
var operation = "increase";
operations[ operation ] // "++"
operations[ "multiply" ] = "*"; // "*"
</code></pre>
<h3 id="Iteration"> Iteration </h3>
<p>Iterating over objects is easy with the for-in-loop:
</p>
<pre><code data-lang="javascript">var obj = {
name: "Pete",
age: 15
};
for( key in obj ) {
alert( "key is " + [ key ] + ", value is " + obj[ key ] );
}
</code></pre>
<p>Note that for-in-loop can be spoiled by extending Object.prototype (see <a href="http://erik.eae.net/archives/2005/06/06/22.13.54/" class="external text" title="http://erik.eae.net/archives/2005/06/06/22.13.54/">Object.prototype is verboten</a>) so take care when using
other libraries.
</p>
<p>jQuery provides a generic <a href="/jQuery.each/"><em>each</em> function</a> to iterate over properties of objects,
as well as elements of arrays:
</p>
<pre><code data-lang="javascript">jQuery.each( obj, function( key, value ) {
console.log( "key", key, "value", value );
});
</code></pre>
<p>The drawback is that the callback is called in the context of each value and you therefore lose the context of your
own object if applicable. More on this below at Functions.
</p>
<h3 id="Boolean_default_3"> Boolean default </h3>
<p>An object, no matter if it has properties or not, never defaults to false:
</p>
<pre><code data-lang="javascript">!{} // false
!!{} // true
</code></pre>
<h3 id="Prototype"> Prototype </h3>
<p>All objects have a prototype property. Whenever the interpreter looks for a property, it also checks in the object's
prototype if the property is not found on the object itself. jQuery uses the prototype extensively to add methods to
jQuery instances. Internally, jQuery makes <code>jQuery.fn</code> an alias of <code>jQuery.prototype</code> so you can
use either one (though plugin developers have standardized on <code>fn</code>).
</p>
<pre><code data-lang="javascript">var form = $("#myform");
console.log( form.clearForm ); // undefined
// jQuery.fn === jQuery.prototype
jQuery.fn.clearForm = function() {
return this.find( ":input" ).each(function() {
this.value = "";
}).end();
};
// works for all instances of jQuery objects, because
// the new method was added to the prototype
console.log( form.clearForm ); // function
form.clearForm();
</code></pre>
<h2 id="Array"> Array </h2>
<p>Arrays in JavaScript are mutable lists with a few built-in methods. You can define arrays using the array literal:
</p>
<pre><code data-lang="javascript">var x = [];
var y = [ 1, 2, 3 ];
</code></pre>
<p>The type of an array is "object":
</p>
<pre><code data-lang="javascript">typeof []; // "object"
typeof [ 1, 2, 3 ]; // "object"
</code></pre>
<p>Reading and writing elements to an array uses the array-notation:
</p>
<pre><code data-lang="javascript">x[ 0 ] = 1;
y[ 2 ] // 3
</code></pre>
<h3 id="Iteration_2"> Iteration </h3>
<p>An array has a length property that is useful for iteration:
</p>
<pre><code data-lang="javascript">for ( var i = 0; i &lt; a.length; i++ ) {
// Do something with a[i]
}
</code></pre>
<p>When performance is critical, reading the length property only once can help to speed things up. This should be used
only when a performance bottleneck was discovered:
</p>
<pre><code data-lang="javascript">for ( var i = 0, j = a.length; i &lt; j; i++ ) {
// Do something with a[i]
}
</code></pre>
<p>Another variation defines a variable that is filled for each iteration, removing the array-notation from the
loop-body. It does not work when the array contains 0 or empty strings!
</p>
<pre><code data-lang="javascript">for ( var i = 0, item; item = a[i]; i++ ) {
// Do something with item
}
</code></pre>
<p>jQuery provides a generic <a href="/jQuery.each/"><em>each</em> function</a> to iterate over element of arrays, as
well as properties of objects:
</p>
<pre><code data-lang="javascript">var x = [ 1, 2, 3 ];
jQuery.each( x, function( index, value ) {
console.log( "index", index, "value", value );
});
</code></pre>
<p>The drawback is that the callback is called in the context of each value and you therefore lose the context of your
own object if applicable. More on this below at Functions.
</p>
<p>The length property can also be used to add elements to the end of an array. That is equivalent to using the
push-method:
</p>
<pre><code data-lang="javascript">var x = [];
x.push( 1 );
x[ x.length ] = 2;
x // [ 1, 2 ]
</code></pre>
<p>You'll see both variations a lot when looking through JavaScript library code.
</p>
<p>Other built-in methods are reverse, join, shift, unshift, pop, slice, splice and sort:
</p>
<pre><code data-lang="javascript">var x = [ 0, 3, 1, 2 ];
x.reverse() // [ 2, 1, 3, 0 ]
x.join(" – ") // "2 - 1 - 3 - 0"
x.pop() // [ 2, 1, 3 ]
x.unshift( -1 ) // [ -1, 2, 1, 3 ]
x.shift() // [ 2, 1, 3 ]
x.sort() // [ 1, 2, 3 ]
x.splice( 1, 2 ) // [ 2, 3 ]
</code></pre>
<p>Note: .unshift() method does not return a length property in Internet Explorer.
</p>
<h3 id="Boolean_Default_4"> Boolean Default </h3>
<p>An array, no matter if it has elements or not, never defaults to false:
</p>
<pre><code data-lang="javascript">![] // false
!![] // true
</code></pre>
<h3 id="Array.3CType.3E_Notation"> Array&lt;Type&gt; Notation </h3>
<p>In the jQuery API you'll often find the notation of Array&lt;Type&gt;:
</p>
<pre>dragPrevention Array&lt;String&gt;
</pre>
<p>This indicates that the method doesn't only expect an array as the argument, but also specifies the expected type.
The notation is borrowed from Java 5's generics notation (or C++ templates).
</p>
<h2 id="ArrayLikeObject">Array-Like Object</h2>
<p>Either a true JavaScript Array or a JavaScript Object that contains a nonnegative integer <code>length</code>
property and index properties from <code>0</code> up to <code>length - 1</code>. This latter case includes array-like
objects commonly encountered in web-based code such as the <code>arguments</code> object and the <code>NodeList</code>
object returned by many DOM methods.</p>
<p>When a jQuery API accepts either plain Objects or Array-Like objects, a plain Object with a numeric
<code>length</code> property will trigger the Array-Like behavior.</p>
<h2 id="PlainObject"> PlainObject </h2>
<p>The PlainObject type is a JavaScript object containing zero or more key-value pairs. The plain object is, in other
words, an <code>Object</code> object. It is designated "plain" in jQuery documentation to distinguish it from other
kinds of JavaScript objects: for example, <code>null</code>, user-defined arrays, and host objects such as
<code>document</code>, all of which have a <code>typeof</code> value of "object." The
<code><a href="/jQuery.isPlainObject/">jQuery.isPlainObject()</a></code> method identifies whether the passed argument
is a plain object or not, as demonstrated below:
</p>
<pre><code data-lang="javascript">
var a = [];
var d = document;
var o = {};
typeof a; // object
typeof d; // object
typeof o; // object
jQuery.isPlainObject( a ); // false
jQuery.isPlainObject( d ); // false
jQuery.isPlainObject( o ); // true
</code></pre>
<h2 id="Null">Null</h2>
<p>The <code>null</code> keyword is a JavaScript literal that is commonly used to express the absence of an intentional
value.</p>
<h2 id="Date"> Date </h2>
<p>The Date type is a JavaScript object that represents a single moment in time. Date objects are instantiated using
their constructor function, which by default creates an object that represents the current date and time.
</p>
<pre><code data-lang="javascript">
new Date();
</code></pre>
<p>To create a Date object for an alternative date and time, pass numeric arguments in the following order: year, month,
day, hour, minute, second, millisecond — although note that the month is zero-based, whereas the other arguments are
one-based. The following creates a Date object representing January 1st, 2014, at 8:15.
</p>
<pre><code data-lang="javascript">
new Date( 2014, 0, 1, 8, 15 );
</code></pre>
<h2 id="Function"> Function </h2>
<p>A function in JavaScript can be either named or anonymous. Any function can be assigned to a variable or passed to a
method, but passing member functions this way can cause them to be called in the context of another object (i.e. with
a different "this" object).
</p>
<pre><code data-lang="javascript">function named() {}
var handler = function() {}
</code></pre>
<p>You see a lot of anonymous functions in jQuery code:
</p>
<pre><code data-lang="javascript">$( document ).ready(function() {});
$( "a" ).click(function() {});
$.ajax({
url: "someurl.php",
success: function() {}
});
</code></pre>
<p>The type of a function is "function".
</p>
<h3 id="Arguments"> Arguments </h3>
<p>Inside a function a special variable "arguments" is always available. It's similar to an array in that it has a
length property, but it lacks the built-in methods of an array. The elements of the pseudo-array are the argument of
the function call.
</p>
<pre><code data-lang="javascript">function log( x ) {
console.log( typeof x, arguments.length );
}
log(); // "undefined", 0
log( 1 ); // "number", 1
log( "1", "2", "3" ); // "string", 3
</code></pre>
<p>The arguments object also has a callee property, which refers to the function you're inside of. For instance:
</p>
<pre><code data-lang="javascript">var awesome = function() { return arguments.callee; }
awesome() === awesome // true
</code></pre>
<h3 id="Context.2C_Call_and_Apply"> Context, Call and Apply </h3>
<p>In JavaScript, the variable "this" always refers to the current context. By default, "this" refers to the window
object. Within a function this context can change, depending on how the function is called.
</p>
<p>All event handlers in jQuery are called with the handling element as the context.
</p>
<pre><code data-lang="javascript">$( document ).ready(function() {
// this refers to window.document
});
$( "a" ).click(function() {
// this refers to an anchor DOM element
});
</code></pre>
<p>You can specify the context for a function call using the function-built-in methods call and apply. The difference
between them is how they pass arguments. Call passes all arguments through as arguments to the function, while apply
accepts an array as the arguments.
</p>
<pre><code data-lang="javascript">function scope() {
console.log( this, arguments.length );
}
scope() // window, 0
scope.call( "foobar", [ 1, 2 ] ); // "foobar", 1
scope.apply( "foobar", [ 1, 2 ] ); // "foobar", 2
</code></pre>
<h3 id="Scope"> Scope </h3>
<p>In JavaScript, all variables defined inside a function are only visible inside that function scope. Consider the
following example:
</p>
<pre><code data-lang="javascript">// global
var x = 0;
(function() {
// private
var x = 1;
console.log( x ); // 1
})();
console.log( x ); // 0
</code></pre>
<p>It defines a variable <i>x</i> in the global scope, then defines an anonymous function and executes it immediately
(the additional parentheses are required for immediate execution). Inside the function another variable <i>x</i> is
defined with a different value. It is only visible within that function and doesn't overwrite the global variable.
</p>
<h3 id="Closures"> Closures </h3>
<p>Closures are created whenever a variable that is defined outside the current scope is accessed from within some inner
scope. In the following example, the variable <i>counter</i> is visible within the create, increment, and print
functions, but not outside of them.
</p>
<pre><code data-lang="javascript">function create() {
var counter = 0;
return {
increment: function() {
counter++;
},
print: function() {
console.log( counter );
}
}
}
var c = create();
c.increment();
c.print(); // 1
</code></pre>
<p>The pattern allows you to create objects with methods that operate on data that isn't visible to the outside—the very
basis of object-oriented programming.
</p>
<h3 id="Proxy_Pattern"> Proxy Pattern </h3>
<p>Combining the above knowledge gives you as a JavaScript developer quite a lot of power. One way to combine that is to
implement a proxy pattern in JavaScript, enabling the basics of aspect-oriented programming (AOP):
</p>
<pre><code data-lang="javascript">(function() {
// log all calls to setArray
var proxied = jQuery.fn.setArray;
jQuery.fn.setArray = function() {
console.log( this, arguments );
return proxied.apply( this, arguments );
};
})();
</code></pre>
<p>The above wraps its code in a function to hide the "proxied"-variable. It saves jQuery's setArray-method in a closure
and overwrites it. The proxy then logs all calls to the method and delegates the call to the original. Using
apply(this, arguments) guarantees that the caller won't be able to notice the difference between the original and the
proxied method.
</p>
<h2 id="Callback"> Callback </h2>
<p>A callback is a plain JavaScript function passed to some method as an argument or option. Some callbacks are just
events, called to give the user a chance to react when a certain state is triggered. jQuery's event system uses such
callbacks everywhere:
</p>
<pre><code data-lang="javascript">$( "body" ).click(function( event ) {
console.log( "clicked: " + event.target );
});
</code></pre>
<p>Most callbacks provide arguments and a context. In the event-handler example, the callback is called with one
argument, an Event. The context is set to the handling element, in the above example, document.body.
</p>
<p>Some callbacks are required to return something, others make that return value optional. To prevent a form
submission, a submit event handler can return false:
</p>
<pre><code data-lang="javascript">$( "#myform" ).submit(function() {
return false;
});
</code></pre>
<p>Instead of always returning false, the callback could check fields of the form for validity, and return false only
when the form is invalid.
</p>
<h2 id="Error"> Error </h2>
<p>An instance of an Error object is thrown as an exception when a runtime error occurs. Error can also be used as base
to define user custom exception classes. In JavaScript an error can be thrown as shown below:
</p>
<pre><code data-lang="javascript">throw new Error( "The argument provided is incorrect" );
</code></pre>
<p>An error can also be thrown by the engine under some circumstances. For example, when trying to access a property of
<code>null</code>:
</p>
<pre><code data-lang="javascript">var obj = null;
console.log( obj.foo() );
</code></pre>
<h2 id="Selector"> Selector </h2>
<p>A selector is used in jQuery to select DOM elements from a DOM document. That document is, in most cases, the DOM
document present in all browsers, but can also be an XML document received via Ajax.
</p>
<p>The selectors are a composition of CSS and custom additions. All selectors available in jQuery are documented on the
<a href="/category/selectors/" title="Selectors">Selectors API page</a>.
</p>
<p>There are lot of plugins that leverage jQuery's selectors in other ways. The validation plugin accepts a selector to
specify a dependency, whether an input is required or not:
</p>
<pre><code data-lang="javascript">emailrules: {
required: "#email:filled"
}
</code></pre>
<p>This would make a checkbox with name "emailrules" required only if the user entered an email address in the email
field, selected via its id, filtered via a custom selector ":filled" that the validation plugin provides.
</p>
<p>If Selector is specified as the type of an argument, it accepts everything that the jQuery constructor accepts, eg.
Strings, Elements, Lists of Elements.
</p>
<h2 id="Event">Event</h2>
<p>jQuery's event system normalizes the event object according to W3C standards. The event object is guaranteed to be
passed to the event handler (no checks for window.event required). It normalizes the target, relatedTarget, which,
metaKey and pageX/Y properties and provides both stopPropagation() and preventDefault() methods.
</p>
<p>Those properties are all documented, and accompanied by examples, on the <a href="/category/events/event-object/" title="Events">Event object</a> page.
</p>
<p>The standard events in the Document Object Model are: <code>blur</code>, <code>focus</code>, <code>load</code>,
<code>resize</code>, <code>scroll</code>, <code>unload</code>, <code>beforeunload</code>, <code>click</code>,
<code>dblclick</code>, <code>mousedown</code>, <code>mouseup</code>, <code>mousemove</code>, <code>mouseover</code>,
<code>mouseout</code>, <code>mouseenter</code>, <code>mouseleave</code>, <code>change</code>, <code>select</code>,
<code>submit</code>, <code>keydown</code>, <code>keypress,</code> and <code>keyup</code>. Since the DOM event names
have predefined meanings for some elements, using them for other purposes is not recommended. jQuery's event model can
trigger an event by any name on an element, and it is propagated up the DOM tree to which that element belongs, if
any.
</p>
<h2 id="Element"> Element </h2>
<p>An element in the Document Object Model (DOM) can have attributes, text, and children. It provides methods to
traverse the parent and children and to get access to its attributes. Due to inconsistencies in DOM API specifications
and implementations, however, those methods can be a challenge to use. jQuery provides a "wrapper" around those
elements to help interacting with the DOM. But sometimes you will be working directly with DOM elements, or see
methods that (also) accept DOM elements as arguments.
</p>
<p>Whenever you call jQuery's <code>.each()</code> method or one of its event methods on a jQuery collection, the
context of the callback function — <code>this</code> — is set to a DOM element.
</p>
<p>Some properties of DOM elements are quite consistent among browsers. Consider this example of a simple onblur
validation:
</p>
<pre><code data-lang="javascript">$( "input[type='text']" ).on( "blur", function() {
if( !this.value ) {
alert( "Please enter some text!" );
}
});
</code></pre>
<p>You could replace <code>this.value</code> with <code>$(this).val()</code> to access the value of the text input via
jQuery, but in that case you wouldn't gain anything.
</p>
<h2 id="Text"> Text </h2>
<p>Text is a node of the Document Object Model (DOM) that represents the textual content of an <a href="#Element">element</a> or an attribute. Consider the following code:
</p>
<pre><code>&lt;p id="target"&gt;&lt;b&gt;Hello&lt;/b&gt; world&lt;/p&gt;</code></pre>
<p>If you retrieve the children of the paragraph of the example as follows:
</p>
<pre><code data-lang="javascript">var children = document.getElementById( "target" ).childNodes;
</code></pre>
<p>you obtain two children. The first one is the <a href="#Element">element</a> representing the <code>b</code> tag. The
second child is a text node containing the string " world".
</p>
<h2 id="jQuery"> jQuery </h2>
<p>A jQuery object contains a collection of Document Object Model (DOM) elements that have been created from an HTML
string or selected from a document. Since jQuery methods often use CSS selectors to match elements from a document,
the set of elements in a jQuery object is often called a set of "matched elements" or "selected elements".
</p>
<p>The jQuery object itself behaves much like an array; it has a <code>length</code> property and the elements in the
object can be accessed by their numeric indices <code>[0]</code> to <code>[length-1]</code>. Note that a jQuery object
is not actually a Javascript Array object, so it does not have all the methods of a true Array object such as
<code>join()</code>.
</p>
<p>Most frequently, you will use the jQuery() function to create a jQuery object. <code>jQuery()</code> can also be
accessed by its familiar single-character alias of <code>$()</code>, unless you have called
<code>jQuery.noConflict()</code> to disable this option. Many jQuery methods return the jQuery object itself, so that
method calls can be chained:
</p>
<p>In API calls that return <code>jQuery</code>, the value returned will be the original jQuery object unless otherwise
documented by that API. API methods such as <code>.filter()</code> or <code>.not()</code> modify their incoming set
and thus return a new jQuery object.
</p>
<pre><code data-lang="javascript">$( "p" ).css( "color", "red" ).find( ".special" ).css( "color", "green" );
</code></pre>
<p>Whenever you use a "destructive" jQuery method that potentially changes the set of elements in the jQuery object,
such as <code>.filter()</code> or <code>.find()</code>, that method actually returns a new jQuery object with the
resulting elements. To return to the previous jQuery object, you use the <code>.end()</code> method.
</p>
<p>A jQuery object may be empty, containing no DOM elements. You can create an empty jQuery object with <code>$()</code>
(that is, passing no arguments at all). A jQuery object may also be empty if a selector doesn't select any elements,
or if a chained method filters out all the elements. It is not an error; any further methods called on that jQuery
object simply have no effect since they have no elements to act upon. So, in this example if there are no bad entries
on the page then no elements will be colored red:
</p>
<pre><code data-lang="javascript">$( ".badEntry" ).css({ color: "red" });
</code></pre>
<h2 id="XMLHttpRequest"> XMLHttpRequest </h2>
<p>Some of jQuery's Ajax functions return the native XMLHttpRequest (XHR) object, or pass it as an argument to
success/error/complete handlers, so that you can do additional processing or monitoring on the request. Note that Ajax
functions only return or pass an XHR object when an XHR object is actually used in the request. For example, JSONP
requests and cross-domain GET requests use a script element rather than an XHR object.
</p>
<p>Although the XHR object is a standard, there are variations in its behavior on different browsers. Refer to the
WHATWG site and Mozilla Developer Network for more information:
</p>
<ul>
<li> <a href="https://xhr.spec.whatwg.org/" class="external text" title="https://xhr.spec.whatwg.org/">WHATWG living
standard</a>
</li>
<li> <a href="https://developer.mozilla.org/docs/DOM/XMLHttpRequest" class="external text" title="https://developer.mozilla.org/docs/DOM/XMLHttpRequest">Mozilla Developer Network</a>
</li>
</ul>
<h2 id="jqXHR"> jqXHR </h2>
<p>As of jQuery 1.5, the <a href="/jQuery.ajax/">$.ajax()</a> method returns the jqXHR object, which is a superset of
the XMLHTTPRequest object. For more information, see the <a href="/jQuery.ajax/#jqXHR">jqXHR section of the $.ajax
entry</a>
</p>
<h2 id="Thenable">Thenable</h2>
<p>Any object that has a <code>then</code> method.</p>
<h2 id="Deferred"> Deferred Object</h2>
<p>As of jQuery 1.5, the <a href="/category/deferred-object/">Deferred</a> object provides a way to register multiple
callbacks into self-managed callback queues, invoke callback queues as appropriate, and relay the success or failure
state of any synchronous or asynchronous function.
</p>
<h2 id="Promise"> Promise Object</h2>
<p>This object provides a subset of the methods of the <a href="/category/deferred-object/">Deferred</a> object (<a href="/deferred.then/"><code>then</code></a>, <a href="/deferred.done/"><code>done</code></a>, <a href="/deferred.fail/"><code>fail</code></a>, <a href="/deferred.always/"><code>always</code></a>, <a href="/deferred.pipe/"><code>pipe</code></a>, <a href="/deferred.progress/"><code>progress</code></a>, <a href="/deferred.state/"><code>state</code></a> and <a href="/deferred.promise/"><code>promise</code></a>) to prevent
users from changing the state of the Deferred.
</p>
<h2 id="Callbacks">Callbacks Object</h2>
<p>A multi-purpose object that provides a powerful way to manage callback lists. It supports adding, removing, firing,
and disabling callbacks. The Callbacks object is created and returned by the <code>$.Callbacks</code> function and
subsequently returned by most of that function's methods. </p>
<h2 id="XMLDocument">XML Document</h2>
<p>A document object created by the browser's XML DOM parser, usually from a string representing XML. XML documents have
different semantics than HTML documents, but most of the traversing and manipulation methods provided by jQuery will
work with them.</p>
<h2 id="Assert">Assert</h2>
<p>A reference to or instance of the object holding all of QUnit's assertions. See the <a href="https://api.qunitjs.com/QUnit.assert/">API documentation for <code>QUnit.assert</code></a> for details.</p>`;
let categories = [{
"slug": "ajax",
"name": "Ajax",
"desc": "The jQuery library has a full suite of Ajax capabilities. The functions and methods therein allow us to load data from the server without a browser page refresh. ",
"children": [{
"slug": "global-ajax-event-handlers",
"name": "Global Ajax Event Handlers",
"desc": "These methods register handlers to be called when certain events, such as initialization or completion, take place for any Ajax request on the page. The global events are fired on each Ajax request if the <code>global</code> property in <a href=\"/jQuery.ajaxSetup/\"><code>jQuery.ajaxSetup()</code></a> is <code>true</code>, which it is by default. <em>Note: Global events are never fired for cross-domain script or JSONP requests, regardless of the value of <code>global</code>.</em>"
},
{
"slug": "helper-functions",
"name": "Helper Functions",
"desc": "These functions assist with common idioms encountered when performing Ajax tasks."
},
{
"slug": "low-level-interface",
"name": "Low-Level Interface",
"desc": "These methods can be used to make arbitrary Ajax requests."
},
{
"slug": "shorthand-methods",
"name": "Shorthand Methods",
"desc": "These methods perform the more common types of Ajax requests in less code."
}
]
},
{
"slug": "attributes",
"name": "Attributes",
"desc": "These methods get and set DOM attributes of elements."
},
{
"slug": "callbacks-object",
"name": "Callbacks Object",
"desc": "The <code>jQuery.Callbacks()</code> function, introduced in version 1.7, returns a multi-purpose object that provides a powerful way to manage callback lists. It supports adding, removing, firing, and disabling callbacks."
},
{
"slug": "core",
"name": "Core",
"desc": ""
},
{
"slug": "css",
"name": "CSS",
"desc": "These methods get and set CSS-related properties of elements."
},
{
"slug": "data",
"name": "Data",
"desc": "These methods allow us to associate arbitrary data with specific DOM elements."
},
{
"slug": "deferred-object",
"name": "Deferred Object",
"desc": "<p>The Deferred object, introduced in jQuery 1.5, is a chainable utility object created by calling the <a href=\"/jQuery.Deferred/\"><code>jQuery.Deferred()</code></a> method. It can register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.</p>\n <p>The Deferred object is chainable, similar to the way a jQuery object is chainable, but it has its own methods. After creating a Deferred object, you can use any of the methods below by either chaining directly from the object creation or saving the object in a variable and invoking one or more methods on that variable.</p>"
},
{
"slug": "deprecated",
"name": "Deprecated",
"desc": "",
"children": [{
"slug": "deprecated-1.3",
"name": "Deprecated 1.3",
"desc": "All the aspects of the API that were deprecated in the corresponding version of jQuery.\n <p>For more information, see the <a href=\"https://blog.jquery.com/2009/01/14/jquery-1-3-released/\">jQuery 1.3 Release Notes</a>.</p>\n "
},
{
"slug": "deprecated-1.7",
"name": "Deprecated 1.7",
"desc": "All the aspects of the API that were deprecated in the corresponding version of jQuery.\n <p>For more information, see the Release Notes/Changelog at <a href=\"https://blog.jquery.com/2011/11/03/jquery-1-7-released/\">https://blog.jquery.com/2011/11/03/jquery-1-7-released/</a></p>\n "
},
{
"slug": "deprecated-1.8",
"name": "Deprecated 1.8",
"desc": "All the aspects of the API that were deprecated in the corresponding version of jQuery.\n <p>For more information, see the Release Notes/Changelog at <a href=\"https://blog.jquery.com/2012/08/09/jquery-1-8-released/\">https://blog.jquery.com/2012/08/09/jquery-1-8-released/</a></p>\n "
},
{
"slug": "deprecated-1.9",
"name": "Deprecated 1.9",
"desc": "All the aspects of the API that were deprecated in the corresponding version of jQuery.\n <p>For more information, see the Release Notes/Changelog at <a href=\"https://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/\">https://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/</a></p>\n "
},
{
"slug": "deprecated-1.10",
"name": "Deprecated 1.10",
"desc": "All the aspects of the API that were deprecated in the corresponding version of jQuery.\n <p>For more information, see the Release Notes/Changelog at <a href=\"https://blog.jquery.com/2013/05/24/jquery-1-10-0-and-2-0-1-released/\">https://blog.jquery.com/2013/05/24/jquery-1-10-0-and-2-0-1-released/</a></p>\n "
},
{
"slug": "deprecated-3.0",
"name": "Deprecated 3.0",
"desc": "All the aspects of the API that were deprecated in the corresponding version of jQuery.\n <p>For more information, see the Release Notes/Changelog at <a href=\"https://blog.jquery.com/2016/06/09/jquery-3-0-final-released/\">https://blog.jquery.com/2016/06/09/jquery-3-0-final-released/</a></p>\n "
},
{
"slug": "deprecated-3.3",
"name": "Deprecated 3.3",
"desc": "All the aspects of the API that were deprecated in the corresponding version of jQuery.\n <p>For more information, see the Release Notes/Changelog at <a href=\"https://blog.jquery.com/2018/01/19/jquery-3-3-0-a-fragrant-bouquet-of-deprecations-and-is-that-a-new-feature/\">https://blog.jquery.com/2018/01/19/jquery-3-3-0-a-fragrant-bouquet-of-deprecations-and-is-that-a-new-feature/</a></p>\n "
},
{
"slug": "deprecated-3.4",
"name": "Deprecated 3.4",
"desc": "All the aspects of the API that were deprecated in the corresponding version of jQuery.\n <p>For more information, see the Release Notes/Changelog at <a href=\"https://blog.jquery.com/2019/04/10/jquery-3-4-0-released/\">https://blog.jquery.com/2019/04/10/jquery-3-4-0-released/</a></p>\n "
}
]
},
{
"slug": "dimensions",
"name": "Dimensions",
"desc": "These methods are used to get and set the CSS dimensions for the various properties."
},
{
"slug": "effects",
"name": "Effects",
"desc": "The jQuery library provides several techniques for adding animation to a web page. These include simple, standard animations that are frequently used, and the ability to craft sophisticated custom effects.",
"children": [{
"slug": "basics",
"name": "Basics",
"desc": ""
},
{
"slug": "custom-effects",
"name": "Custom",
"desc": "These methods allow you to create effects that are not provided \"out of the box\" by jQuery."
},
{
"slug": "fading",
"name": "Fading",
"desc": "These methods adjust the opacity of elements."
},
{
"slug": "sliding",
"name": "Sliding",
"desc": ""
}
]
},
{
"slug": "events",
"name": "Events",
"desc": "These methods are used to register behaviors to take effect when the user interacts with the browser, and to further manipulate those registered behaviors.",
"children": [{
"slug": "browser-events",
"name": "Browser Events",
"desc": ""
},
{
"slug": "document-loading",
"name": "Document Loading",
"desc": ""
},
{
"slug": "event-handler-attachment",
"name": "Event Handler Attachment",
"desc": ""
},
{
"slug": "event-object",
"name": "Event Object",
"desc": "\n <p>jQuery's event system normalizes the event object according to <a href=\"https://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html\">W3C standards</a>. The event object is guaranteed to be passed to the event handler. Most properties from the original event are copied over and normalized to the new event object.</p>\n <div class=\"longdesc\">\n <h4>jQuery.Event Constructor</h4>\n <p>The <code>jQuery.Event</code> constructor is exposed and can be used when calling <a href=\"/trigger\">trigger</a>. The <code>new</code> operator is optional.</p>\n <p>Check <a href=\"/trigger\">trigger</a>'s documentation to see how to combine it with your own event object.</p>\n <p>Example:</p>\n <pre><code>//Create a new jQuery.Event object without the \"new\" operator.\nvar e = jQuery.Event( \"click\" );\n\n// trigger an artificial click event\njQuery( \"body\" ).trigger( e );\n</code></pre>\n <p>As of jQuery 1.6, you can also pass an object to <code>jQuery.Event()</code> and its properties will be set on the newly created Event object.</p>\n <p>Example:</p>\n <pre><code>// Create a new jQuery.Event object with specified event properties.\nvar e = jQuery.Event( \"keydown\", { keyCode: 64 } );\n\n// trigger an artificial keydown event with keyCode 64\njQuery( \"body\" ).trigger( e );\n</code></pre>\n <h4>Common Event Properties</h4>\n <p>jQuery normalizes the following properties for cross-browser consistency:</p>\n <ul>\n <li>\n <code>target</code>\n </li>\n <li>\n <code>relatedTarget</code>\n </li>\n <li>\n <code>pageX</code>\n </li>\n <li>\n <code>pageY</code>\n </li>\n <li>\n <code>which</code>\n </li>\n <li>\n <code>metaKey</code>\n </li>\n </ul>\n <p>The following properties are also copied to the event object, though some of their values may be undefined depending on the event:</p>\n <p>altKey, bubbles, button, buttons, cancelable, char, charCode, clientX, clientY, ctrlKey, currentTarget, data, detail, eventPhase, key, keyCode, metaKey, offsetX, offsetY, originalTarget, pageX, pageY, relatedTarget, screenX, screenY, shiftKey, target, toElement, view, which</p>\n <h4>Other Properties</h4>\n <p>To access event properties not listed above, use the <code>event.originalEvent</code> object:</p>\n <pre><code>// Access the `dataTransfer` property from the `drop` event which\n// holds the files dropped into the browser window.\nvar files = event.originalEvent.dataTransfer.files;\n</code></pre>\n </div>\n "
},
{
"slug": "form-events",
"name": "Form Events",
"desc": ""
},
{
"slug": "keyboard-events",
"name": "Keyboard Events",
"desc": ""
},
{
"slug": "mouse-events",
"name": "Mouse Events",
"desc": ""
}
]
},
{
"slug": "forms",
"name": "Forms",
"desc": "These methods and event handlers handle forms and their various elements."
},
{
"slug": "internals",
"name": "Internals",
"desc": "Although this category is referred to as 'internal', any methods documented within the API site should be considered public and may be freely used. "
},
{
"slug": "manipulation",
"name": "Manipulation",
"desc": "All of the methods in this section manipulate the DOM in some manner. A few of them simply change one of the attributes of an element (also listed in the <a href=\"/category/attributes/\">Attributes category</a>), while others set an element's style properties (also listed in the <a href=\"/category/css/\">CSS category</a>). Still others modify entire elements (or groups of elements) themselves&#x2014;inserting, copying, removing, and so on. All of these methods are referred to as \"setters,\" as they change the values of properties.\n\t\t\tA few of these methods&#x2014;such as <code>.attr()</code>, <code>.html()</code>, and <code>.val()</code>&#x2014;also act as \"getters,\" retrieving information from DOM elements for later use.\n\t\t",
"children": [{
"slug": "class-attribute",
"name": "Class Attribute",
"desc": "These methods inspect and manipulate the CSS classes assigned to elements."
},
{
"slug": "copying",
"name": "Copying",
"desc": "This method allows us to make copies of elements."
},
{
"slug": "dom-insertion",
"name": "DOM Insertion",
"desc": ""
},
{
"slug": "dom-insertion-around",
"name": "DOM Insertion, Around",
"desc": "These methods allow us to insert new content surrounding existing content."
},
{
"slug": "dom-insertion-inside",
"name": "DOM Insertion, Inside",
"desc": "These methods allow us to insert new content inside an existing element."
},
{
"slug": "dom-insertion-outside",
"name": "DOM Insertion, Outside",
"desc": "These methods allow us to insert new content outside an existing element."
},
{
"slug": "dom-removal",
"name": "DOM Removal",
"desc": "These methods allow us to delete elements from the DOM."
},
{
"slug": "dom-replacement",
"name": "DOM Replacement",
"desc": "These methods are used to remove content from the DOM and replace it with new content."
},
{
"slug": "general-attributes",
"name": "General Attributes",
"desc": "These methods get and set DOM attributes of elements"
},
{
"slug": "style-properties",
"name": "Style Properties",
"desc": "These methods get and set CSS-related properties of elements."
}
]
},
{
"slug": "miscellaneous",
"name": "Miscellaneous",
"desc": "",
"children": [{
"slug": "collection-manipulation",
"name": "Collection Manipulation",
"desc": ""
},
{
"slug": "data-storage",
"name": "Data Storage",
"desc": "These methods allow us to associate arbitrary data with specific DOM elements."
},
{
"slug": "dom-element-methods",
"name": "DOM Element Methods",
"desc": ""
},
{
"slug": "setup-methods",
"name": "Setup Methods",
"desc": ""
}
]
},
{
"slug": "offset",
"name": "Offset",
"desc": ""
},
{
"slug": "properties",
"name": "Properties",
"desc": "",
"children": [{
"slug": "jquery-object-instance-properties",
"name": "Properties of jQuery Object Instances",
"desc": "Each jQuery object created with the jQuery() function contains a number of properties alongside its methods. These properties allow us to inspect various attributes of the object."
},
{
"slug": "global-jquery-object-properties",
"name": "Properties of the Global jQuery Object",
"desc": "These properties are associated with the global jQuery object."
}
]
},
{
"slug": "removed",
"name": "Removed",
"desc": ""
},
{
"slug": "selectors",
"name": "Selectors",
"desc": "\n <p>Borrowing from CSS 1&#x2013;3, and then adding its own, jQuery offers a powerful set of tools for matching a set of elements in a document.</p>\n <p>To use any of the meta-characters ( such as <code> !\"#$%&amp;'()*+,./:;&lt;=&gt;?@[\\]^`{|}~</code> ) as a literal part of a name, it must be escaped with with two backslashes: <code>\\\\</code>. For example, an element with <code>id=\"foo.bar\"</code>, can use the selector <code>$(\"#foo\\\\.bar\")</code>. The W3C CSS specification contains the <a href=\"https://www.w3.org/TR/CSS21/syndata.html#value-def-identifier\">complete set of rules regarding valid CSS selectors</a>. Also useful is the blog entry by Mathias Bynens on <a href=\"https://mathiasbynens.be/notes/css-escapes\">CSS character escape sequences for identifiers</a>.</p>\n ",
"children": [{
"slug": "attribute-selectors",
"name": "Attribute",
"desc": "\n <p>The CSS specification allows elements to be identified by their attributes. While not supported by some older browsers for the purpose of styling documents, jQuery allows you to employ them regardless of the browser being used.</p>\n <p>When using any of the following attribute selectors, you should account for attributes that have multiple, space-separated values. Since these selectors see attribute values as a single string, this selector, for example, <code>$(\"a[rel='nofollow']\")</code>, will select <code>&lt;a href=\"example.html\" rel=\"nofollow\"&gt;Some text&lt;/a&gt;</code> but not <code>&lt;a href=\"example.html\" rel=\"nofollow foe\"&gt;Some text&lt;/a&gt;</code>.</p>\n <p>Attribute values in selector expressions <b>must</b> follow the rules for W3C CSS selectors; in general, that means anything other than a <a href=\"https://www.w3.org/TR/CSS21/syndata.html#value-def-identifier\">valid identifier</a> should be surrounded by quotation marks.</p>\n <ul>\n <li>double quotes inside single quotes: <code>$('a[rel=\"nofollow self\"]')</code></li>\n <li>single quotes inside double quotes: <code>$(\"a[rel='nofollow self']\")</code></li>\n <li>escaped single quotes inside single quotes: <code>$('a[rel=\\'nofollow self\\']')</code></li>\n <li>escaped double quotes inside double quotes: <code>$(\"a[rel=\\\"nofollow self\\\"]\")</code></li>\n </ul>\n <p>The variation you choose is generally a matter of style or convenience.</p>\n\n <p><strong>Note</strong>: In jQuery 1.3 <code>[@attr]</code> style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the \"@\" symbol from your selectors in order to make them work again.</p>\n \n "
},
{
"slug": "basic-css-selectors",
"name": "Basic",
"desc": "The following selectors are based on the Cascading Style Sheet 1 specification, as outlined by the W3C. For more information about the specifications, visit <a href=\"https://www.w3.org/Style/CSS/#specs\">https://www.w3.org/Style/CSS/#specs</a>. "
},
{
"slug": "basic-filter-selectors",
"name": "Basic Filter",
"desc": ""
},
{
"slug": "child-filter-selectors",
"name": "Child Filter",
"desc": ""
},
{
"slug": "content-filter-selector",
"name": "Content Filter",
"desc": ""
},
{
"slug": "form-selectors",
"name": "Form",
"desc": ""
},
{
"slug": "hierarchy-selectors",
"name": "Hierarchy",
"desc": ""
},
{
"slug": "jquery-selector-extensions",
"name": "jQuery Extensions",
"desc": "jQuery has extended the CSS3 selectors with the following selectors. Because these selectors are jQuery extension and not part of the CSS specification, queries using them cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. To achieve the best performance when using these selectors, first select some elements using a pure CSS selector, then use <a href=\"https://api.jquery.com/filter/\"><code>.filter()</code></a>."
},
{
"slug": "visibility-filter-selectors",
"name": "Visibility Filter",
"desc": ""
}
]
},
{
"slug": "traversing",
"name": "Traversing",
"desc": "",
"children": [{
"slug": "filtering",
"name": "Filtering",
"desc": ""
},
{
"slug": "miscellaneous-traversal",
"name": "Miscellaneous Traversing",
"desc": ""
},
{
"slug": "tree-traversal",
"name": "Tree Traversal",
"desc": ""
}
]
},
{
"slug": "uncategorized",
"name": "Uncategorized"
},
{
"slug": "utilities",
"name": "Utilities",
"desc": ""
},
{
"slug": "version",
"name": "Version",
"desc": "",
"children": [{
"slug": "1.0",
"name": "Version 1.0",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\t<a href=\"https://blog.jquery.com/2006/08/26/jquery-10/\">jQuery 1.0 Release Notes</a>.\n\t\t\t"
},
{
"slug": "1.0.4",
"name": "Version 1.0.4",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\tRelease Notes: <a href=\"https://blog.jquery.com/2006/08/31/jquery-101/\">1.0.1</a>, <a href=\"https://blog.jquery.com/2006/10/09/jquery-102/\">1.0.2</a>, <a href=\"https://blog.jquery.com/2006/10/27/jquery-103/\">1.0.3</a>, <a href=\"https://blog.jquery.com/2006/12/12/jquery-104/\">1.0.4</a>.\n\t\t\t"
},
{
"slug": "1.1",
"name": "Version 1.1",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\t<a href=\"https://blog.jquery.com/2007/01/14/jquery-birthday-11-new-site-new-docs/\">jQuery 1.1 Release Notes</a>.\n\t\t\t"
},
{
"slug": "1.1.2",
"name": "Version 1.1.2",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\t<a href=\"https://blog.jquery.com/2007/02/27/jquery-112/\">jQuery 1.1.2 Release Notes</a>.\n\t\t\t"
},
{
"slug": "1.1.3",
"name": "Version 1.1.3",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\t<a href=\"https://blog.jquery.com/2007/07/01/jquery-113-800-faster-still-20kb/\">jQuery 1.1.3 Release Notes</a>\n\t\t\t"
},
{
"slug": "1.1.4",
"name": "Version 1.1.4",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\t<a href=\"https://blog.jquery.com/2007/08/24/jquery-114-faster-more-tests-ready-for-12/\">jQuery 1.1.4 Release Notes</a>.\n\t\t\t"
},
{
"slug": "1.2",
"name": "Version 1.2",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\t<a href=\"https://blog.jquery.com/2007/09/10/jquery-1-2-released/\">jQuery 1.2 Release Notes</a>\n\t\t\t"
},
{
"slug": "1.2.3",
"name": "Version 1.2.3",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\tRelease Notes: <a href=\"https://blog.jquery.com/2007/09/16/jquery-1-2-1-released/\">1.2.1</a>, <a href=\"https://blog.jquery.com/2008/01/14/jquery-1-2-2-released/\">1.2.2</a>, <a href=\"https://blog.jquery.com/2008/02/07/jquery-1-2-3-released/\">1.2.3</a>.\n\t\t\t"
},
{
"slug": "1.2.6",
"name": "Version 1.2.6",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\t<a href=\"https://blog.jquery.com/2008/05/24/jquery-1-2-6-released/\">jQuery 1.2.6 Release Notes</a>.\n\t\t\t"
},
{
"slug": "1.3",
"name": "Version 1.3",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\tRelease Notes: <a href=\"https://blog.jquery.com/2009/01/14/jquery-1-3-released/\">1.3</a>, <a href=\"https://blog.jquery.com/2009/01/21/jquery-131-released/\">1.3.1</a>, <a href=\"https://blog.jquery.com/2009/02/20/jquery-1-3-2-released/\">1.3.2</a>\n\t\t\t"
},
{
"slug": "1.4",
"name": "Version 1.4",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\t<a href=\"https://web.archive.org/web/20150119205819/http://jquery14.com/day-01/jquery-14\">jQuery 1.4 Release Notes</a>.\n\t\t\t"
},
{
"slug": "1.4.1",
"name": "Version 1.4.1",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\t<a href=\"https://web.archive.org/web/20150213113058/http://jquery14.com/day-12/jquery-141-released\">jQuery 1.4.1 Release Notes</a>.\n\t\t\t"
},
{
"slug": "1.4.2",
"name": "Version 1.4.2",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\t<a href=\"https://blog.jquery.com/2010/02/19/jquery-142-released/\">jQuery 1.4.2 Release Notes</a>.\n\t\t\t"
},
{
"slug": "1.4.3",
"name": "Version 1.4.3",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.\n\t\t\t\t<a href=\"https://blog.jquery.com/2010/10/16/jquery-143-released/\">jQuery 1.4.3 Release Notes</a>.\n\t\t\t"
},
{
"slug": "1.4.4",
"name": "Version 1.4.4",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery. <a href=\"https://blog.jquery.com/2010/11/11/jquery-1-4-4-release-notes/\">jQuery 1.4.4 Release Notes</a>."
},
{
"slug": "1.5",
"name": "Version 1.5",
"desc": "\n <p>All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery.</p>\n <p>jQuery 1.5 also includes a large rewrite of the Ajax module, which has a number of extensibility improvements. You can find out more about those improvements in the <a href=\"https://api.jquery.com/extending-ajax/\">Extending Ajax</a> documentation.</p>\n <p>Additionally jQuery 1.5 includes a new Deferred callback management system you can learn more about in in the <a href=\"https://api.jquery.com/category/deferred-object/\">Deferred Object</a> documentation.</p>\n "
},
{
"slug": "1.5.1",
"name": "Version 1.5.1",
"desc": "Aspects of the API that were changed in the corresponding version of jQuery. API changes in jQuery 1.5.1 dealt primarily with jQuery.ajax settings and jQuery.support properties."
},
{
"slug": "1.6",
"name": "Version 1.6",
"desc": "All the aspects of the API that were added, or had a new signature added, in the corresponding version of jQuery."
},
{
"slug": "1.7",
"name": "Version 1.7",
"desc": "\n <p>Aspects of the API that were changed in the corresponding version of jQuery. API changes in jQuery 1.7.0 dealt primarily with the new\n\t\t\t\tEvent APIs: <code>.on()</code> and <code>.off()</code>\n\t\t\t\tBetter Support for HTML5 in IE6/7/8\n\t\t\t\t<code>jQuery.Callbacks()</code>\n\t\t\t\tToggling Animations Work Intuitively\n\t\t\t\t</p>\n <p>For more information, see the Release Notes/Changelog at <a href=\"https://blog.jquery.com/2011/11/03/jquery-1-7-released/\">https://blog.jquery.com/2011/11/03/jquery-1-7-released/</a></p>\n <hr/>\n "
},
{
"slug": "1.8",
"name": "Version 1.8",
"desc": "\n <p>Aspects of the API that were changed in the corresponding version of jQuery. API changes in jQuery 1.8.0 dealt primarily with animations and the removal of some methods such as <code>deferred.isResolved()</code>, <code>deferred.isRejected()</code>, <code>$.curCSS()</code>, <code>$.attrFn()</code>, and <code>$(element).closest(Array)</code> returning Array.\n </p>\n <p>For more information, see the Release Notes/Changelog at <a href=\"https://blog.jquery.com/2012/08/09/jquery-1-8-released/\">https://blog.jquery.com/2012/08/09/jquery-1-8-released/</a></p>\n <hr/>\n "
},
{
"slug": "1.9",
"name": "Version 1.9",
"desc": "\n <p>Aspects of the API that were changed in the corresponding version of jQuery. Changes in jQuery 1.9 dealt primarily with removal or modification of several APIs that behaved inconsistently or inefficiently in the past. A <a href=\"https://github.com/jquery/jquery-migrate\">jQuery Migrate Plugin</a> was offered to help developers with a transitional upgrade path.\n </p>\n <p>For more information, see the <a href=\"https://jquery.com/upgrade-guide/1.9/\">jQuery Core 1.9 Upgrade guide</a> and the <a href=\"https://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/\">Release Notes/Changelog</a></p>\n <hr/>\n "
},
{
"slug": "1.12-2.2",
"name": "Version 1.12 & 2.2",
"desc": "\n <p>Aspects of the API that were changed in the corresponding versions of jQuery. Changes in jQuery 1.12 and 2.2 includes performance improvements of the selector engine, manipulation of class names for SVG elements, support for the Symbol type and iterators added in ES2015, and a new hook has been added for filtering HTML. A <a href=\"https://github.com/jquery/jquery-migrate\">jQuery Migrate Plugin</a> was offered to help developers with a transitional upgrade path.\n </p>\n <p>For more information, see the <a href=\"https://blog.jquery.com/2016/01/08/jquery-2-2-and-1-12-released/\">Release Notes/Changelog</a></p>\n <hr/>\n "
},
{
"slug": "3.0",
"name": "Version 3.0",
"desc": "\n <p>Aspects of the API that were changed in the corresponding version of jQuery. Changes in jQuery 3.0 dealt primarily with deferreds, data, show/hide and removal of some deprecated APIs. A <a href=\"https://github.com/jquery/jquery-migrate\">jQuery Migrate Plugin</a> was offered to help developers with a transitional upgrade path.\n </p>\n <p>For more information, see the <a href=\"https://jquery.com/upgrade-guide/3.0/\">jQuery Core 3.0 Upgrade guide</a> and the <a href=\"https://blog.jquery.com/2016/06/09/jquery-3-0-final-released/\">Release Notes/Changelog</a></p>\n <hr/>\n "
},
{
"slug": "3.1",
"name": "Version 3.1",
"desc": "\n <p><a href=\"/jQuery.readyException\">jQuery.readyException</a> was added.</p>\n <hr/>\n "
},
{
"slug": "all",
"name": "All"
}
]
}
];
let jqueryData = [{
"title": ".add()",
"type": "method",
"name": "add",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "selector",
"type": "Selector",
"desc": "A string representing a selector expression to find additional elements to add to the set of matched elements."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "elements",
"type": "Element",
"desc": "One or more elements to add to the set of matched elements."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "html",
"type": "htmlString",
"desc": "An HTML fragment to add to the set of matched elements."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "selection",
"type": "jQuery",
"desc": "An existing jQuery object to add to the set of matched elements."
}],
"added": "1.3.2"
},
{
"arguments": [{
"name": "selector",
"type": "Selector",
"desc": "A string representing a selector expression to find additional elements to add to the set of matched elements."
},
{
"name": "context",
"type": "Element",
"desc": "The point in the document at which the selector should begin matching; similar to the context argument of the <code>$(selector, context)</code> method."
}
],
"added": "1.4"
}
],
"desc": "Create a new jQuery object with elements added to the set of matched elements.",
"longdesc": "<p>Given a jQuery object that represents a set of DOM elements, the <code>.add()</code> method constructs a new jQuery object from the union of those elements and the ones passed into the method. The argument to <code>.add()</code> can be pretty much anything that <code>$()</code> accepts, including a jQuery selector expression, references to DOM elements, or an HTML snippet.</p>\n <p>Do not assume that this method appends the elements to the existing collection in the order they are passed to the <code>.add()</code> method. When all elements are members of the same document, the resulting collection from <code>.add()</code> will be sorted in document order; that is, in order of each element's appearance in the document. If the collection consists of elements from different documents or ones not in any document, the sort order is undefined. To create a jQuery object with elements in a well-defined order and without sorting overhead, use the <code>$(array_of_DOM_elements)</code> signature.</p>\n <p>The updated set of elements can be used in a following (chained) method, or assigned to a variable for later use. For example:</p>\n <pre><code>\n$( \"p\" ).add( \"div\" ).addClass( \"widget\" );\nvar pdiv = $( \"p\" ).add( \"div\" );\n </code></pre>\n <p>The following will <em>not</em> save the added elements, because the <code>.add()</code> method creates a new set and leaves the original set in pdiv unchanged:</p>\n <pre><code>\nvar pdiv = $( \"p\" );\npdiv.add( \"div\" ); // WRONG, pdiv will not change\n </code></pre>\n <p>Consider a page with a simple list and a paragraph following it:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li&gt;list item 1&lt;/li&gt;\n &lt;li&gt;list item 2&lt;/li&gt;\n &lt;li&gt;list item 3&lt;/li&gt;\n&lt;/ul&gt;\n&lt;p&gt;a paragraph&lt;/p&gt;\n </code></pre>\n <p>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 <code>.add()</code> method's argument:</p>\n <pre><code>\n$( \"li\" ).add( \"p\" ).css( \"background-color\", \"red\" );\n </code></pre>\n <p>Or:</p>\n <pre><code>\n$( \"li\" ).add( document.getElementsByTagName( \"p\" )[ 0 ] )\n .css( \"background-color\", \"red\" );\n </code></pre>\n <p>The result of this call is a red background behind all four elements.\nUsing an HTML snippet as the <code>.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 <pre><code>\n$( \"li\" ).add( \"&lt;p id='new'&gt;new paragraph&lt;/p&gt;\" )\n .css( \"background-color\", \"red\" );\n </code></pre>\n <p>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 <p>As of jQuery 1.4 the results from .add() will always be returned in document order (rather than a simple concatenation).</p>\n <p><strong>Note:</strong> To reverse the <code>.add()</code> you can use <a href=\"/not/\"><code>.not( elements | selector )</code></a> to remove elements from the jQuery results, or <a href=\"/end/\"><code>.end()</code></a> to return to the selection before you added.</p>",
"examples": [{
"desc": "Finds all divs and makes a border. Then adds all paragraphs to the jQuery object to set their backgrounds yellow.",
"code": "$( \"div\" ).css( \"border\", \"2px solid red\" )\n .add( \"p\" )\n .css( \"background\", \"yellow\" );",
"html": "<div></div>\n<div></div>\n<div></div>\n<div></div>\n<div></div>\n<div></div>\n\n<p>Added this... (notice no border)</p>",
"css": "div {\n width: 60px;\n height: 60px;\n margin: 10px;\n float: left;\n }\n p {\n clear: left;\n font-weight: bold;\n font-size: 16px;\n color: blue;\n margin: 0 10px;\n padding: 2px;\n }"
},
{
"desc": "Adds more elements, matched by the given expression, to the set of matched elements.",
"code": "$( \"p\" ).add( \"span\" ).css( \"background\", \"yellow\" );",
"html": "<p>Hello</p>\n<span>Hello Again</span>",
"css": ""
},
{
"desc": "Adds more elements, created on the fly, to the set of matched elements.",
"code": "$( \"p\" ).clone().add( \"<span>Again</span>\" ).appendTo( document.body );",
"html": "<p>Hello</p>",
"css": ""
},
{
"desc": "Adds one or more Elements to the set of matched elements.",
"code": "$( \"p\" ).add( document.getElementById( \"a\" ) ).css( \"background\", \"yellow\" );",
"html": "<p>Hello</p>\n<span id=\"a\">Hello Again</span>",
"css": ""
},
{
"desc": "Demonstrates how to add (or push) elements to an existing collection",
"code": "var collection = $( \"p\" );\n// Capture the new collection\ncollection = collection.add( document.getElementById( \"a\" ) );\ncollection.css( \"background\", \"yellow\" );",
"html": "<p>Hello</p>\n<span id=\"a\">Hello Again</span>",
"css": ""
}
],
"categories": [
"traversing/miscellaneous-traversal",
"version/1.0",
"version/1.4"
]
},
{
"title": ".addBack()",
"type": "method",
"name": "addBack",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "selector",
"type": "Selector",
"optional": "true",
"desc": "A string containing a selector expression to match the current set of elements against."
}],
"added": "1.8"
}],
"desc": "Add the previous set of elements on the stack to the current set, optionally filtered by a selector.",
"longdesc": "<p>As described in the discussion for <code><a href=\"/end/\">.end()</a></code>, 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, <code>.addBack()</code> can help.</p>\n <p>Consider a page with a simple list on it:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li&gt;list item 1&lt;/li&gt;\n &lt;li&gt;list item 2&lt;/li&gt;\n &lt;li class=\"third-item\"&gt;list item 3&lt;/li&gt;\n &lt;li&gt;list item 4&lt;/li&gt;\n &lt;li&gt;list item 5&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>The result of the following code is a red background behind items 3, 4 and 5:</p>\n <pre><code>\n$( \"li.third-item\" ).nextAll().addBack()\n .css( \"background-color\", \"red\" );\n </code></pre>\n <p>First, the initial selector locates item 3, initializing the stack with the set containing just this item. The call to <code>.nextAll()</code> then pushes the set of items 4 and 5 onto the stack. Finally, the <code>.addBack()</code> invocation merges these two sets together, creating a jQuery object that points to all three items in document order: <code>{[&lt;li.third-item&gt;,&lt;li&gt;,&lt;li&gt; ]}</code>.</p>",
"examples": [{
"desc": "The <code>.addBack()</code> method causes the previous set of DOM elements in the traversal stack to be added to the current set. In the first example, the top stack contains the set resulting from <code>.find(\"p\")</code>. In the second example, <code>.addBack()</code> adds the previous set of elements on the stack — in this case <code>$(\"div.after-addback\")</code> — to the current set, selecting both the div and its enclosed paragraphs.",
"code": "$( \"div.left, div.right\" ).find( \"div, div > p\" ).addClass( \"border\" );\n\n// First Example\n$( \"div.before-addback\" ).find( \"p\" ).addClass( \"background\" );\n\n// Second Example\n$( \"div.after-addback\" ).find( \"p\" ).addBack().addClass( \"background\" );",
"html": "<div class=\"left\">\n <p><strong>Before <code>addBack()</code></strong></p>\n <div class=\"before-addback\">\n <p>First Paragraph</p>\n <p>Second Paragraph</p>\n </div>\n</div>\n<div class=\"right\">\n <p><strong>After <code>addBack()</code></strong></p>\n <div class=\"after-addback\">\n <p>First Paragraph</p>\n <p>Second Paragraph</p>\n </div>\n</div>",
"css": "p, div {\n margin: 5px;\n padding: 5px;\n }\n .border {\n border: 2px solid red;\n }\n .background {\n background: yellow;\n }\n .left, .right {\n width: 45%;\n float: left;\n }\n .right {\n margin-left: 3%;\n }"
}],
"categories": [
"traversing/miscellaneous-traversal",
"version/1.8"
]
},
{
"title": ".addClass()",
"type": "method",
"name": "addClass",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "className",
"type": "String",
"desc": "One or more space-separated classes to be added to the class attribute of each matched element."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "A function returning one or more space-separated class names to be added to the existing class name(s). Receives the index position of the element in the set and the existing class name(s) as arguments. Within the function, <code>this</code> refers to the current element in the set.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "currentClassName",
"type": "String"
}
]
}],
"added": "1.4"
}
],
"desc": "Adds the specified class(es) to each element in the set of matched elements.",
"longdesc": "<p>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 <p>Before jQuery version 1.12/2.2, the <code>.addClass()</code> method manipulated the <code>className</code> <em>property</em> of the selected elements, not the <code>class</code> <em>attribute</em>. Once the property was changed, it was the browser that updated the attribute accordingly. An implication of this behavior was that this method only worked for documents with HTML DOM semantics (e.g., not pure XML documents).</p>\n <p>As of jQuery 1.12/2.2, this behavior is changed to improve the support for XML documents, including SVG. Starting from this version, the <code>class</code> <em>attribute</em> is used instead. So, <code>.addClass()</code> can be used on XML or SVG documents.</p>\n <p>More than one class may be added at a time, separated by a space, to the set of matched elements, like so:</p>\n <pre><code>\n$( \"p\" ).addClass( \"myClass yourClass\" );\n </code></pre>\n <p>This method is often used with <code>.removeClass()</code> to switch elements' classes from one to another, like so:</p>\n <pre><code>\n$( \"p\" ).removeClass( \"myClass noClass\" ).addClass( \"yourClass\" );\n </code></pre>\n <p>Here, the <code>myClass</code> and <code>noClass</code> classes are removed from all paragraphs, while <code>yourClass</code> is added.</p>\n <p>As of jQuery 1.4, the <code>.addClass()</code> method's argument can receive a function.</p>\n <pre><code>\n$( \"ul li\" ).addClass(function( index ) {\n return \"item-\" + index;\n});\n </code></pre>\n <p>Given an unordered list with two <code>&lt;li&gt;</code> elements, this example adds the class \"item-0\" to the first <code>&lt;li&gt;</code> and \"item-1\" to the second.</p>",
"examples": [{
"desc": "Add the class \"selected\" to the matched elements.",
"code": "$( \"p\" ).last().addClass( \"selected\" );",
"html": "<p>Hello</p>\n<p>and</p>\n<p>Goodbye</p>",
"css": "p {\n margin: 8px;\n font-size: 16px;\n }\n .selected {\n color: blue;\n }\n .highlight {\n background: yellow;\n }"
},
{
"desc": "Add the classes \"selected\" and \"highlight\" to the matched elements.",
"code": "$( \"p\" ).last().addClass( \"selected highlight\" );",
"html": "<p>Hello</p>\n<p>and</p>\n<p>Goodbye</p>",
"css": "p {\n margin: 8px;\n font-size: 16px;\n }\n .selected {\n color: red;\n }\n .highlight {\n background: yellow;\n }"
},
{
"desc": "Pass in a function to <code>.addClass()</code> to add the \"green\" class to a div that already has a \"red\" class.",
"code": "$( \"div\" ).addClass(function( index, currentClass ) {\n var addedClass;\n\n if ( currentClass === \"red\" ) {\n addedClass = \"green\";\n $( \"p\" ).text( \"There is one green div\" );\n }\n\n return addedClass;\n});",
"html": "<div>This div should be white</div>\n <div class=\"red\">This div will be green because it now has the \"green\" and \"red\" classes.\n It would be red if the addClass function failed.</div>\n <div>This div should be white</div>\n <p>There are zero green divs</p>",
"css": "div {\n background: white;\n }\n .red {\n background: red;\n }\n .red.green {\n background: green;\n }"
}
],
"categories": [
"attributes",
"manipulation/class-attribute",
"css",
"version/1.0",
"version/1.4"
]
},
{
"title": ".after()",
"type": "method",
"name": "after",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "content",
"type": [
"htmlString",
"Element",
"Text",
"Array",
"jQuery"
],
"desc": "HTML string, DOM element, text node, array of elements and text nodes, or jQuery object to insert after each element in the set of matched elements."
},
{
"name": "content",
"optional": "true",
"type": [
"htmlString",
"Element",
"Text",
"Array",
"jQuery"
],
"desc": "One or more additional DOM elements, text nodes, arrays of elements and text nodes, HTML strings, or jQuery objects to insert after each element in the set of matched elements."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert after each element in the set of matched elements. Receives the index position of the element in the set as an argument. Within the function, <code>this</code> refers to the current element in the set.",
"arguments": [{
"name": "index",
"type": "Integer"
}]
}],
"added": "1.4"
},
{
"arguments": [{
"name": "function-html",
"type": "Function",
"desc": "A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert after each element in the set of matched elements. Receives the index position of the element in the set and the old HTML value of the element as arguments. Within the function, <code>this</code> refers to the current element in the set.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "html",
"type": "String"
}
]
}],
"added": "1.10"
}
],
"desc": "Insert content, specified by the parameter, after each element in the set of matched elements.",
"longdesc": "<p>The <code>.after()</code> and <code><a href=\"/insertAfter/\">.insertAfter()</a></code> methods perform the same task. The major difference is in the syntax—specifically, in the placement of the content and target. With <code>.after()</code>, the content to be inserted comes from the method's argument: <code>$(target).after(contentToBeInserted)</code>. With <code>.insertAfter()</code>, on the other hand, the content precedes the method and is inserted after the target, which in turn is passed as the <code>.insertAfter()</code> method's argument: <code>$(contentToBeInserted).insertAfter(target)</code>.</p>\n <p>Using the following HTML:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;h2&gt;Greetings&lt;/h2&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>Content can be created and then inserted after several elements at once:</p>\n <pre><code>\n$( \".inner\" ).after( \"&lt;p&gt;Test&lt;/p&gt;\" );\n </code></pre>\n <p>Each inner <code>&lt;div&gt;</code> element gets this new content:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;h2&gt;Greetings&lt;/h2&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;p&gt;Test&lt;/p&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n &lt;p&gt;Test&lt;/p&gt;\n&lt;/div&gt;</code></pre>\n <p>An element in the DOM can also be selected and inserted after another element:</p>\n <pre><code>\n$( \".container\" ).after( $( \"h2\" ) );\n </code></pre>\n <p>If an element selected this way is inserted into a single location elsewhere in the DOM, it will be moved rather than cloned:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n&lt;h2&gt;Greetings&lt;/h2&gt;\n </code></pre>\n <p><strong>Important</strong>: If there is more than one target element, however, cloned copies of the inserted element will be created for each target except for the last one.</p>\n <h4 id=\"passing-a-function\">Passing a Function</h4>\n <p>As of jQuery 1.4, <code>.after()</code> supports passing a function that returns the elements to insert.</p>\n <pre><code>\n$( \"p\" ).after(function() {\n return \"&lt;div&gt;\" + this.className + \"&lt;/div&gt;\";\n});\n </code></pre>\n <p>This example inserts a <code>&lt;div&gt;</code> after each paragraph, with each new <code>&lt;div&gt;</code> containing the class name(s) of its preceding paragraph.</p>\n <h4 id=\"additional-arguments\">Additional Arguments</h4>\n <p>Similar to other content-adding methods such as <code><a href=\"/prepend/\">.prepend()</a></code> and <code><a href=\"/before/\">.before()</a></code>, <code>.after()</code> also supports passing in multiple arguments as input. Supported input includes DOM elements, jQuery objects, HTML strings, and arrays of DOM elements.</p>\n <p>For example, the following will insert two new <code>&lt;div&gt;</code>s and an existing <code>&lt;div&gt;</code> after the first paragraph:</p>\n <pre><code>\nvar $newdiv1 = $( \"&lt;div id='object1'&gt;&lt;/div&gt;\" ),\n newdiv2 = document.createElement( \"div\" ),\n existingdiv1 = document.getElementById( \"foo\" );\n\n$( \"p\" ).first().after( $newdiv1, [ newdiv2, existingdiv1 ] );\n </code></pre>\n <p>Since <code>.after()</code> can accept any number of additional arguments, the same result can be achieved by passing in the three <code>&lt;div&gt;</code>s as three separate arguments, like so: <code>$( \"p\" ).first().after( $newdiv1, newdiv2, existingdiv1 )</code>. The type and number of arguments will largely depend on the elements that are collected in the code.</p>",
"note": [{
"type": "additional",
"text": "Prior to jQuery 1.9, <code>.after()</code> would attempt to add or change nodes in the current jQuery set if the first node in the set was not connected to a document, and in those cases return a new jQuery set rather than the original set. The method might or might not have returned a new result depending on the number or connectedness of its arguments! As of jQuery 1.9, <code>.after()</code>, <code>.before()</code>, and <code>.replaceWith()</code> always return the original unmodified set. Attempting to use these methods on a node without a parent has no effect—that is, neither the set nor the nodes it contains are changed."
},
{
"type": "additional",
"text": "By design, any jQuery constructor or method that accepts an HTML string — <a href=\"/jQuery/\">jQuery()</a>, <a href=\"/append/\">.append()</a>, <a href=\"/after/\">.after()</a>, etc. — can potentially execute code. This can occur by injection of script tags or use of HTML attributes that execute code (for example, <code>&lt;img onload=\"\"&gt;</code>). Do not use these methods to insert strings obtained from untrusted sources such as URL query parameters, cookies, or form inputs. Doing so can introduce cross-site-scripting (XSS) vulnerabilities. Remove or escape any user input before adding content to the document."
}
],
"examples": [{
"desc": "Inserts some HTML after all paragraphs.",
"code": "$( \"p\" ).after( \"<b>Hello</b>\" );",
"html": "<p>I would like to say: </p>",
"css": "p {\n background: yellow;\n }"
},
{
"desc": "Inserts a DOM element after all paragraphs.",
"code": "$( \"p\" ).after( document.createTextNode( \"Hello\" ) );",
"html": "<p>I would like to say: </p>",
"css": "p {\n background: yellow;\n }"
},
{
"desc": "Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.",
"code": "$( \"p\" ).after( $( \"b\" ) );",
"html": "<b>Hello</b>\n<p>I would like to say: </p>",
"css": "p {\n background: yellow;\n }"
}
],
"categories": [
"manipulation/dom-insertion-outside",
"version/1.0",
"version/1.4"
]
},
{
"title": ".ajaxComplete()",
"type": "method",
"name": "ajaxComplete",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "The function to be invoked.",
"arguments": [{
"name": "event",
"type": "Event"
},
{
"name": "jqXHR",
"type": "jqXHR"
},
{
"name": "ajaxOptions",
"type": "PlainObject"
}
]
}],
"added": "1.0"
}],
"desc": "Register a handler to be called when Ajax requests complete. This is an <a href=\"/Ajax_Events/\">AjaxEvent</a>.",
"longdesc": "<p>Whenever an Ajax request completes, jQuery triggers the <code>ajaxComplete</code> event. Any and all handlers that have been registered with the <code>.ajaxComplete()</code> method are executed at this time.</p>\n <p>To observe this method in action, set up a basic Ajax load request:</p>\n <pre><code>\n&lt;div class=\"trigger\"&gt;Trigger&lt;/div&gt;\n&lt;div class=\"result\"&gt;&lt;/div&gt;\n&lt;div class=\"log\"&gt;&lt;/div&gt;\n </code></pre>\n <p>Attach the event handler to the document:</p>\n <pre><code>\n$( document ).ajaxComplete(function() {\n $( \".log\" ).text( \"Triggered ajaxComplete handler.\" );\n});\n </code></pre>\n <p>Now, make an Ajax request using any jQuery method:</p>\n <pre><code>\n$( \".trigger\" ).click(function() {\n $( \".result\" ).load( \"ajax/test.html\" );\n});\n </code></pre>\n <p>When the user clicks the element with class <code>trigger</code> and the Ajax request completes, the log message is displayed.</p>\n <p>All <code>ajaxComplete</code> handlers are invoked, regardless of what Ajax request was completed. If you must differentiate between the requests, use the parameters passed to the handler. Each time an <code>ajaxComplete</code> handler is executed, it is passed the event object, the <code>XMLHttpRequest</code> object, and the settings object that was used in the creation of the request. For example, you can restrict the callback to only handling events dealing with a particular URL:</p>\n <pre><code>\n$( document ).ajaxComplete(function( event, xhr, settings ) {\n if ( settings.url === \"ajax/test.html\" ) {\n $( \".log\" ).text( \"Triggered ajaxComplete handler. The result is \" +\n xhr.responseText );\n }\n});\n </code></pre>\n <p><strong>Note:</strong> You can get the returned Ajax contents by looking at <code>xhr.responseText</code>.</p>",
"note": [{
"type": "additional",
"text": "As of jQuery 1.9, all the handlers for the <a href=\"/category/ajax/global-ajax-event-handlers/\">jQuery global Ajax events</a>, including those added with the <code>.ajaxComplete()</code> method, <em>must</em> be attached to <code>document</code>."
},
{
"type": "additional",
"text": "If <code><a href=\"/jQuery.Ajax/\">$.ajax()</a></code> or <code><a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a></code> is called with the <code>global</code> option set to <code>false</code>, the <code>.ajaxComplete()</code> method will not fire."
}
],
"examples": [{
"desc": "Show a message when an Ajax request completes.",
"code": "$( document ).ajaxComplete(function( event, request, settings ) {\n $( \"#msg\" ).append( \"<li>Request Complete.</li>\" );\n});",
"html": "",
"css": ""
}],
"categories": [
"ajax/global-ajax-event-handlers",
"version/1.0"
]
},
{
"title": ".ajaxError()",
"type": "method",
"name": "ajaxError",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "The function to be invoked.",
"arguments": [{
"name": "event",
"type": "Event"
},
{
"name": "jqXHR",
"type": "jqXHR"
},
{
"name": "ajaxSettings",
"type": "PlainObject"
},
{
"name": "thrownError",
"type": "String"
}
]
}],
"added": "1.0"
}],
"desc": "Register a handler to be called when Ajax requests complete with an error. This is an <a href=\"/Ajax_Events/\">Ajax Event</a>.",
"longdesc": "<p>Whenever an Ajax request completes with an error, jQuery triggers the <code>ajaxError</code> event. Any and all handlers that have been registered with the <code>.ajaxError()</code> method are executed at this time. <strong>Note:</strong> <em>This handler is not called for cross-domain script and cross-domain JSONP requests.</em></p>\n <p>To observe this method in action, set up a basic Ajax load request.</p>\n <pre><code>\n&lt;button class=\"trigger\"&gt;Trigger&lt;/button&gt;\n&lt;div class=\"result\"&gt;&lt;/div&gt;\n&lt;div class=\"log\"&gt;&lt;/div&gt;\n </code></pre>\n <p>Attach the event handler to the document:</p>\n <pre><code>\n$( document ).ajaxError(function() {\n $( \".log\" ).text( \"Triggered ajaxError handler.\" );\n});\n </code></pre>\n <p>Now, make an Ajax request using any jQuery method:</p>\n <pre><code>\n$( \"button.trigger\" ).on( \"click\", function() {\n $( \"div.result\" ).load( \"ajax/missing.html\" );\n});\n </code></pre>\n <p>When the user clicks the button and the Ajax request fails, because the requested file is missing, the log message is displayed.</p>\n <p>All <code>ajaxError</code> handlers are invoked, regardless of what Ajax request was completed. To differentiate between the requests, use the parameters passed to the handler. Each time an <code>ajaxError</code> handler is executed, it is passed the event object, the <code>jqXHR</code> object (prior to jQuery 1.5, the <code><abbr title=\"XMLHttpRequest\">XHR</abbr></code> object), and the settings object that was used in the creation of the request. When an HTTP error occurs, the fourth argument (<code>thrownError</code>) receives the textual portion of the HTTP status, such as \"Not Found\" or \"Internal Server Error.\" For example, to restrict the error callback to only handling events dealing with a particular URL:</p>\n <pre><code>\n$( document ).ajaxError(function( event, jqxhr, settings, thrownError ) {\n if ( settings.url == \"ajax/missing.html\" ) {\n $( \"div.log\" ).text( \"Triggered ajaxError handler.\" );\n }\n});</code></pre>",
"note": [{
"type": "additional",
"text": "As of jQuery 1.9, all the handlers for the <a href=\"/category/ajax/global-ajax-event-handlers/\">jQuery global Ajax events</a>, including those added with the <code>.ajaxError()</code> method, <em>must</em> be attached to <code>document</code>."
},
{
"type": "additional",
"text": "If <code><a href=\"/jQuery.Ajax/\">$.ajax()</a></code> or <code><a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a></code> is called with the <code>global</code> option set to <code>false</code>, the <code>.ajaxError()</code> method will not fire."
}
],
"examples": [{
"desc": "Show a message when an Ajax request fails.",
"code": "$( document ).ajaxError(function( event, request, settings ) {\n $( \"#msg\" ).append( \"<li>Error requesting page \" + settings.url + \"</li>\" );\n});",
"html": "",
"css": ""
}],
"categories": [
"ajax/global-ajax-event-handlers",
"version/1.0"
]
},
{
"title": ".ajaxSend()",
"type": "method",
"name": "ajaxSend",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "The function to be invoked.",
"arguments": [{
"name": "event",
"type": "Event"
},
{
"name": "jqXHR",
"type": "jqXHR"
},
{
"name": "ajaxOptions",
"type": "PlainObject"
}
]
}],
"added": "1.0"
}],
"desc": "Attach a function to be executed before an Ajax request is sent. This is an <a href=\"/Ajax_Events/\">Ajax Event</a>.",
"longdesc": "<p>Whenever an Ajax request is about to be sent, jQuery triggers the <code>ajaxSend</code> event. Any and all handlers that have been registered with the <code>.ajaxSend()</code> method are executed at this time.</p>\n <p>To observe this method in action, set up a basic Ajax load request:</p>\n <pre><code>\n&lt;div class=\"trigger\"&gt;Trigger&lt;/div&gt;\n&lt;div class=\"result\"&gt;&lt;/div&gt;\n&lt;div class=\"log\"&gt;&lt;/div&gt;\n </code></pre>\n <p>Attach the event handler to the document:</p>\n <pre><code>\n$( document ).ajaxSend(function() {\n $( \".log\" ).text( \"Triggered ajaxSend handler.\" );\n});\n </code></pre>\n <p>Now, make an Ajax request using any jQuery method:</p>\n <pre><code>\n$( \".trigger\" ).click(function() {\n $( \".result\" ).load( \"ajax/test.html\" );\n});\n </code></pre>\n <p>When the user clicks the element with class <code>trigger</code> and the Ajax request is about to begin, the log message is displayed.</p>\n <p>All <code>ajaxSend</code> handlers are invoked, regardless of what Ajax request is to be sent. If you must differentiate between the requests, use the parameters passed to the handler. Each time an <code>ajaxSend</code> handler is executed, it is passed the event object, the <code>jqXHR</code> object (in version 1.4, <code>XMLHttpRequest</code>object), and the <a href=\"/jQuery.ajax/\">settings object</a> that was used in the creation of the Ajax request. For example, you can restrict the callback to only handling events dealing with a particular URL:</p>\n <pre><code>\n$( document ).ajaxSend(function( event, jqxhr, settings ) {\n if ( settings.url == \"ajax/test.html\" ) {\n $( \".log\" ).text( \"Triggered ajaxSend handler.\" );\n }\n});\n </code></pre>",
"note": [{
"type": "additional",
"text": "As of jQuery 1.9, all the handlers for the <a href=\"/category/ajax/global-ajax-event-handlers/\">jQuery global Ajax events</a>, including those added with the <code>.ajaxSend()</code> method, <em>must</em> be attached to <code>document</code>."
},
{
"type": "additional",
"text": "If <code><a href=\"/jQuery.Ajax/\">$.ajax()</a></code> or <code><a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a></code> is called with the <code>global</code> option set to <code>false</code>, the <code>.ajaxSend()</code> method will not fire."
}
],
"examples": [{
"desc": "Show a message before an Ajax request is sent.",
"code": "$( document ).ajaxSend(function( event, request, settings ) {\n $( \"#msg\" ).append( \"<li>Starting request at \" + settings.url + \"</li>\" );\n});",
"html": "",
"css": ""
}],
"categories": [
"ajax/global-ajax-event-handlers",
"version/1.0"
]
},
{
"title": ".ajaxStart()",
"type": "method",
"name": "ajaxStart",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "The function to be invoked."
}],
"added": "1.0"
}],
"desc": "Register a handler to be called when the first Ajax request begins. This is an <a href=\"/Ajax_Events/\">Ajax Event</a>.",
"longdesc": "<p>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 <code>ajaxStart</code> event. Any and all handlers that have been registered with the <code>.ajaxStart()</code> method are executed at this time.</p>\n <p>To observe this method in action, set up a basic Ajax load request:</p>\n <pre><code>\n&lt;div class=\"trigger\"&gt;Trigger&lt;/div&gt;\n&lt;div class=\"result\"&gt;&lt;/div&gt;\n&lt;div class=\"log\"&gt;&lt;/div&gt;\n </code></pre>\n <p>Attach the event handler to any element:</p>\n <pre><code>\n$( document ).ajaxStart(function() {\n $( \".log\" ).text( \"Triggered ajaxStart handler.\" );\n});\n </code></pre>\n <p>Now, make an Ajax request using any jQuery method:</p>\n <pre><code>\n$( \".trigger\" ).click(function() {\n $( \".result\" ).load( \"ajax/test.html\" );\n});\n </code></pre>\n <p>When the user clicks the element with class <code>trigger</code> and the Ajax request is sent, the log message is displayed.</p>",
"note": [{
"type": "additional",
"text": "As of jQuery 1.9, all the handlers for the <a href=\"/category/ajax/global-ajax-event-handlers/\">jQuery global Ajax events</a>, including those added with the <code>.ajaxStart()</code> method, <em>must</em> be attached to <code>document</code>."
},
{
"type": "additional",
"text": "If <code><a href=\"/jQuery.Ajax/\">$.ajax()</a></code> or <code><a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a></code> is called with the <code>global</code> option set to <code>false</code>, the <code>.ajaxStart()</code> method will not fire."
}
],
"examples": [{
"desc": "Show a loading message whenever an Ajax request starts (and none is already active).",
"code": "$( document ).ajaxStart(function() {\n $( \"#loading\" ).show();\n});",
"html": "",
"css": ""
}],
"categories": [
"ajax/global-ajax-event-handlers",
"version/1.0"
]
},
{
"title": ".ajaxStop()",
"type": "method",
"name": "ajaxStop",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "The function to be invoked."
}],
"added": "1.0"
}],
"desc": "Register a handler to be called when all Ajax requests have completed. This is an <a href=\"/Ajax_Events/\">Ajax Event</a>.",
"longdesc": "<p>Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the <code>ajaxStop</code> event. Any and all handlers that have been registered with the <code>.ajaxStop()</code> method are executed at this time. The <code>ajaxStop</code> event is also triggered if the last outstanding Ajax request is cancelled by returning false within the <code>beforeSend</code> callback function. </p>\n <p>To observe this method in action, set up a basic Ajax load request:</p>\n <pre><code>\n&lt;div class=\"trigger\"&gt;Trigger&lt;/div&gt;\n&lt;div class=\"result\"&gt;&lt;/div&gt;\n&lt;div class=\"log\"&gt;&lt;/div&gt;\n </code></pre>\n <p>Attach the event handler to the document:</p>\n <pre><code>\n$( document ).ajaxStop(function() {\n $( \".log\" ).text( \"Triggered ajaxStop handler.\" );\n});\n </code></pre>\n <p>Now, make an Ajax request using any jQuery method:</p>\n <pre><code>\n$( \".trigger\" ).click(function() {\n $( \".result\" ).load( \"ajax/test.html\" );\n});\n </code></pre>\n <p>When the user clicks the element with class <code>trigger</code> and the Ajax request completes, the log message is displayed.</p>",
"note": [{
"type": "additional",
"text": "As of jQuery 1.9, all the handlers for the <a href=\"/category/ajax/global-ajax-event-handlers/\">jQuery global Ajax events</a>, including those added with the <code>.ajaxStop()</code> method, <em>must</em> be attached to <code>document</code>."
},
{
"type": "additional",
"text": "If <code><a href=\"/jQuery.Ajax/\">$.ajax()</a></code> or <code><a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a></code> is called with the <code>global</code> option set to <code>false</code>, the <code>.ajaxStop()</code> method will not fire."
}
],
"examples": [{
"desc": "Hide a loading message after all the Ajax requests have stopped.",
"code": "$( document ).ajaxStop(function() {\n $( \"#loading\" ).hide();\n});",
"html": "",
"css": ""
}],
"categories": [
"ajax/global-ajax-event-handlers",
"version/1.0"
]
},
{
"title": ".ajaxSuccess()",
"type": "method",
"name": "ajaxSuccess",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "The function to be invoked.",
"arguments": [{
"name": "event",
"type": "Event"
},
{
"name": "jqXHR",
"type": "jqXHR"
},
{
"name": "ajaxOptions",
"type": "PlainObject"
},
{
"name": "data",
"type": "PlainObject"
}
]
}],
"added": "1.0"
}],
"desc": "Attach a function to be executed whenever an Ajax request completes successfully. This is an <a href=\"/Ajax_Events/\">Ajax Event</a>.",
"longdesc": "<p>Whenever an Ajax request completes successfully, jQuery triggers the <code>ajaxSuccess</code> event. Any and all handlers that have been registered with the <code>.ajaxSuccess()</code> method are executed at this time.</p>\n <p>To observe this method in action, set up a basic Ajax load request:</p>\n <pre><code>\n&lt;div class=\"trigger\"&gt;Trigger&lt;/div&gt;\n&lt;div class=\"result\"&gt;&lt;/div&gt;\n&lt;div class=\"log\"&gt;&lt;/div&gt;\n </code></pre>\n <p>Attach the event handler to any element:</p>\n <pre><code>\n$(document).ajaxSuccess(function() {\n $( \".log\" ).text( \"Triggered ajaxSuccess handler.\" );\n});\n </code></pre>\n <p>Now, make an Ajax request using any jQuery method:</p>\n <pre><code>\n$( \".trigger\" ).on( \"click\", function() {\n $( \".result\" ).load( \"ajax/test.html\" );\n});\n </code></pre>\n <p>When the user clicks the element with class <code>trigger</code> and the Ajax request completes successfully, the log message is displayed.</p>\n <p>All <code>ajaxSuccess</code> handlers are invoked, regardless of what Ajax request was completed. If you must differentiate between the requests, you can use the parameters passed to the handler. Each time an <code>ajaxSuccess</code> handler is executed, it is passed the event object, the <code>XMLHttpRequest</code> object, and the settings object that was used in the creation of the request. For example, you can restrict the callback to only handling events dealing with a particular URL:</p>\n <pre><code>\n$( document ).ajaxSuccess(function( event, xhr, settings ) {\n if ( settings.url == \"ajax/test.html\" ) {\n $( \".log\" ).text( \"Triggered ajaxSuccess handler. The Ajax response was: \" +\n xhr.responseText );\n }\n});\n </code></pre>\n <p><strong>Note:</strong> You can get the returned Ajax contents by looking at <code>xhr.responseXML</code> or <code>xhr.responseText</code> for xml and html respectively.</p>",
"note": [{
"type": "additional",
"text": "As of jQuery 1.9, all the handlers for the <a href=\"/category/ajax/global-ajax-event-handlers/\">jQuery global Ajax events</a>, including those added with the <code>.ajaxSuccess()</code> method, <em>must</em> be attached to <code>document</code>."
},
{
"type": "additional",
"text": "If <code><a href=\"/jQuery.Ajax/\">$.ajax()</a></code> or <code><a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a></code> is called with the <code>global</code> option set to <code>false</code>, the <code>.ajaxSuccess()</code> method will not fire."
}
],
"examples": [{
"desc": "Show a message when an Ajax request completes successfully.",
"code": "$( document ).ajaxSuccess(function( event, request, settings ) {\n $( \"#msg\" ).append( \"<li>Successful Request!</li>\" );\n});",
"html": "",
"css": ""
}],
"categories": [
"ajax/global-ajax-event-handlers",
"version/1.0"
]
},
{
"title": "All Selector (\"*\")",
"type": "selector",
"name": "all",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Selects all elements.",
"longdesc": "<p>Caution: The all, or universal, selector is extremely slow, except when used by itself.</p>",
"examples": [{
"desc": "Find every element (including head, body, etc) in the document. Note that if your browser has an extension/add-on enabled that inserts a <code>&lt;script&gt;</code> or <code>&lt;link&gt;</code> element into the DOM, that element will be counted as well.",
"code": "var elementCount = $( \"*\" ).css( \"border\", \"3px solid red\" ).length;\n$( \"body\" ).prepend( \"<h3>\" + elementCount + \" elements found</h3>\" );",
"html": "<div>DIV</div>\n<span>SPAN</span>\n<p>P <button>Button</button></p>",
"css": "h3 {\n margin: 0;\n }\n div, span, p {\n width: 80px;\n height: 40px;\n float: left;\n padding: 10px;\n margin: 10px;\n background-color: #EEEEEE;\n }"
},
{
"desc": "Find all elements within document.body so elements like head, script, etc. are excluded.",
"code": "var elementCount = $( \"#test\" ).find( \"*\" ).css( \"border\", \"3px solid red\" ).length;\n$( \"body\" ).prepend( \"<h3>\" + elementCount + \" elements found</h3>\" );",
"html": "<div id=\"test\">\n <div>DIV</div>\n <span>SPAN</span>\n <p>P <button>Button</button></p>\n</div>",
"css": "h3 {\n margin: 0;\n }\n div, span, p {\n width: 80px;\n height: 40px;\n float: left;\n padding: 10px;\n margin: 10px;\n background-color: #EEEEEE;\n }\n #test {\n width: auto;\n height: auto;\n background-color: transparent;\n }"
}
],
"categories": [
"selectors/basic-css-selectors",
"version/1.0"
]
},
{
"title": ".andSelf()",
"type": "method",
"name": "andSelf",
"return": "jQuery",
"deprecated": "1.8",
"removed": "3.0",
"signatures": [{
"arguments": [],
"added": "1.2"
}],
"desc": "Add the previous set of elements on the stack to the current set.",
"longdesc": "<div class=\"warning\">\n <p>Note: This API has been removed in jQuery 3.0; use <a href=\"/addBack/\"><code>.addBack()</code></a> instead, which should work identically.</p>\n </div>",
"examples": [],
"categories": [
"traversing/miscellaneous-traversal",
"version/1.2",
"deprecated/deprecated-1.8",
"removed"
]
},
{
"title": ".animate()",
"type": "method",
"name": "animate",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "properties",
"type": "PlainObject",
"desc": "An object of CSS properties and values that the animation will move toward."
},
{
"name": "duration",
"default": "400",
"optional": "true",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run."
},
{
"name": "easing",
"type": "String",
"default": "swing",
"optional": "true",
"desc": "A string indicating which easing function to use for the transition."
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete, called once per matched element."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "properties",
"type": "PlainObject",
"desc": "An object of CSS properties and values that the animation will move toward."
},
{
"name": "options",
"type": "PlainObject",
"desc": "A map of additional options to pass to the method.",
"properties": [{
"name": "duration",
"default": "400",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run.",
"arguments": []
},
{
"name": "easing",
"type": "String",
"default": "swing",
"desc": "A string indicating which easing function to use for the transition.",
"arguments": []
},
{
"name": "queue",
"default": "true",
"type": [
"Boolean",
"String"
],
"desc": "A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. <strong>As of jQuery 1.7</strong>, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call <code>.dequeue(\"queuename\")</code> to start it.",
"arguments": []
},
{
"name": "specialEasing",
"type": "PlainObject",
"added": "1.4",
"desc": "An object containing one or more of the CSS properties defined by the properties argument and their corresponding easing functions.",
"arguments": []
},
{
"name": "step",
"type": "Function",
"desc": "A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.",
"arguments": [{
"name": "now",
"type": "Number",
"desc": "The numeric value of the property being animated at each step"
},
{
"name": "tween",
"type": "Tween",
"desc": "An object of properties related to the animation and the element being animated. For information about the tween object and its properties, see <a href=\"/jQuery.Tween/\">jQuery.Tween</a>"
}
]
},
{
"name": "progress",
"type": "Function",
"added": "1.8",
"desc": "A function to be called after each step of the animation, only once per animated element regardless of the number of animated properties.",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "progress",
"type": "Number",
"desc": "A number from 0 to 1 indicating the progress of the animation"
},
{
"name": "remainingMs",
"type": "Number",
"desc": "A number indicating the remaining number of milliseconds until the scheduled end of the animation"
}
]
},
{
"name": "complete",
"type": "Function",
"desc": "A function that is called once the animation on an element is complete.",
"arguments": []
},
{
"name": "start",
"type": "Function",
"added": "1.8",
"desc": "A function to call when the animation on an element begins.",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
}]
},
{
"name": "done",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element completes (its Promise object is resolved).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
},
{
"name": "fail",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element fails to complete (its Promise object is rejected).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
},
{
"name": "always",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element completes or stops without completing (its Promise object is either resolved or rejected).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
}
]
}
],
"added": "1.0"
}
],
"desc": "Perform a custom animation of a set of CSS properties.",
"longdesc": "<p>The <code>.animate()</code> method allows us to create animation effects on any numeric CSS property. The only required parameter is a plain object of CSS properties. This object is similar to the one that can be sent to the <code>.css()</code> method, except that the range of properties is more restrictive.</p>\n <h4 id=\"animation-properties\">Animation Properties and Values</h4>\n <p>All animated properties should be animated to a <em>single numeric value</em>, except as noted below; most properties that are non-numeric cannot be animated using basic jQuery functionality (For example, <code>width</code>, <code>height</code>, or <code>left</code> can be animated but <code>background-color</code> cannot be, unless the <a href=\"https://github.com/jquery/jquery-color\">jQuery.Color</a> plugin is used). Property values are treated as a number of pixels unless otherwise specified. The units <code>em</code> and <code>%</code> can be specified where applicable.</p>\n <p>In addition to style properties, some non-style properties such as <code>scrollTop</code> and <code>scrollLeft</code>, as well as custom properties, can be animated.</p>\n <p>Shorthand CSS properties (e.g. font, background, border) are not fully supported. For example, if you want to animate the rendered border width, at least a border style and border width other than \"auto\" must be set in advance. Or, if you want to animate font size, you would use <code>fontSize</code> or the CSS equivalent <code>'font-size'</code> rather than simply <code>'font'</code>. </p>\n <p>In addition to numeric values, each property can take the strings <code>'show'</code>, <code>'hide'</code>, and <code>'toggle'</code>. These shortcuts allow for custom hiding and showing animations that take into account the display type of the element. In order to use jQuery's built-in toggle state tracking, the <code>'toggle'</code> keyword must be consistently given as the value of the property being animated.</p>\n <p>Animated properties can also be relative. If a value is supplied with a leading <code>+=</code> or <code>-=</code> sequence of characters, then the target value is computed by adding or subtracting the given number from the current value of the property.</p>\n <div class=\"warning\">\n <p><strong>Note:</strong> Unlike shorthand animation methods such as <code>.slideDown()</code> and <code>.fadeIn()</code>, the <code>.animate()</code> method does <em>not</em> make hidden elements visible as part of the effect. For example, given <code>$( \"someElement\" ).hide().animate({height: \"20px\"}, 500)</code>, the animation will run, but <em>the element will remain hidden</em>.</p>\n </div>\n <h4 id=\"duration\">Duration</h4>\n <p>Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The default duration is <code>400</code> milliseconds. The strings <code>'fast'</code> and <code>'slow'</code> can be supplied to indicate durations of <code>200</code> and <code>600</code> milliseconds, respectively.</p>\n <h4 id=\"callbacks\">Callback Functions</h4>\n <p>If supplied, the <code>start</code>, <code>step</code>, <code>progress</code>, <code>complete</code>, <code>done</code>, <code>fail</code>, and <code>always</code> callbacks are called on a <em>per-element</em> basis; <code>this</code> is set to the DOM element being animated. If no elements are in the set, no callbacks are called. If multiple elements are animated, the callback is executed once per matched element, not once for the animation as a whole. Use the <code>.promise()</code> method to obtain a promise to which you can attach callbacks that fire once for an animated set of any size, including zero elements.</p>\n <h4 id=\"basic-usage\">Basic Usage</h4>\n <p>To animate any element, such as a simple image:</p>\n <pre><code>\n&lt;div id=\"clickme\"&gt;\n Click here\n&lt;/div&gt;\n&lt;img id=\"book\" src=\"book.png\" alt=\"\" width=\"100\" height=\"123\"\n style=\"position: relative; left: 10px;\"&gt;\n </code></pre>\n <p>To animate the opacity, left offset, and height of the image simultaneously:</p>\n <pre><code>\n$( \"#clickme\" ).click(function() {\n $( \"#book\" ).animate({\n opacity: 0.25,\n left: \"+=50\",\n height: \"toggle\"\n }, 5000, function() {\n // Animation complete.\n });\n});\n </code></pre>\n <p class=\"image\">\n <figure>\n <img src=\"/resources/animate-1.jpg\" alt=\"\"/>\n <figcaption>Figure 1 - Illustration of the specified animation effect</figcaption>\n </figure>\n </p>\n <p>Note that the target value of the <code>height</code> property is <code>'toggle'</code>. Since the image was visible before, the animation shrinks the height to 0 to hide it. A second click then reverses this transition:\n </p>\n <p class=\"image\">\n <figure>\n <img src=\"/resources/animate-2.jpg\" alt=\"\"/>\n <figcaption>Figure 2 - Illustration of the specified animation effect</figcaption>\n </figure>\n </p>\n <p>The <code>opacity</code> of the image is already at its target value, so this property is not animated by the second click. Since the target value for <code>left</code> is a relative value, the image moves even farther to the right during this second animation.</p>\n <p>Directional properties (<code>top</code>, <code>right</code>, <code>bottom</code>, <code>left</code>) have no discernible effect on elements if their <code>position</code> style property is <code>static</code>, which it is by default.</p>\n <div class=\"warning\">\n <p><strong>Note: </strong>The <a href=\"https://jqueryui.com/\">jQuery UI</a> project extends the <code>.animate()</code> method by allowing some non-numeric styles such as colors to be animated. The project also includes mechanisms for specifying animations through CSS classes rather than individual attributes.</p>\n </div>\n <div class=\"warning\">\n <p><strong>Note:</strong> if attempting to animate an element with a height or width of 0px, where contents of the element are visible due to overflow, jQuery may clip this overflow during animation. By fixing the dimensions of the original element being hidden however, it is possible to ensure that the animation runs smoothly. A <a href=\"https://www.google.com/search?q=clearfix\">clearfix</a> can be used to automatically fix the dimensions of your main element without the need to set this manually.</p>\n </div>\n <h4 id=\"step\">Step Function</h4>\n <p>The second version of <code>.animate()</code> provides a <code>step</code> option — a callback function that is fired at each step of the animation. This function is useful for enabling custom animation types or altering the animation as it is occurring. It accepts two arguments (<code>now</code> and <code>fx</code>), and <code>this</code> is set to the DOM element being animated.</p>\n <ul>\n <li><code>now</code>: the numeric value of the property being animated at each step</li>\n <li><code>fx</code>: a reference to the <code>jQuery.fx</code> prototype object, which contains a number of properties such as <code>elem</code> for the animated element, <code>start</code> and <code>end</code> for the first and last value of the animated property, respectively, and <code>prop</code> for the property being animated.</li>\n </ul>\n <p>Note that the <code>step</code> function is called for each animated property on each animated element. For example, given two list items, the <code>step</code> function fires four times at each step of the animation: </p>\n <pre><code>\n$( \"li\" ).animate({\n opacity: .5,\n height: \"50%\"\n}, {\n step: function( now, fx ) {\n var data = fx.elem.id + \" \" + fx.prop + \": \" + now;\n $( \"body\" ).append( \"&lt;div&gt;\" + data + \"&lt;/div&gt;\" );\n }\n});\n </code></pre>\n <h4 id=\"easing\">Easing</h4>\n <p>The remaining parameter of <code>.animate()</code> is a string naming an easing function to use. An easing function specifies the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called <code>swing</code>, and one that progresses at a constant pace, called <code>linear</code>. More easing functions are available with the use of plug-ins, most notably the <a href=\"https://jqueryui.com/\">jQuery UI suite</a>.</p>\n <h4 id=\"per-property-easing\">Per-property Easing</h4>\n <p>As of jQuery version 1.4, you can set per-property easing functions within a single <code>.animate()</code> call. In the first version of <code>.animate()</code>, each property can take an array as its value: The first member of the array is the CSS property and the second member is an easing function. If a per-property easing function is not defined for a particular property, it uses the value of the <code>.animate()</code> method's optional easing argument. If the easing argument is not defined, the default <code>swing</code> function is used.</p>\n <p>For example, to simultaneously animate the width and height with the <code>swing</code> easing function and the opacity with the <code>linear</code> easing function:</p>\n <pre><code>\n$( \"#clickme\" ).click(function() {\n $( \"#book\" ).animate({\n width: [ \"toggle\", \"swing\" ],\n height: [ \"toggle\", \"swing\" ],\n opacity: \"toggle\"\n }, 5000, \"linear\", function() {\n $( this ).after( \"&lt;div&gt;Animation complete.&lt;/div&gt;\" );\n });\n});\n </code></pre>\n <p>In the second version of <code>.animate()</code>, the options object can include the <code>specialEasing</code> property, which is itself an object of CSS properties and their corresponding easing functions. For example, to simultaneously animate the width using the <code>linear</code> easing function and the height using the <code>easeOutBounce</code> easing function:</p>\n <pre><code>\n$( \"#clickme\" ).click(function() {\n $( \"#book\" ).animate({\n width: \"toggle\",\n height: \"toggle\"\n }, {\n duration: 5000,\n specialEasing: {\n width: \"linear\",\n height: \"easeOutBounce\"\n },\n complete: function() {\n $( this ).after( \"&lt;div&gt;Animation complete.&lt;/div&gt;\" );\n }\n });\n});\n </code></pre>\n <p>As previously noted, a plugin is required for the <code>easeOutBounce</code> function.</p>",
"note": [{
"type": "additional",
"text": "All jQuery effects, including <code>.animate()</code>, can be turned off globally by setting <code>jQuery.fx.off = true</code>, which effectively sets the duration to 0. For more information, see <a href=\"/jquery.fx.off/\">jQuery.fx.off</a>."
}],
"examples": [{
"desc": "Click the button to animate the div with a number of different properties.",
"code": "// Using multiple unit types within one animation.\n\n$( \"#go\" ).click(function() {\n $( \"#block\" ).animate({\n width: \"70%\",\n opacity: 0.4,\n marginLeft: \"0.6in\",\n fontSize: \"3em\",\n borderWidth: \"10px\"\n }, 1500 );\n});",
"html": "<button id=\"go\">&raquo; Run</button>\n<div id=\"block\">Hello!</div>",
"css": "div {\n background-color: #bca;\n width: 100px;\n border: 1px solid green;\n }"
},
{
"desc": "Animates a div's left property with a relative value. Click several times on the buttons to see the relative animations queued up.",
"code": "$( \"#right\" ).click(function() {\n $( \".block\" ).animate({ \"left\": \"+=50px\" }, \"slow\" );\n});\n\n$( \"#left\" ).click(function(){\n $( \".block\" ).animate({ \"left\": \"-=50px\" }, \"slow\" );\n});",
"html": "<button id=\"left\">&laquo;</button>\n<button id=\"right\">&raquo;</button>\n<div class=\"block\"></div>",
"css": "div {\n position: absolute;\n background-color: #abc;\n left: 50px;\n width: 90px;\n height: 90px;\n margin: 5px;\n }"
},
{
"desc": "The first button shows how an unqueued animation works. It expands the div out to 90% width <strong>while</strong> the font-size is increasing. Once the font-size change is complete, the border animation will begin.\n\nThe second button starts a traditional chained animation, where each animation will start once the previous animation on the element has completed.",
"code": "$( \"#go1\" ).click(function() {\n $( \"#block1\" )\n .animate({\n width: \"90%\"\n }, {\n queue: false,\n duration: 3000\n })\n .animate({ fontSize: \"24px\" }, 1500 )\n .animate({ borderRightWidth: \"15px\" }, 1500 );\n});\n\n$( \"#go2\" ).click(function() {\n $( \"#block2\" )\n .animate({ width: \"90%\" }, 1000 )\n .animate({ fontSize: \"24px\" }, 1000 )\n .animate({ borderLeftWidth: \"15px\" }, 1000 );\n});\n\n$( \"#go3\" ).click(function() {\n $( \"#go1\" ).add( \"#go2\" ).click();\n});\n\n$( \"#go4\" ).click(function() {\n $( \"div\" ).css({\n width: \"\",\n fontSize: \"\",\n borderWidth: \"\"\n });\n});",
"html": "<button id=\"go1\">&raquo; Animate Block1</button>\n<button id=\"go2\">&raquo; Animate Block2</button>\n<button id=\"go3\">&raquo; Animate Both</button>\n<button id=\"go4\">&raquo; Reset</button>\n<div id=\"block1\">Block1</div>\n<div id=\"block2\">Block2</div>",
"css": "div {\n background-color: #bca;\n width: 200px;\n height: 1.1em;\n text-align: center;\n border: 2px solid green;\n margin: 3px;\n font-size: 14px;\n }\n button {\n font-size: 14px;\n }"
},
{
"desc": "Animates the first div's left property and synchronizes the remaining divs, using the step function to set their left properties at each stage of the animation.",
"code": "$( \"#go\" ).click(function() {\n $( \".block\" ).first().animate({\n left: 100\n }, {\n duration: 1000,\n step: function( now, fx ){\n $( \".block\" ).slice( 1 ).css( \"left\", now );\n }\n });\n});",
"html": "<p><button id=\"go\">Run »</button></p>\n<div class=\"block\"></div>\n<div class=\"block\"></div>\n<div class=\"block\"></div>\n<div class=\"block\"></div>\n<div class=\"block\"></div>\n<div class=\"block\"></div>",
"css": "div {\n position: relative;\n background-color: #abc;\n width: 40px;\n height: 40px;\n float: left;\n margin: 5px;\n }"
},
{
"desc": "Animate all paragraphs to toggle both height and opacity, completing the animation within 600 milliseconds.",
"code": "$( \"p\" ).animate({\n height: \"toggle\",\n opacity: \"toggle\"\n}, \"slow\" );",
"html": "",
"css": ""
},
{
"desc": "Animate all paragraphs to a left style of 50 and opacity of 1 (opaque, visible), completing the animation within 500 milliseconds.",
"code": "$( \"p\" ).animate({\n left: 50,\n opacity: 1\n}, 500 );",
"html": "",
"css": ""
},
{
"desc": "Animate the left and opacity style properties of all paragraphs; run the animation <em>outside</em> the queue, so that it will automatically start without waiting for its turn.",
"code": "$( \"p\" ).animate({\n left: \"50px\",\n opacity: 1\n}, {\n duration: 500,\n queue: false\n});",
"html": "",
"css": ""
},
{
"desc": "An example of using an 'easing' function to provide a different style of animation. This will only work if you have a plugin that provides this easing function. Note, this code will do nothing unless the paragraph element is hidden.",
"code": "$( \"p\" ).animate({\n opacity: \"show\"\n}, \"slow\", \"easein\" );",
"html": "",
"css": ""
},
{
"desc": "Animates all paragraphs to toggle both height and opacity, completing the animation within 600 milliseconds.",
"code": "$( \"p\" ).animate({\n height: \"toggle\",\n opacity: \"toggle\"\n}, {\n duration: \"slow\"\n});",
"html": "",
"css": ""
},
{
"desc": "Use an easing function to provide a different style of animation. This will only work if you have a plugin that provides this easing function.",
"code": "$( \"p\" ).animate({\n opacity: \"show\"\n}, {\n duration: \"slow\",\n easing: \"easein\"\n});",
"html": "",
"css": ""
},
{
"desc": "Animate all paragraphs and execute a callback function when the animation is complete. The first argument is an object of CSS properties, the second specifies that the animation should take 1000 milliseconds to complete, the third states the easing type, and the fourth argument is an anonymous callback function.",
"code": "$( \"p\" ).animate({\n height: 200,\n width: 400,\n opacity: 0.5\n}, 1000, \"linear\", function() {\n alert( \"all done\" );\n});",
"html": "",
"css": ""
}
],
"categories": [
"effects/custom-effects",
"version/1.0"
]
},
{
"title": ":animated Selector",
"type": "selector",
"name": "animated",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.2"
}],
"desc": "Select all elements that are in the progress of an animation at the time the selector is run.",
"longdesc": "<p><strong>Note:</strong> If you use a custom jQuery build <em>without the effects module</em>, the <code>:animated</code> selector will throw an error. </p>",
"note": [{
"type": "additional",
"text": "Because <code>:animated</code> is a jQuery extension and not part of the CSS specification, queries using <code>:animated</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>undefined</code> instead."
}],
"examples": [{
"desc": "Change the color of any div that is animated.",
"code": "$( \"#run\" ).click(function() {\n $( \"div:animated\" ).toggleClass( \"colored\" );\n});\n\nfunction animateIt() {\n $( \"#mover\" ).slideToggle( \"slow\", animateIt );\n}\n\nanimateIt();",
"html": "<button id=\"run\">Run</button>\n\n<div></div>\n<div id=\"mover\"></div>\n<div></div>",
"css": "div {\n background: yellow;\n border: 1px solid #AAA;\n width: 80px;\n height: 80px;\n margin: 0 5px;\n float: left;\n }\n div.colored {\n background: green;\n }"
}],
"categories": [
"selectors/basic-filter-selectors",
"selectors/jquery-selector-extensions",
"version/1.2"
]
},
{
"title": ".append()",
"type": "method",
"name": "append",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "content",
"type": [
"htmlString",
"Element",
"Text",
"Array",
"jQuery"
],
"desc": "DOM element, text node, array of elements and text nodes, HTML string, or jQuery object to insert at the end of each element in the set of matched elements."
},
{
"name": "content",
"optional": "true",
"type": [
"htmlString",
"Element",
"Text",
"Array",
"jQuery"
],
"desc": "One or more additional DOM elements, text nodes, arrays of elements and text nodes, HTML strings, or jQuery objects to insert at the end of each element in the set of matched elements."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert at the end of each element in the set of matched elements. Receives the index position of the element in the set and the old HTML value of the element as arguments. Within the function, <code>this</code> refers to the current element in the set.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "html",
"type": "String"
}
]
}],
"added": "1.4"
}
],
"desc": "Insert content, specified by the parameter, to the end of each element in the set of matched elements.",
"longdesc": "<p>The <code>.append()</code> method inserts the specified content as the last child of each element in the jQuery collection (To insert it as the <em>first</em> child, use <a href=\"/prepend/\"><code>.prepend()</code></a>).</p>\n <p>The <code>.append()</code> and <code><a href=\"/appendTo/\">.appendTo()</a></code> methods perform the same task. The major difference is in the syntax-specifically, in the placement of the content and target. With <code>.append()</code>, the selector expression preceding the method is the container into which the content is inserted. With <code>.appendTo()</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 into the target container.</p>\n <p>Consider the following HTML:</p>\n <pre><code>\n&lt;h2&gt;Greetings&lt;/h2&gt;\n&lt;div class=\"container\"&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>You can create content and insert it into several elements at once:</p>\n <pre><code>\n$( \".inner\" ).append( \"&lt;p&gt;Test&lt;/p&gt;\" );\n </code></pre>\n <p>Each inner <code>&lt;div&gt;</code> element gets this new content:</p>\n <pre><code>\n&lt;h2&gt;Greetings&lt;/h2&gt;\n&lt;div class=\"container\"&gt;\n &lt;div class=\"inner\"&gt;\n Hello\n &lt;p&gt;Test&lt;/p&gt;\n &lt;/div&gt;\n &lt;div class=\"inner\"&gt;\n Goodbye\n &lt;p&gt;Test&lt;/p&gt;\n &lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>You can also select an element on the page and insert it into another:</p>\n <pre><code>\n$( \".container\" ).append( $( \"h2\" ) );\n </code></pre>\n <p>If an element selected this way is inserted into a single location elsewhere in the DOM, it will be moved into the target (not cloned):</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n &lt;h2&gt;Greetings&lt;/h2&gt;\n&lt;/div&gt;\n </code></pre>\n <p><strong>Important</strong>: If there is more than one target element, however, cloned copies of the inserted element will be created for each target except for the last one.</p>\n <h4 id=\"additional-arguments\">Additional Arguments</h4>\n <p>Similar to other content-adding methods such as <code><a href=\"/prepend/\">.prepend()</a></code> and <code><a href=\"/before/\">.before()</a></code>, <code>.append()</code> also supports passing in multiple arguments as input. Supported input includes DOM elements, jQuery objects, HTML strings, and arrays of DOM elements.</p>\n <p>For example, the following will insert two new <code>&lt;div&gt;</code>s and an existing <code>&lt;div&gt;</code> as the last three child nodes of the body:</p>\n <pre><code>\nvar $newdiv1 = $( \"&lt;div id='object1'&gt;&lt;/div&gt;\" ),\n newdiv2 = document.createElement( \"div\" ),\n existingdiv1 = document.getElementById( \"foo\" );\n\n$( \"body\" ).append( $newdiv1, [ newdiv2, existingdiv1 ] );\n </code></pre>\n <p>Since <code>.append()</code> can accept any number of additional arguments, the same result can be achieved by passing in the three <code>&lt;div&gt;</code>s as three separate arguments, like so: <code>$('body').append( $newdiv1, newdiv2, existingdiv1 )</code>. The type and number of arguments will largely depend on how you collect the elements in your code.</p>",
"note": [{
"type": "additional",
"text": "By design, any jQuery constructor or method that accepts an HTML string — <a href=\"/jQuery/\">jQuery()</a>, <a href=\"/append/\">.append()</a>, <a href=\"/after/\">.after()</a>, etc. — can potentially execute code. This can occur by injection of script tags or use of HTML attributes that execute code (for example, <code>&lt;img onload=\"\"&gt;</code>). Do not use these methods to insert strings obtained from untrusted sources such as URL query parameters, cookies, or form inputs. Doing so can introduce cross-site-scripting (XSS) vulnerabilities. Remove or escape any user input before adding content to the document."
},
{
"type": "additional",
"text": "jQuery doesn't officially support SVG. Using jQuery methods on SVG documents, unless explicitly documented for that method, might cause unexpected behaviors. Examples of methods that support SVG as of jQuery 3.0 are <code>addClass</code> and <code>removeClass</code>."
}
],
"examples": [{
"desc": "Appends some HTML to all paragraphs.",
"code": "$( \"p\" ).append( \"<strong>Hello</strong>\" );",
"html": "<p>I would like to say: </p>",
"css": "p {\n background: yellow;\n }"
},
{
"desc": "Appends an Element to all paragraphs.",
"code": "$( \"p\" ).append( document.createTextNode( \"Hello\" ) );",
"html": "<p>I would like to say: </p>",
"css": "p {\n background: yellow;\n }"
},
{
"desc": "Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.",
"code": "$( \"p\" ).append( $( \"strong\" ) );",
"html": "<strong>Hello world!!!</strong>\n<p>I would like to say: </p>",
"css": "p {\n background: yellow;\n }"
}
],
"categories": [
"manipulation/dom-insertion-inside",
"version/1.0",
"version/1.4"
]
},
{
"title": ".appendTo()",
"type": "method",
"name": "appendTo",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "target",
"type": [
"Selector",
"htmlString",
"Element",
"Array",
"jQuery"
],
"desc": "A selector, element, HTML string, array of elements, or jQuery object; the matched set of elements will be inserted at the end of the element(s) specified by this parameter."
}],
"added": "1.0"
}],
"desc": "Insert every element in the set of matched elements to the end of the target.",
"longdesc": "<p>\n\t\t\tThe\n\t\t\t<code>\n\t\t\t\t<a href=\"/append/\">\n\t\t\t\t\t.append()\n\t\t\t\t</a>\n\t\t\t</code>\n\t\t\tand\n\t\t\t<code>\n\t\t\t\t.appendTo()\n\t\t\t</code>\n\t\t\tmethods perform the same task. The major difference is in the syntax-specifically, in the placement of the content and target. With\n\t\t\t<code>\n\t\t\t\t.append()\n\t\t\t</code>\n\t\t\t, the selector expression preceding the method is the container into which the content is inserted. With\n\t\t\t<code>\n\t\t\t\t.appendTo()\n\t\t\t</code>\n\t\t\t, 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 into the target container.\n\t\t</p>\n\t\t<p>\n\t\t\tConsider the following HTML:\n\t\t</p>\n\t\t<pre>\n\t\t\t<code>\n\t\t\t\t&lt;h2&gt;Greetings&lt;/h2&gt;\n\t\t\t\t&lt;div class=\"container\"&gt;\n\t\t\t\t&lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n\t\t\t\t&lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n\t\t\t\t&lt;/div&gt;\n\t\t\t</code>\n\t\t</pre>\n\t\t<p>\n\t\t\tWe can create content and insert it into several elements at once:\n\t\t</p>\n\t\t<pre>\n\t\t\t<code>\n\t\t\t\t$( \"&lt;p&gt;Test&lt;/p&gt;\" ).appendTo( \".inner\" );\n\t\t\t</code>\n\t\t</pre>\n\t\t<p>\n\t\t\tEach inner\n\t\t\t<code>\n\t\t\t\t&lt;div&gt;\n\t\t\t</code>\n\t\t\telement gets this new content:\n\t\t</p>\n\t\t<pre>\n\t\t\t<code>\n\t\t\t\t&lt;h2&gt;Greetings&lt;/h2&gt;\n\t\t\t\t&lt;div class=\"container\"&gt;\n\t\t\t\t&lt;div class=\"inner\"&gt;\n\t\t\t\tHello\n\t\t\t\t&lt;p&gt;Test&lt;/p&gt;\n\t\t\t\t&lt;/div&gt;\n\t\t\t\t&lt;div class=\"inner\"&gt;\n\t\t\t\tGoodbye\n\t\t\t\t&lt;p&gt;Test&lt;/p&gt;\n\t\t\t\t&lt;/div&gt;\n\t\t\t\t&lt;/div&gt;\n\t\t\t</code>\n\t\t</pre>\n\t\t<p>\n\t\t\tWe can also select an element on the page and insert it into another:\n\t\t</p>\n\t\t<pre>\n\t\t\t<code>\n\t\t\t\t$( \"h2\" ).appendTo( $( \".container\" ) );\n\t\t\t</code>\n\t\t</pre>\n\t\t<p>\n\t\t\tIf an element selected this way is inserted into a single location elsewhere in the DOM, it will be moved into the target (not cloned) and a new set consisting of the inserted element is returned:\n\t\t</p>\n\t\t<pre>\n\t\t\t<code>\n\t\t\t\t&lt;div class=\"container\"&gt;\n\t\t\t\t&lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n\t\t\t\t&lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n\t\t\t\t&lt;h2&gt;Greetings&lt;/h2&gt;\n\t\t\t\t&lt;/div&gt;\n\t\t\t</code>\n\t\t</pre>\n\t\t<p>\n\t\t\tIf there is more than one target element, however, cloned copies of the inserted element will be created for each target except the last, and that new set (the original element plus clones) is returned.\n\t\t</p>\n\t\t<p>\n\t\t\t<strong>\n\t\t\t\tBefore jQuery 1.9,\n\t\t\t</strong>\n\t\t\tthe append-to-single-element case did not create a new set, but instead returned the original set which made it difficult to use the\n\t\t\t<code>\n\t\t\t\t.end()\n\t\t\t</code>\n\t\t\tmethod reliably when being used with an unknown number of elements.\n\t\t</p>",
"note": [{
"type": "additional",
"text": "By design, any jQuery constructor or method that accepts an HTML string — <a href=\"/jQuery/\">jQuery()</a>, <a href=\"/append/\">.append()</a>, <a href=\"/after/\">.after()</a>, etc. — can potentially execute code. This can occur by injection of script tags or use of HTML attributes that execute code (for example, <code>&lt;img onload=\"\"&gt;</code>). Do not use these methods to insert strings obtained from untrusted sources such as URL query parameters, cookies, or form inputs. Doing so can introduce cross-site-scripting (XSS) vulnerabilities. Remove or escape any user input before adding content to the document."
},
{
"type": "additional",
"text": "jQuery doesn't officially support SVG. Using jQuery methods on SVG documents, unless explicitly documented for that method, might cause unexpected behaviors. Examples of methods that support SVG as of jQuery 3.0 are <code>addClass</code> and <code>removeClass</code>."
}
],
"examples": [{
"desc": "Append all spans to the element with the ID \"foo\" (Check append() documentation for more examples)",
"code": "$( \"span\" ).appendTo( \"#foo\" );",
"html": "<span>I have nothing more to say... </span>\n\t\t\t\n\t\t\t<div id=\"foo\">FOO! </div>",
"css": "#foo {\n\t\t\tbackground: yellow;\n\t\t\t}"
}],
"categories": [
"manipulation/dom-insertion-inside",
"version/1.0"
]
},
{
"entries": [{
"title": ".attr()",
"type": "method",
"name": "attr",
"return": "String",
"signatures": [{
"arguments": [{
"name": "attributeName",
"type": "String",
"desc": "The name of the attribute to get."
}],
"added": "1.0"
}],
"desc": "Get the value of an attribute for the first element in the set of matched elements.",
"longdesc": "<p>\n\t\t\t\tThe\n\t\t\t\t<code>\n\t\t\t\t\t.attr()\n\t\t\t\t</code>\n\t\t\t\tmethod gets the attribute value for only the\n\t\t\t\t<em>\n\t\t\t\t\tfirst\n\t\t\t\t</em>\n\t\t\t\telement in the matched set. To get the value for each element individually, use a looping construct such as jQuery's\n\t\t\t\t<code>\n\t\t\t\t\t.each()\n\t\t\t\t</code>\n\t\t\t\tor\n\t\t\t\t<code>\n\t\t\t\t\t.map()\n\t\t\t\t</code>\n\t\t\t\tmethod.\n\t\t\t</p>\n\t\t\t<p>\n\t\t\t\tUsing jQuery's\n\t\t\t\t<code>\n\t\t\t\t\t.attr()\n\t\t\t\t</code>\n\t\t\t\tmethod to get the value of an element's attribute has two main benefits:\n\t\t\t</p>\n\t\t\t<ol>\n\t\t\t\t<li>\n\t\t\t\t\t<strong>\n\t\t\t\t\t\tConvenience\n\t\t\t\t\t</strong>\n\t\t\t\t\t: It can be called directly on a jQuery object and chained to other jQuery methods.\n\t\t\t\t</li>\n\t\t\t\t<li>\n\t\t\t\t\t<strong>\n\t\t\t\t\t\tCross-browser consistency\n\t\t\t\t\t</strong>\n\t\t\t\t\t: The values of some attributes are reported inconsistently across browsers, and even across versions of a single browser. The\n\t\t\t\t\t<code>\n\t\t\t\t\t\t.attr()\n\t\t\t\t\t</code>\n\t\t\t\t\tmethod reduces such inconsistencies.\n\t\t\t\t</li>\n\t\t\t</ol>\n\t\t\t<div class=\"warning\">\n\t\t\t\t<p>\n\t\t\t\t\t<strong>\n\t\t\t\t\t\tNote:\n\t\t\t\t\t</strong>\n\t\t\t\t\tAttribute values are strings with the exception of a few attributes such as value and tabindex.\n\t\t\t\t</p>\n\t\t\t</div>\n\t\t\t<p>\n\t\t\t\tAs of jQuery 1.6, the\n\t\t\t\t<code>\n\t\t\t\t\t.attr()\n\t\t\t\t</code>\n\t\t\t\tmethod returns\n\t\t\t\t<code>\n\t\t\t\t\tundefined\n\t\t\t\t</code>\n\t\t\t\tfor attributes that have not been set.\n\t\t\t\t<strong>\n\t\t\t\t\tTo retrieve and change DOM properties such as the\n\t\t\t\t\t<code>\n\t\t\t\t\t\tchecked\n\t\t\t\t\t</code>\n\t\t\t\t\t,\n\t\t\t\t\t<code>\n\t\t\t\t\t\tselected\n\t\t\t\t\t</code>\n\t\t\t\t\t, or\n\t\t\t\t\t<code>\n\t\t\t\t\t\tdisabled\n\t\t\t\t\t</code>\n\t\t\t\t\tstate of form elements, use the\n\t\t\t\t\t<a href=\"/prop/\">\n\t\t\t\t\t\t.prop()\n\t\t\t\t\t</a>\n\t\t\t\t\tmethod.\n\t\t\t\t</strong>\n\t\t\t</p>\n\t\t\t<note id=\"svg-support\" type=\"additional\"/>\n\t\t\t<h4>\n\t\t\t\tAttributes vs. Properties\n\t\t\t</h4>\n\t\t\t<p>\n\t\t\t\tThe difference between\n\t\t\t\t<em>\n\t\t\t\t\tattributes\n\t\t\t\t</em>\n\t\t\t\tand\n\t\t\t\t<em>\n\t\t\t\t\tproperties\n\t\t\t\t</em>\n\t\t\t\tcan be important in specific situations.\n\t\t\t\t<strong>\n\t\t\t\t\tBefore jQuery 1.6\n\t\t\t\t</strong>\n\t\t\t\t, the\n\t\t\t\t<code>\n\t\t\t\t\t.attr()\n\t\t\t\t</code>\n\t\t\t\tmethod sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior.\n\t\t\t\t<strong>\n\t\t\t\t\tAs of jQuery 1.6\n\t\t\t\t</strong>\n\t\t\t\t, the\n\t\t\t\t<code>\n\t\t\t\t\t.prop()\n\t\t\t\t</code>\n\t\t\t\tmethod provides a way to explicitly retrieve property values, while\n\t\t\t\t<code>\n\t\t\t\t\t.attr()\n\t\t\t\t</code>\n\t\t\t\tretrieves attributes.\n\t\t\t</p>\n\t\t\t<p>\n\t\t\t\tFor example,\n\t\t\t\t<code>\n\t\t\t\t\tselectedIndex\n\t\t\t\t</code>\n\t\t\t\t,\n\t\t\t\t<code>\n\t\t\t\t\ttagName\n\t\t\t\t</code>\n\t\t\t\t,\n\t\t\t\t<code>\n\t\t\t\t\tnodeName\n\t\t\t\t</code>\n\t\t\t\t,\n\t\t\t\t<code>\n\t\t\t\t\tnodeType\n\t\t\t\t</code>\n\t\t\t\t,\n\t\t\t\t<code>\n\t\t\t\t\townerDocument\n\t\t\t\t</code>\n\t\t\t\t,\n\t\t\t\t<code>\n\t\t\t\t\tdefaultChecked\n\t\t\t\t</code>\n\t\t\t\t, and\n\t\t\t\t<code>\n\t\t\t\t\tdefaultSelected\n\t\t\t\t</code>\n\t\t\t\tshould be retrieved and set with the\n\t\t\t\t<code>\n\t\t\t\t\t<a href=\"/prop/\">\n\t\t\t\t\t\t.prop()\n\t\t\t\t\t</a>\n\t\t\t\t</code>\n\t\t\t\tmethod. Prior to jQuery 1.6, these properties were retrievable with the\n\t\t\t\t<code>\n\t\t\t\t\t.attr()\n\t\t\t\t</code>\n\t\t\t\tmethod, but this was not within the scope of\n\t\t\t\t<code>\n\t\t\t\t\tattr\n\t\t\t\t</code>\n\t\t\t\t. These do not have corresponding attributes and are only properties.\n\t\t\t</p>\n\t\t\t<p>\n\t\t\t\tConcerning boolean attributes, consider a DOM element defined by the HTML markup\n\t\t\t\t<code>\n\t\t\t\t\t&lt;input type=\"checkbox\" checked=\"checked\" /&gt;\n\t\t\t\t</code>\n\t\t\t\t, and assume it is in a JavaScript variable named\n\t\t\t\t<code>\n\t\t\t\t\telem\n\t\t\t\t</code>\n\t\t\t\t:\n\t\t\t</p>\n\t\t\t<table>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\telem.checked\n\t\t\t\t\t\t</code>\n\t\t\t\t\t</th>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t</code>\n\t\t\t\t\t\t(Boolean) Will change with checkbox state\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\t$( elem ).prop( \"checked\" )\n\t\t\t\t\t\t</code>\n\t\t\t\t\t</th>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t</code>\n\t\t\t\t\t\t(Boolean) Will change with checkbox state\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\telem.getAttribute( \"checked\" )\n\t\t\t\t\t\t</code>\n\t\t\t\t\t</th>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\t\"checked\"\n\t\t\t\t\t\t</code>\n\t\t\t\t\t\t(String) Initial state of the checkbox; does not change\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\t$( elem ).attr( \"checked\" )\n\t\t\t\t\t\t</code>\n\t\t\t\t\t\t<em>\n\t\t\t\t\t\t\t(1.6)\n\t\t\t\t\t\t</em>\n\t\t\t\t\t</th>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\t\"checked\"\n\t\t\t\t\t\t</code>\n\t\t\t\t\t\t(String) Initial state of the checkbox; does not change\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\t$( elem ).attr( \"checked\" )\n\t\t\t\t\t\t</code>\n\t\t\t\t\t\t<em>\n\t\t\t\t\t\t\t(1.6.1+)\n\t\t\t\t\t\t</em>\n\t\t\t\t\t</th>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\t\"checked\"\n\t\t\t\t\t\t</code>\n\t\t\t\t\t\t(String) Will change with checkbox state\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\t$( elem ).attr( \"checked\" )\n\t\t\t\t\t\t</code>\n\t\t\t\t\t\t<em>\n\t\t\t\t\t\t\t(pre-1.6)\n\t\t\t\t\t\t</em>\n\t\t\t\t\t</th>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t</code>\n\t\t\t\t\t\t(Boolean) Changed with checkbox state\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<br/>\n\t\t\t<p>\n\t\t\t\tAccording to the\n\t\t\t\t<a href=\"https://www.w3.org/TR/html401/interact/forms.html#h-17.4\">\n\t\t\t\t\tW3C forms specification\n\t\t\t\t</a>\n\t\t\t\t, the\n\t\t\t\t<code>\n\t\t\t\t\tchecked\n\t\t\t\t</code>\n\t\t\t\tattribute is a\n\t\t\t\t<em>\n\t\t\t\t\t<a href=\"https://www.w3.org/TR/html4/intro/sgmltut.html#h-3.3.4.2\">\n\t\t\t\t\t\tboolean attribute\n\t\t\t\t\t</a>\n\t\t\t\t</em>\n\t\t\t\t, which means the corresponding property is\n\t\t\t\t<strong>\n\t\t\t\t\ttrue\n\t\t\t\t</strong>\n\t\t\t\tif the attribute is present at all—even if, for example, the attribute has no value or is set to empty string value or even \"false\". This is true of all boolean attributes.\n\t\t\t</p>\n\t\t\t<p>\n\t\t\t\tNevertheless, the most important concept to remember about the\n\t\t\t\t<code>\n\t\t\t\t\tchecked\n\t\t\t\t</code>\n\t\t\t\tattribute is that it does not correspond to the\n\t\t\t\t<code>\n\t\t\t\t\tchecked\n\t\t\t\t</code>\n\t\t\t\tproperty. The attribute actually corresponds to the\n\t\t\t\t<code>\n\t\t\t\t\tdefaultChecked\n\t\t\t\t</code>\n\t\t\t\tproperty and should be used only to set the\n\t\t\t\t<em>\n\t\t\t\t\tinitial\n\t\t\t\t</em>\n\t\t\t\tvalue of the checkbox. The\n\t\t\t\t<code>\n\t\t\t\t\tchecked\n\t\t\t\t</code>\n\t\t\t\tattribute value does not change with the state of the checkbox, while the\n\t\t\t\t<code>\n\t\t\t\t\tchecked\n\t\t\t\t</code>\n\t\t\t\tproperty does. Therefore, the cross-browser-compatible way to determine if a checkbox is checked is to use the property:\n\t\t\t</p>\n\t\t\t<ul>\n\t\t\t\t<li>\n\t\t\t\t\t<code>\n\t\t\t\t\t\tif ( elem.checked )\n\t\t\t\t\t</code>\n\t\t\t\t</li>\n\t\t\t\t<li>\n\t\t\t\t\t<code>\n\t\t\t\t\t\tif ( $( elem ).prop( \"checked\" ) )\n\t\t\t\t\t</code>\n\t\t\t\t</li>\n\t\t\t\t<li>\n\t\t\t\t\t<code>\n\t\t\t\t\t\tif ( $( elem ).is( \":checked\" ) )\n\t\t\t\t\t</code>\n\t\t\t\t</li>\n\t\t\t</ul>\n\t\t\t<p>\n\t\t\t\tThe same is true for other dynamic attributes, such as\n\t\t\t\t<code>\n\t\t\t\t\tselected\n\t\t\t\t</code>\n\t\t\t\tand\n\t\t\t\t<code>\n\t\t\t\t\tvalue\n\t\t\t\t</code>\n\t\t\t\t.\n\t\t\t</p>",
"note": [{
"type": "additional",
"text": "jQuery doesn't officially support SVG. Using jQuery methods on SVG documents, unless explicitly documented for that method, might cause unexpected behaviors. Examples of methods that support SVG as of jQuery 3.0 are <code>addClass</code> and <code>removeClass</code>."
},
{
"type": "additional",
"text": "In Internet Explorer prior to version 9, using <code><a href=\"/prop/\">.prop()</a></code> to set a DOM element property to anything other than a simple primitive value (number, string, or boolean) can cause memory leaks if the property is not removed (using <a href=\"/removeProp/\"><code>.removeProp()</code></a>) before the DOM element is removed from the document. To safely set values on DOM objects without memory leaks, use <a href=\"/data/\"><code>.data()</code></a>."
}
],
"examples": [{
"desc": "Display the checked attribute and property of a checkbox as it changes.",
"code": "$( \"input\" )\n\t\t\t\t.change(function() {\n\t\t\t\tvar $input = $( this );\n\t\t\t\t$( \"p\" ).html( \".attr( 'checked' ): <b>\" + $input.attr( \"checked\" ) + \"</b><br>\" +\n\t\t\t\t\".prop( 'checked' ): <b>\" + $input.prop( \"checked\" ) + \"</b><br>\" +\n\t\t\t\t\".is( ':checked' ): <b>\" + $input.is( \":checked\" ) + \"</b>\" );\n\t\t\t\t})\n\t\t\t\t.change();",
"html": "<input id=\"check1\" type=\"checkbox\" checked=\"checked\">\n\t\t\t\t<label for=\"check1\">Check me</label>\n\t\t\t\t<p></p>",
"css": "p {\n\t\t\t\tmargin: 20px 0 0;\n\t\t\t\t}\n\t\t\t\tb {\n\t\t\t\tcolor: blue;\n\t\t\t\t}"
},
{
"desc": "Find the title attribute of the first &lt;em&gt; in the page.",
"code": "var title = $( \"em\" ).attr( \"title\" );\n\t\t\t\t$( \"div\" ).text( title );",
"html": "<p>Once there was a <em title=\"huge, gigantic\">large</em> dinosaur...</p>\n\t\t\t\t\n\t\t\t\tThe title of the emphasis is:<div></div>",
"css": "em {\n\t\t\t\tcolor: blue;\n\t\t\t\tfont-weight: bold;\n\t\t\t\t}\n\t\t\t\tdiv {\n\t\t\t\tcolor: red;\n\t\t\t\t}"
}
],
"categories": [
"attributes",
"manipulation/general-attributes",
"version/1.0",
"version/1.1",
"version/1.6"
]
},
{
"title": "",
"type": "method",
"name": "attr",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "attributeName",
"type": "String",
"desc": "The name of the attribute to set."
},
{
"name": "value",
"type": [
"String",
"Number",
"Null"
],
"desc": "A value to set for the attribute. If\n\t\t\t\t\t<code>\n\t\t\t\t\t\tnull\n\t\t\t\t\t</code>\n\t\t\t\t\t, the specified attribute will be removed (as in\n\t\t\t\t\t<a href=\"/removeAttr/\">\n\t\t\t\t\t\t<code>\n\t\t\t\t\t\t\t.removeAttr()\n\t\t\t\t\t\t</code>\n\t\t\t\t\t</a>\n\t\t\t\t\t)."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "attributes",
"type": "PlainObject",
"desc": "An object of attribute-value pairs to set."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "attributeName",
"type": "String",
"desc": "The name of the attribute to set."
},
{
"name": "function",
"type": "Function",
"desc": "A function returning the value to set.\n\t\t\t\t\t<code>\n\t\t\t\t\t\tthis\n\t\t\t\t\t</code>\n\t\t\t\t\tis the current element. Receives the index position of the element in the set and the old attribute value as arguments.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "attr",
"type": "String"
}
]
}
],
"added": "1.1"
}
],
"desc": "Set one or more attributes for the set of matched elements.",
"longdesc": "<p>\n\t\t\t\tThe\n\t\t\t\t<code>\n\t\t\t\t\t.attr()\n\t\t\t\t</code>\n\t\t\t\tmethod is a convenient way to set the value of attributes—especially when setting multiple attributes or using values returned by a function. Consider the following image:\n\t\t\t</p>\n\t\t\t<pre>\n\t\t\t\t<code>\n\t\t\t\t\t&lt;img id=\"greatphoto\" src=\"brush-seller.jpg\" alt=\"brush seller\"&gt;\n\t\t\t\t</code>\n\t\t\t</pre>\n\t\t\t<h4 id=\"setting-simple-attr\">\n\t\t\t\tSetting a simple attribute\n\t\t\t</h4>\n\t\t\t<p>\n\t\t\t\tTo change the\n\t\t\t\t<code>\n\t\t\t\t\talt\n\t\t\t\t</code>\n\t\t\t\tattribute, simply pass the name of the attribute and its new value to the\n\t\t\t\t<code>\n\t\t\t\t\t.attr()\n\t\t\t\t</code>\n\t\t\t\tmethod:\n\t\t\t</p>\n\t\t\t<pre>\n\t\t\t\t<code>\n\t\t\t\t\t$( \"#greatphoto\" ).attr( \"alt\", \"Beijing Brush Seller\" );\n\t\t\t\t</code>\n\t\t\t</pre>\n\t\t\t<p>\n\t\t\t\t<em>\n\t\t\t\t\tAdd\n\t\t\t\t</em>\n\t\t\t\tan attribute the same way:\n\t\t\t</p>\n\t\t\t<pre>\n\t\t\t\t<code>\n\t\t\t\t\t$( \"#greatphoto\" ).attr( \"title\", \"Photo by Kelly Clark\" );\n\t\t\t\t</code>\n\t\t\t</pre>\n\t\t\t<h4 id=\"setting-several-attrs\">\n\t\t\t\tSetting several attributes at once\n\t\t\t</h4>\n\t\t\t<p>\n\t\t\t\tTo change the\n\t\t\t\t<code>\n\t\t\t\t\talt\n\t\t\t\t</code>\n\t\t\t\tattribute and add the\n\t\t\t\t<code>\n\t\t\t\t\ttitle\n\t\t\t\t</code>\n\t\t\t\tattribute at the same time, pass both sets of names and values into the method at once using a plain JavaScript object. Each key-value pair in the object adds or modifies an attribute:\n\t\t\t</p>\n\t\t\t<pre>\n\t\t\t\t<code>\n\t\t\t\t\t$( \"#greatphoto\" ).attr({\n\t\t\t\t\talt: \"Beijing Brush Seller\",\n\t\t\t\t\ttitle: \"photo by Kelly Clark\"\n\t\t\t\t\t});\n\t\t\t\t</code>\n\t\t\t</pre>\n\t\t\t<p>\n\t\t\t\tWhen setting multiple attributes, the quotes around attribute names are optional.\n\t\t\t</p>\n\t\t\t<p>\n\t\t\t\t<strong>\n\t\t\t\t\tWARNING\n\t\t\t\t</strong>\n\t\t\t\t: When setting the 'class' attribute, you must always use quotes!\n\t\t\t</p>\n\t\t\t<div class=\"warning\">\n\t\t\t\t<p>\n\t\t\t\t\t<strong>\n\t\t\t\t\t\tNote:\n\t\t\t\t\t</strong>\n\t\t\t\t\tAttempting to change the\n\t\t\t\t\t<code>\n\t\t\t\t\t\ttype\n\t\t\t\t\t</code>\n\t\t\t\t\tattribute on an\n\t\t\t\t\t<code>\n\t\t\t\t\t\tinput\n\t\t\t\t\t</code>\n\t\t\t\t\tor\n\t\t\t\t\t<code>\n\t\t\t\t\t\tbutton\n\t\t\t\t\t</code>\n\t\t\t\t\telement created via\n\t\t\t\t\t<code>\n\t\t\t\t\t\tdocument.createElement()\n\t\t\t\t\t</code>\n\t\t\t\t\twill throw an exception on Internet Explorer 8 or older.\n\t\t\t\t</p>\n\t\t\t</div>\n\t\t\t<h4 id=\"computed-attr-values\">\n\t\t\t\tComputed attribute values\n\t\t\t</h4>\n\t\t\t<p>\n\t\t\t\tBy using a function to set attributes, you can compute the value based on other properties of the element. For example, to concatenate a new value with an existing value:\n\t\t\t</p>\n\t\t\t<pre>\n\t\t\t\t<code>\n\t\t\t\t\t$( \"#greatphoto\" ).attr( \"title\", function( i, val ) {\n\t\t\t\t\treturn val + \" - photo by Kelly Clark\";\n\t\t\t\t\t});\n\t\t\t\t</code>\n\t\t\t</pre>\n\t\t\t<p>\n\t\t\t\tThis use of a function to compute attribute values can be particularly useful when modifying the attributes of multiple elements at once.\n\t\t\t</p>\n\t\t\t<p>\n\t\t\t\t<strong>\n\t\t\t\t\tNote:\n\t\t\t\t</strong>\n\t\t\t\tIf nothing is returned in the setter function (ie.\n\t\t\t\t<code>\n\t\t\t\t\tfunction(index, attr){}\n\t\t\t\t</code>\n\t\t\t\t), or if\n\t\t\t\t<code>\n\t\t\t\t\tundefined\n\t\t\t\t</code>\n\t\t\t\tis returned, the current value is not changed. This is useful for selectively setting values only when certain criteria are met.\n\t\t\t</p>",
"examples": [{
"desc": "Set some attributes for all &lt;img&gt;s in the page.",
"code": "$( \"img\" ).attr({\n\t\t\t\tsrc: \"/resources/hat.gif\",\n\t\t\t\ttitle: \"jQuery\",\n\t\t\t\talt: \"jQuery Logo\"\n\t\t\t\t});\n\t\t\t\t$( \"div\" ).text( $( \"img\" ).attr( \"alt\" ) );",
"html": "<img>\n\t\t\t\t<img>\n\t\t\t\t<img>\n\t\t\t\t\n\t\t\t\t<div><b>Attribute of Ajax</b></div>",
"css": "img {\n\t\t\t\tpadding: 10px;\n\t\t\t\t}\n\t\t\t\tdiv {\n\t\t\t\tcolor: red;\n\t\t\t\tfont-size: 24px;\n\t\t\t\t}"
},
{
"desc": "Set the id for divs based on the position in the page.",
"code": "$( \"div\" )\n\t\t\t\t.attr( \"id\", function( arr ) {\n\t\t\t\treturn \"div-id\" + arr;\n\t\t\t\t})\n\t\t\t\t.each(function() {\n\t\t\t\t$( \"span\", this ).html( \"(id = '<b>\" + this.id + \"</b>')\" );\n\t\t\t\t});",
"html": "<div>Zero-th <span></span></div>\n\t\t\t\t<div>First <span></span></div>\n\t\t\t\t<div>Second <span></span></div>",
"css": "div {\n\t\t\t\tcolor: blue;\n\t\t\t\t}\n\t\t\t\tspan {\n\t\t\t\tcolor: red;\n\t\t\t\t}\n\t\t\t\tb {\n\t\t\t\tfont-weight: bolder;\n\t\t\t\t}"
},
{
"desc": "Set the src attribute from title attribute on the image.",
"code": "$( \"img\" ).attr( \"src\", function() {\n\t\t\t\treturn \"/resources/\" + this.title;\n\t\t\t\t});",
"html": "<img title=\"hat.gif\">",
"css": ""
}
],
"categories": [
"attributes",
"manipulation/general-attributes",
"version/1.0",
"version/1.1",
"version/1.6"
]
}
]
},
{
"title": "Attribute Contains Prefix Selector [name|=\"value\"]",
"type": "selector",
"name": "attributeContainsPrefix",
"return": "",
"signatures": [{
"arguments": [{
"name": "attribute",
"type": "String",
"desc": "An attribute name."
},
{
"name": "value",
"type": "String",
"desc": "An attribute value. Can be either a <a href=\"https://www.w3.org/TR/css3-selectors/#attribute-selectors\">valid identifier</a> or a quoted string."
}
],
"added": "1.0"
}],
"desc": "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 (-).",
"longdesc": "<p>This selector was introduced into the CSS specification to handle language attributes.</p>",
"examples": [{
"desc": "Finds all links with an hreflang attribute that is english.",
"code": "$( \"a[hreflang|='en']\" ).css( \"border\", \"3px dotted green\" );",
"html": "<a href=\"example.html\" hreflang=\"en\">Some text</a>\n<a href=\"example.html\" hreflang=\"en-UK\">Some other text</a>\n<a href=\"example.html\" hreflang=\"english\">will not be outlined</a>",
"css": "a {\n display: inline-block;\n }"
}],
"categories": [
"selectors/attribute-selectors",
"version/1.0"
]
},
{
"title": "Attribute Contains Selector [name*=\"value\"]",
"type": "selector",
"name": "attributeContains",
"return": "",
"signatures": [{
"arguments": [{
"name": "attribute",
"type": "String",
"desc": "An attribute name."
},
{
"name": "value",
"type": "String",
"desc": "An attribute value. Can be either a <a href=\"https://www.w3.org/TR/css3-selectors/#attribute-selectors\">valid identifier</a> or a quoted string."
}
],
"added": "1.0"
}],
"desc": "Selects elements that have the specified attribute with a value containing a given substring.",
"longdesc": "<p>This is the most generous of the jQuery attribute selectors that match against a value. It will select an element if the selector's string appears anywhere within the element's attribute value. Compare this selector with the Attribute Contains Word selector (e.g. [attr~=\"word\"]), which is more appropriate in many cases.</p>",
"examples": [{
"desc": "Finds all inputs with a name attribute that contains 'man' and sets the value with some text.",
"code": "$( \"input[name*='man']\" ).val( \"has man in it!\" );",
"html": "<input name=\"man-news\">\n<input name=\"milkman\">\n<input name=\"letterman2\">\n<input name=\"newmilk\">",
"css": ""
}],
"categories": [
"selectors/attribute-selectors",
"version/1.0"
]
},
{
"title": "Attribute Contains Word Selector [name~=\"value\"]",
"type": "selector",
"name": "attributeContainsWord",
"return": "",
"signatures": [{
"arguments": [{
"name": "attribute",
"type": "String",
"desc": "An attribute name."
},
{
"name": "value",
"type": "String",
"desc": "An attribute value. Can be either a <a href=\"https://www.w3.org/TR/css3-selectors/#attribute-selectors\">valid identifier</a> or a quoted string."
}
],
"added": "1.0"
}],
"desc": "Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.",
"longdesc": "<p>This selector matches the test string against each word in the attribute value, where a \"word\" is defined as a string delimited by whitespace. The selector matches if the test string is exactly equal to any of the words.</p>",
"examples": [{
"desc": "Finds all inputs with a name attribute that contains the word 'man' and sets the value with some text.",
"code": "$( \"input[name~='man']\" ).val( \"mr. man is in it!\" );",
"html": "<input name=\"man-news\">\n<input name=\"milk man\">\n<input name=\"letterman2\">\n<input name=\"newmilk\">",
"css": ""
}],
"categories": [
"selectors/attribute-selectors",
"version/1.0"
]
},
{
"title": "Attribute Ends With Selector [name$=\"value\"]",
"type": "selector",
"name": "attributeEndsWith",
"return": "",
"signatures": [{
"arguments": [{
"name": "attribute",
"type": "String",
"desc": "An attribute name."
},
{
"name": "value",
"type": "String",
"desc": "An attribute value. Can be either a <a href=\"https://www.w3.org/TR/css3-selectors/#attribute-selectors\">valid identifier</a> or a quoted string."
}
],
"added": "1.0"
}],
"desc": "Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.",
"longdesc": "",
"examples": [{
"desc": "Finds all inputs with an attribute name that ends with 'letter' and puts text in them.",
"code": "$( \"input[name$='letter']\" ).val( \"a letter\" );",
"html": "<input name=\"newsletter\">\n<input name=\"milkman\">\n<input name=\"jobletter\">",
"css": ""
}],
"categories": [
"selectors/attribute-selectors",
"version/1.0"
]
},
{
"title": "Attribute Equals Selector [name=\"value\"]",
"type": "selector",
"name": "attributeEquals",
"return": "",
"signatures": [{
"arguments": [{
"name": "attribute",
"type": "String",
"desc": "An attribute name."
},
{
"name": "value",
"type": "String",
"desc": "An attribute value. <strong>Can be either a <a href=\"https://www.w3.org/TR/css3-selectors/#attribute-selectors\">valid identifier</a> or a quoted string.</strong>"
}
],
"added": "1.0"
}],
"desc": "Selects elements that have the specified attribute with a value exactly equal to a certain value.",
"longdesc": "",
"examples": [{
"desc": "Finds all inputs with a value of \"Hot Fuzz\" and changes the text of the next sibling span.",
"code": "$( \"input[value='Hot Fuzz']\" ).next().text( \"Hot Fuzz\" );",
"html": "<div>\n <label>\n <input type=\"radio\" name=\"newsletter\" value=\"Hot Fuzz\">\n <span>name?</span>\n </label>\n</div>\n<div>\n <label>\n <input type=\"radio\" name=\"newsletter\" value=\"Cold Fusion\">\n <span>value?</span>\n </label>\n</div>\n<div>\n <label>\n <input type=\"radio\" name=\"newsletter\" value=\"Evil Plans\">\n <span>value?</span>\n </label>\n</div>",
"css": ""
}],
"categories": [
"selectors/attribute-selectors",
"version/1.0"
]
},
{
"title": "Attribute Not Equal Selector [name!=\"value\"]",
"type": "selector",
"name": "attributeNotEqual",
"return": "",
"signatures": [{
"arguments": [{
"name": "attribute",
"type": "String",
"desc": "An attribute name."
},
{
"name": "value",
"type": "String",
"desc": "An attribute value. Can be either a <a href=\"https://www.w3.org/TR/css3-selectors/#attribute-selectors\">valid identifier</a> or a quoted string."
}
],
"added": "1.0"
}],
"desc": "Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value.",
"longdesc": "<p>This selector is equivalent to <code>:not([attr='value'])</code>.</p>",
"note": [{
"type": "additional",
"text": "Because <code>[name!=\"value\"]</code> is a jQuery extension and not part of the CSS specification, queries using <code>[name!=\"value\"]</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>$( \"your-pure-css-selector\" ).not( \"[name='value']\" )</code> instead."
}],
"examples": [{
"desc": "Finds all inputs that don't have the name 'newsletter' and appends text to the span next to it.",
"code": "$( \"input[name!='newsletter']\" ).next().append( \"<b>; not newsletter</b>\" );",
"html": "<div>\n <input type=\"radio\" name=\"newsletter\" value=\"Hot Fuzz\">\n <span>name is newsletter</span>\n</div>\n<div>\n <input type=\"radio\" value=\"Cold Fusion\">\n <span>no name</span>\n</div>\n<div>\n <input type=\"radio\" name=\"accept\" value=\"Evil Plans\">\n <span>name is accept</span>\n</div>",
"css": ""
}],
"categories": [
"selectors/attribute-selectors",
"selectors/jquery-selector-extensions",
"version/1.0"
]
},
{
"title": "Attribute Starts With Selector [name^=\"value\"]",
"type": "selector",
"name": "attributeStartsWith",
"return": "",
"signatures": [{
"arguments": [{
"name": "attribute",
"type": "String",
"desc": "An attribute name."
},
{
"name": "value",
"type": "String",
"desc": "An attribute value. Can be either a <a href=\"https://www.w3.org/TR/css3-selectors/#attribute-selectors\">valid identifier</a> or a quoted string."
}
],
"added": "1.0"
}],
"desc": "Selects elements that have the specified attribute with a value beginning exactly with a given string.",
"longdesc": "<p>This selector can be useful for identifying elements in pages produced by server-side frameworks that produce HTML with systematic element IDs. However it will be slower than using a class selector so leverage classes, if you can, to group like elements.</p>",
"examples": [{
"desc": "Finds all inputs with an attribute name that starts with 'news' and puts text in them.",
"code": "$( \"input[name^='news']\" ).val( \"news here!\" );",
"html": "<input name=\"newsletter\">\n<input name=\"milkman\">\n<input name=\"newsboy\">",
"css": ""
}],
"categories": [
"selectors/attribute-selectors",
"version/1.0"
]
},
{
"title": ".before()",
"type": "method",
"name": "before",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "content",
"type": [
"htmlString",
"Element",
"Text",
"Array",
"jQuery"
],
"desc": "HTML string, DOM element, text node, array of elements and text nodes, or jQuery object to insert before each element in the set of matched elements."
},
{
"name": "content",
"optional": "true",
"type": [
"htmlString",
"Element",
"Text",
"Array",
"jQuery"
],
"desc": "One or more additional DOM elements, text nodes, arrays of elements and text nodes, HTML strings, or jQuery objects to insert before each element in the set of matched elements."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert before each element in the set of matched elements. Receives the index position of the element in the set as an argument. Within the function, <code>this</code> refers to the current element in the set.",
"arguments": [{
"name": "index",
"type": "Integer"
}]
}],
"added": "1.4"
},
{
"arguments": [{
"name": "function-html",
"type": "Function",
"desc": "A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert before each element in the set of matched elements. Receives the index position of the element in the set and the old HTML value of the element as arguments. Within the function, <code>this</code> refers to the current element in the set.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "html",
"type": "String"
}
]
}],
"added": "1.10"
}
],
"desc": "Insert content, specified by the parameter, before each element in the set of matched elements.",
"longdesc": "<p>The <code>.before()</code> and <code><a href=\"/insertBefore/\">.insertBefore()</a></code> methods perform the same task. The major difference is in the syntax—specifically, in the placement of the content and target. With <code>.before()</code>, the content to be inserted comes from the method's argument: <code>$(target).before(contentToBeInserted)</code>. With <code>.insertBefore()</code>, on the other hand, the content precedes the method and is inserted before the target, which in turn is passed as the <code>.insertBefore()</code> method's argument: <code>$(contentToBeInserted).insertBefore(target)</code>.</p>\n <p>Consider the following HTML:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;h2&gt;Greetings&lt;/h2&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>You can create content and insert it before several elements at once:</p>\n <pre><code>\n$( \".inner\" ).before( \"&lt;p&gt;Test&lt;/p&gt;\" );\n </code></pre>\n <p>Each inner <code>&lt;div&gt;</code> element gets this new content:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;h2&gt;Greetings&lt;/h2&gt;\n &lt;p&gt;Test&lt;/p&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;p&gt;Test&lt;/p&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>You can also select an element on the page and insert it before another:</p>\n <pre><code>\n$( \".container\" ).before( $( \"h2\" ) );\n </code></pre>\n <p>If an element selected this way is inserted into a single location elsewhere in the DOM, it will be moved before the target (not cloned):</p>\n <pre><code>\n&lt;h2&gt;Greetings&lt;/h2&gt;\n&lt;div class=\"container\"&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p><strong>Important</strong>: If there is more than one target element, however, cloned copies of the inserted element will be created for each target except for the last one.</p>\n <h4 id=\"additional-arguments\">Additional Arguments</h4>\n <p>Similar to other content-adding methods such as <code><a href=\"/prepend/\">.prepend()</a></code> and <code><a href=\"/after/\">.after()</a></code>, <code>.before()</code> also supports passing in multiple arguments as input. Supported input includes DOM elements, jQuery objects, HTML strings, and arrays of DOM elements.</p>\n <p>For example, the following will insert two new <code>&lt;div&gt;</code>s and an existing <code>&lt;div&gt;</code> before the first paragraph:</p>\n <pre><code>\nvar newdiv1 = $( \"&lt;div id='object1'&gt;&lt;/div&gt;\" ),\n newdiv2 = document.createElement( \"div\" ),\n existingdiv1 = document.getElementById( \"foo\" );\n\n$( \"p\" ).first().before( newdiv1, [ newdiv2, existingdiv1 ] );\n </code></pre>\n <p>Since <code>.before()</code> can accept any number of additional arguments, the same result can be achieved by passing in the three <code>&lt;div&gt;</code>s as three separate arguments, like so: <code>$( \"p\" ).first().before( $newdiv1, newdiv2, existingdiv1 )</code>. The type and number of arguments will largely depend on how you collect the elements in your code.</p>",
"note": [{
"type": "additional",
"text": "Prior to jQuery 1.9, <code>.before()</code> would attempt to add or change nodes in the current jQuery set if the first node in the set was not connected to a document, and in those cases return a new jQuery set rather than the original set. The method might or might not have returned a new result depending on the number or connectedness of its arguments! As of jQuery 1.9, <code>.after()</code>, <code>.before()</code>, and <code>.replaceWith()</code> always return the original unmodified set. Attempting to use these methods on a node without a parent has no effect—that is, neither the set nor the nodes it contains are changed."
},
{
"type": "additional",
"text": "By design, any jQuery constructor or method that accepts an HTML string — <a href=\"/jQuery/\">jQuery()</a>, <a href=\"/append/\">.append()</a>, <a href=\"/after/\">.after()</a>, etc. — can potentially execute code. This can occur by injection of script tags or use of HTML attributes that execute code (for example, <code>&lt;img onload=\"\"&gt;</code>). Do not use these methods to insert strings obtained from untrusted sources such as URL query parameters, cookies, or form inputs. Doing so can introduce cross-site-scripting (XSS) vulnerabilities. Remove or escape any user input before adding content to the document."
}
],
"examples": [{
"desc": "Inserts some HTML before all paragraphs.",
"code": "$( \"p\" ).before( \"<b>Hello</b>\" );",
"html": "<p> is what I said...</p>",
"css": "p {\n background: yellow;\n }"
},
{
"desc": "Inserts a DOM element before all paragraphs.",
"code": "$( \"p\" ).before( document.createTextNode( \"Hello\" ) );",
"html": "<p> is what I said...</p>",
"css": "p {\n background: yellow;\n }"
},
{
"desc": "Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.",
"code": "$( \"p\" ).before( $( \"b\" ) );",
"html": "<p> is what I said...</p><b>Hello</b>",
"css": "p {\n background: yellow;\n }"
}
],
"categories": [
"manipulation/dom-insertion-outside",
"version/1.0",
"version/1.4"
]
},
{
"title": ".bind()",
"type": "method",
"name": "bind",
"return": "jQuery",
"deprecated": "3.0",
"signatures": [{
"arguments": [{
"name": "eventType",
"type": "String",
"desc": "A string containing one or more DOM event types, such as \"click\" or \"submit,\" or custom event names."
},
{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "eventType",
"type": "String",
"desc": "A string containing one or more DOM event types, such as \"click\" or \"submit,\" or custom event names."
},
{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "preventBubble",
"type": "Boolean",
"optional": "true",
"desc": "Setting the third argument to false will attach a function that prevents the default action from occurring and stops the event from bubbling. The default is true."
}
],
"added": "1.4.3"
},
{
"arguments": [{
"name": "events",
"type": "Object",
"desc": "An object containing one or more DOM event types and functions to execute for them."
}],
"added": "1.4"
}
],
"desc": "Attach a handler to an event for the elements.",
"longdesc": "<p>As of jQuery 3.0, <code>.bind()</code> has been deprecated. It was superseded by the <a href=\"/on/\"><code>.on()</code></a> method for attaching event handlers to a document since jQuery 1.7, so its use was already discouraged. For earlier versions, the <code>.bind()</code> method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements <em>must exist</em> at the point the call to <code>.bind()</code> occurs. For more flexible event binding, see the discussion of event delegation in <a href=\"/on/\"><code>.on()</code></a>.</p>\n <p>Any string is legal for <code>eventType</code>; if the string is not the name of a native DOM event, then the handler is bound to a custom event. These events are never called by the browser, but may be triggered manually from other JavaScript code using <code>.trigger()</code> or <code>.triggerHandler()</code>.</p>\n <p>If the <code>eventType</code> string contains a period (<code>.</code>) character, then the event is namespaced. The period character separates the event from its namespace. For example, in the call <code>.bind( \"click.name\", handler )</code>, the string <code>click</code> is the event type, and the string <code>name</code> is the namespace. Namespacing allows us to unbind or trigger some events of a type without affecting others. See the discussion of <code>.unbind()</code> for more information.</p>\n <p>There are shorthand methods for some standard browser events such as <a href=\"/click/\"><code>.click()</code></a> that can be used to attach or trigger event handlers. For a complete list of shorthand methods, see the <a href=\"/category/events/\">events category</a>.</p>\n <p>When an event reaches an element, all handlers bound to that event type for the element are fired. If there are multiple handlers registered, they will always execute in the order in which they were bound. After all handlers have executed, the event continues along the normal event propagation path.</p>\n <p>A basic usage of <code>.bind()</code> is:</p>\n <pre><code>\n$( \"#foo\" ).bind( \"click\", function() {\n alert( \"User clicked on 'foo.'\" );\n});\n </code></pre>\n <p>This code will cause the element with an ID of <code>foo</code> to respond to the <code>click</code> event. When a user clicks inside this element thereafter, the alert will be shown.</p>\n <h4 id=\"multiple-events\">Multiple Events</h4>\n <p>Multiple event types can be bound at once by including each one separated by a space:</p>\n <pre><code>\n$( \"#foo\" ).bind( \"mouseenter mouseleave\", function() {\n $( this ).toggleClass( \"entered\" );\n});\n </code></pre>\n <p>The effect of this on <code>&lt;div id=\"foo\"&gt;</code> (when it does not initially have the \"entered\" class) is to add the \"entered\" class when the mouse enters the <code>&lt;div&gt;</code> and remove the class when the mouse leaves. </p>\n <p>As of jQuery 1.4 we can bind multiple event handlers simultaneously by passing an object of event type/handler pairs:</p>\n <pre><code>\n$( \"#foo\" ).bind({\n click: function() {\n // Do something on click\n },\n mouseenter: function() {\n // Do something on mouseenter\n }\n});\n </code></pre>\n <h4 id=\"event-handlers\">Event Handlers</h4>\n <p>The <code>handler</code> parameter takes a callback function, as shown above. Within the handler, the keyword <code>this</code> refers to the DOM element to which the handler is bound. To make use of the element in jQuery, it can be passed to the normal <code>$()</code> function. For example:</p>\n <pre><code>\n$( \"#foo\" ).bind( \"click\", function() {\n alert( $( this ).text() );\n});\n </code></pre>\n <p>After this code is executed, when the user clicks inside the element with an ID of <code>foo</code>, its text contents will be shown as an alert.\n </p>\n <p>As of jQuery 1.4.2 duplicate event handlers can be bound to an element instead of being discarded. This is useful when the event data feature is being used, or when other unique data resides in a closure around the event handler function.</p>\n <p>In jQuery 1.4.3 you can now pass in <code>false</code> in place of an event handler. This will bind an event handler equivalent to: <code>function(){ return false; }</code>. This function can be removed at a later time by calling: <code>.unbind( eventName, false )</code>.</p>\n <h4 id=\"event-object\">\n <a href=\"/category/events/event-object/\">The Event object</a>\n </h4>\n <p>The <code>handler</code> callback function can also take parameters. When the function is called, the event object will be passed to the first parameter.</p>\n <p>The event object is often unnecessary and the parameter omitted, as sufficient context is usually available when the handler is bound to know exactly what needs to be done when the handler is triggered. However, at times it becomes necessary to gather more information about the user's environment at the time the event was initiated. <a href=\"/category/events/event-object/\">View the full Event Object</a>.</p>\n <p>Returning <code>false</code> from a handler is equivalent to calling both <code>.preventDefault()</code> and <code>.stopPropagation()</code> on the event object.</p>\n <p>Using the event object in a handler looks like this:</p>\n <pre><code>\n$( document ).ready(function() {\n $( \"#foo\" ).bind( \"click\", function( event ) {\n alert( \"The mouse cursor is at (\" +\n event.pageX + \", \" + event.pageY +\n \")\" );\n });\n});\n </code></pre>\n <p>Note the parameter added to the anonymous function. This code will cause a click on the element with ID <code>foo</code> to report the page coordinates of the mouse cursor at the time of the click.</p>\n <h4 id=\"passing-event-data\">Passing Event Data</h4>\n <p>The optional <code>eventData</code> parameter is not commonly used. When provided, this argument allows us to pass additional information to the handler. One handy use of this parameter is to work around issues caused by closures. For example, suppose we have two event handlers that both refer to the same external variable:</p>\n <pre><code>\nvar message = \"Spoon!\";\n$( \"#foo\" ).bind( \"click\", function() {\n alert( message );\n});\nmessage = \"Not in the face!\";\n$( \"#bar\" ).bind( \"click\", function() {\n alert( message );\n});\n </code></pre>\n <p>Because the handlers are closures that both have <code>message</code> in their environment, both will display the message <samp>Not in the face!</samp> when triggered. The variable's value has changed. To sidestep this, we can pass the message in using <code>eventData</code>:\n </p>\n <pre><code>\nvar message = \"Spoon!\";\n$( \"#foo\" ).bind( \"click\", {\n msg: message\n}, function( event ) {\n alert( event.data.msg );\n});\nmessage = \"Not in the face!\";\n$( \"#bar\" ).bind( \"click\", {\n msg: message\n}, function( event ) {\n alert( event.data.msg );\n});\n </code></pre>\n <p>This time the variable is not referred to directly within the handlers; instead, the variable is passed in <em>by value</em> through <code>eventData</code>, which fixes the value at the time the event is bound. The first handler will now display <samp>Spoon!</samp> while the second will alert <samp>Not in the face!</samp>\n </p>\n <div class=\"warning\">\n <p>Note that objects are passed to functions <em>by reference</em>, which further complicates this scenario.</p>\n </div>\n <p>If <code>eventData</code> is present, it is the second argument to the <code>.bind()</code> method; if no additional data needs to be sent to the handler, then the callback is passed as the second and final argument.</p>\n <div class=\"warning\">\n <p>See the <code>.trigger()</code> method reference for a way to pass data to a handler at the time the event happens rather than when the handler is bound.</p>\n </div>\n <p>As of jQuery 1.4 we can no longer attach data (and thus, events) to object, embed, or applet elements because critical errors occur when attaching data to Java applets.</p>\n <p><strong>Note: </strong>Although demonstrated in the next example, it is inadvisable to bind handlers to both the <code>click</code> and <code>dblclick</code> events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events before the <code>dblclick</code> and others only one. Double-click sensitivity (maximum time between clicks that is detected as a double click) can vary by operating system and browser, and is often user-configurable.</p>",
"examples": [{
"desc": "Handle click and double-click for the paragraph. Note: the coordinates are window relative, so in this case relative to the demo iframe.",
"code": "$( \"p\" ).bind( \"click\", function( event ) {\n var str = \"( \" + event.pageX + \", \" + event.pageY + \" )\";\n $( \"span\" ).text( \"Click happened! \" + str );\n});\n$( \"p\" ).bind( \"dblclick\", function() {\n $( \"span\" ).text( \"Double-click happened in \" + this.nodeName );\n});\n$( \"p\" ).bind( \"mouseenter mouseleave\", function( event ) {\n $( this ).toggleClass( \"over\" );\n});",
"html": "<p>Click or double click here.</p>\n<span></span>",
"css": "p {\n background: yellow;\n font-weight: bold;\n cursor: pointer;\n padding: 5px;\n }\n p.over {\n background: #ccc;\n }\n span {\n color: red;\n }"
},
{
"desc": "To display each paragraph's text in an alert box whenever it is clicked:",
"code": "$( \"p\" ).bind( \"click\", function() {\n alert( $( this ).text() );\n});",
"html": "",
"css": ""
},
{
"desc": "You can pass some extra data before the event handler:",
"code": "function handler( event ) {\n alert( event.data.foo );\n}\n$( \"p\" ).bind( \"click\", {\n foo: \"bar\"\n}, handler );",
"html": "",
"css": ""
},
{
"desc": "Cancel a default action and prevent it from bubbling up by returning <code>false</code>:",
"code": "$( \"form\" ).bind( \"submit\", function() {\n return false;\n})",
"html": "",
"css": ""
},
{
"desc": "Cancel only the default action by using the .preventDefault() method.",
"code": "$( \"form\" ).bind( \"submit\", function( event ) {\n event.preventDefault();\n});",
"html": "",
"css": ""
},
{
"desc": "Stop an event from bubbling without preventing the default action by using the .stopPropagation() method.",
"code": "$( \"form\" ).bind( \"submit\", function( event ) {\n event.stopPropagation();\n});",
"html": "",
"css": ""
},
{
"desc": "Bind custom events.",
"code": "$( \"p\" ).bind( \"myCustomEvent\", function( e, myName, myValue ) {\n $( this ).text( myName + \", hi there!\" );\n $( \"span\" )\n .stop()\n .css( \"opacity\", 1 )\n .text( \"myName = \" + myName )\n .fadeIn( 30 )\n .fadeOut( 1000 );\n });\n$( \"button\" ).click(function() {\n $( \"p\" ).trigger( \"myCustomEvent\", [ \"John\" ] );\n});",
"html": "<p>Has an attached custom event.</p>\n<button>Trigger custom event</button>\n<span style=\"display: none;\"></span>",
"css": "p {\n color: red;\n }\n span {\n color: blue;\n }"
},
{
"desc": "Bind multiple events simultaneously.",
"code": "$( \"div.test\" ).bind({\n click: function() {\n $( this ).addClass( \"active\" );\n },\n mouseenter: function() {\n $( this ).addClass( \"inside\" );\n },\n mouseleave: function() {\n $( this ).removeClass( \"inside\" );\n }\n});",
"html": "",
"css": ""
}
],
"categories": [
"events/event-handler-attachment",
"version/1.0",
"version/1.4",
"version/1.4.3",
"deprecated/deprecated-3.0"
]
},
{
"title": ".blur()",
"type": "method",
"name": "blur",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"blur\" JavaScript event, or trigger that event on an element.",
"longdesc": "<p>This method is a shortcut for <code>.on( \"blur\", handler )</code> in the first two variations, and <code>.trigger( \"blur\" )</code> in the third.</p>\n <p>The <code>blur</code> event is sent to an element when it loses focus. Originally, this event was only applicable to form elements, such as <code>&lt;input&gt;</code>. In recent browsers, the domain of the event has been extended to include all element types. An element can lose focus via keyboard commands, such as the Tab key, or by mouse clicks elsewhere on the page.</p>\n <p>For example, consider the HTML:</p>\n <pre><code>\n&lt;form&gt;\n &lt;input id=\"target\" type=\"text\" value=\"Field 1\"&gt;\n &lt;input type=\"text\" value=\"Field 2\"&gt;\n&lt;/form&gt;\n&lt;div id=\"other\"&gt;\n Trigger the handler\n&lt;/div&gt;\nThe event handler can be bound to the first input field:\n$( \"#target\" ).blur(function() {\n alert( \"Handler for .blur() called.\" );\n});\n </code></pre>\n <p>Now if the first field has the focus, clicking elsewhere or tabbing away from it displays the alert:</p>\n <p>\n <samp>Handler for .blur() called.</samp>\n </p>\n <p>To trigger the event programmatically, apply <code>.blur()</code> without an argument:</p>\n <pre><code>\n$( \"#other\" ).click(function() {\n $( \"#target\" ).blur();\n});\n </code></pre>\n <p>After this code executes, clicks on <samp>Trigger the handler</samp> will also alert the message.</p>\n <p>The <code>blur</code> event does not bubble in Internet Explorer. Therefore, scripts that rely on event delegation with the <code>blur</code> event will not work consistently across browsers. As of version 1.4.2, however, jQuery works around this limitation by mapping <code>blur</code> to the <code>focusout</code> event in its event delegation methods, <a href=\"/live/\"><code>.live()</code></a> and <a href=\"/delegate/\"><code>.delegate()</code></a>.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.blur()</code> method is just a shorthand for <code>.on( \"blur\", handler )</code>, detaching is possible using <code>.off( \"blur\" )</code>."
}],
"examples": [{
"desc": "To trigger the blur event on all paragraphs:",
"code": "$( \"p\" ).blur();",
"html": "",
"css": ""
}],
"categories": [
"events/form-events",
"forms",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ":button Selector",
"type": "selector",
"name": "button",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Selects all button elements and elements of type button.",
"longdesc": "<p>An equivalent selector to <code>$( \":button\" )</code> using valid CSS is <code>$( \"button, input[type='button']\" )</code>.</p>",
"note": [{
"type": "additional",
"text": "Because <code>:button</code> is a jQuery extension and not part of the CSS specification, queries using <code>:button</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>undefined</code> instead."
}],
"examples": [{
"desc": "Find all button inputs and mark them.",
"code": "var input = $( \":button\" ).addClass( \"marked\" );\n$( \"div\" ).text( \"For this type jQuery found \" + input.length + \".\" );\n// Prevent the form from submitting\n$( \"form\" ).submit(function( event ) {\n event.preventDefault();\n});",
"html": "<form>\n <fieldset>\n <input type=\"button\" value=\"Input Button\">\n <input type=\"checkbox\">\n\n <input type=\"file\">\n <input type=\"hidden\">\n <input type=\"image\">\n\n <input type=\"password\">\n <input type=\"radio\">\n <input type=\"reset\">\n\n <input type=\"submit\">\n <input type=\"text\">\n <select>\n <option>Option</option>\n </select>\n\n <textarea></textarea>\n <button>Button</button>\n </fieldset>\n</form>\n\n<div></div>",
"css": "textarea {\n height: 35px;\n }\n div {\n color: red;\n }\n fieldset {\n margin: 0;\n padding: 0;\n border-width: 0;\n }\n .marked {\n background-color: yellow;\n border: 3px red solid;\n }"
}],
"categories": [
"selectors/form-selectors",
"selectors/jquery-selector-extensions",
"version/1.0"
]
},
{
"title": "callbacks.add()",
"name": "callbacks.add",
"type": "method",
"return": "Callbacks",
"signatures": [{
"arguments": [{
"name": "callbacks",
"type": [
"Function",
"Array"
],
"desc": "A function, or array of functions, that are to be added to the callback list."
}],
"added": "1.7"
}],
"desc": "Add a callback or a collection of callbacks to a callback list.",
"longdesc": "<p>This method returns the Callbacks object onto which it is attached (<code>this</code>).</p>",
"examples": [{
"desc": "Use <code>callbacks.add()</code> to add new callbacks to a callback list:",
"code": "// A sample logging function to be added to a callbacks list\nvar foo = function( value ) {\n console.log( \"foo: \" + value );\n};\n\n// Another function to also be added to the list\nvar bar = function( value ) {\n console.log( \"bar: \" + value );\n};\n\nvar callbacks = $.Callbacks();\n\n// Add the function \"foo\" to the list\ncallbacks.add( foo );\n\n// Fire the items on the list\ncallbacks.fire( \"hello\" );\n// Outputs: \"foo: hello\"\n\n// Add the function \"bar\" to the list\ncallbacks.add( bar );\n\n// Fire the items on the list again\ncallbacks.fire( \"world\" );\n\n// Outputs:\n// \"foo: world\"\n// \"bar: world\"",
"html": "",
"css": ""
}],
"categories": [
"callbacks-object",
"version/1.7"
]
},
{
"title": "callbacks.disable()",
"name": "callbacks.disable",
"type": "method",
"return": "Callbacks",
"signatures": [{
"arguments": [],
"added": "1.7"
}],
"desc": "Disable a callback list from doing anything more.",
"longdesc": "<p>This method returns the Callbacks object onto which it is attached (<code>this</code>).</p>",
"examples": [{
"desc": "Use <code>callbacks.disable()</code> to disable further calls to a callback list:",
"code": "// A sample logging function to be added to a callbacks list\nvar foo = function( value ) {\n console.log( value );\n};\n\nvar callbacks = $.Callbacks();\n\n// Add the above function to the list\ncallbacks.add( foo );\n\n// Fire the items on the list\ncallbacks.fire( \"foo\" );\n// Outputs: foo\n\n// Disable further calls being possible\ncallbacks.disable();\n\n// Attempt to fire with \"foobar\" as an argument\ncallbacks.fire( \"foobar\" );\n// foobar isn't output",
"html": "",
"css": ""
}],
"categories": [
"callbacks-object",
"version/1.7"
]
},
{
"title": "callbacks.disabled()",
"name": "callbacks.disabled",
"type": "method",
"return": "Boolean",
"signatures": [{
"arguments": [],
"added": "1.7"
}],
"desc": "Determine if the callbacks list has been disabled.",
"longdesc": "",
"examples": [{
"desc": "Use <code>callbacks.disabled()</code> to determine if the callbacks list has been disabled:",
"code": "// A sample logging function to be added to a callbacks list\nvar foo = function( value ) {\n console.log( \"foo:\" + value );\n};\n\nvar callbacks = $.Callbacks();\n\n// Add the logging function to the callback list\ncallbacks.add( foo );\n\n// Fire the items on the list, passing an argument\ncallbacks.fire( \"hello\" );\n// Outputs \"foo: hello\"\n\n// Disable the callbacks list\ncallbacks.disable();\n\n// Test the disabled state of the list\nconsole.log ( callbacks.disabled() );\n// Outputs: true",
"html": "",
"css": ""
}],
"categories": [
"callbacks-object",
"version/1.7"
]
},
{
"title": "callbacks.empty()",
"name": "callbacks.empty",
"type": "method",
"return": "Callbacks",
"signatures": [{
"arguments": [],
"added": "1.7"
}],
"desc": "Remove all of the callbacks from a list.",
"longdesc": "<p>This method returns the Callbacks object onto which it is attached (<code>this</code>).</p>",
"examples": [{
"desc": "Use <code>callbacks.empty()</code> to empty a list of callbacks:",
"code": "// A sample logging function to be added to a callbacks list\nvar foo = function( value1, value2 ) {\n console.log( \"foo: \" + value1 + \",\" + value2 );\n};\n\n// Another function to also be added to the list\nvar bar = function( value1, value2 ) {\n console.log( \"bar: \" + value1 + \",\" + value2 );\n};\n\nvar callbacks = $.Callbacks();\n\n// Add the two functions\ncallbacks.add( foo );\ncallbacks.add( bar );\n\n// Empty the callbacks list\ncallbacks.empty();\n\n// Check to ensure all callbacks have been removed\nconsole.log( callbacks.has( foo ) );\n// false\nconsole.log( callbacks.has( bar ) );\n// false",
"html": "",
"css": ""
}],
"categories": [
"callbacks-object",
"version/1.7"
]
},
{
"title": "callbacks.fire()",
"name": "callbacks.fire",
"type": "method",
"return": "Callbacks",
"signatures": [{
"arguments": [{
"name": "arguments",
"type": "Anything",
"desc": "The argument or list of arguments to pass back to the callback list."
}],
"added": "1.7"
}],
"desc": "Call all of the callbacks with the given arguments.",
"longdesc": "<p>This method returns the Callbacks object onto which it is attached (<code>this</code>).</p>",
"examples": [{
"desc": "Use <code>callbacks.fire()</code> to invoke the callbacks in a list with any arguments that have been passed:",
"code": "// A sample logging function to be added to a callbacks list\nvar foo = function( value ) {\n console.log( \"foo:\" + value );\n};\n\nvar callbacks = $.Callbacks();\n\n// Add the function \"foo\" to the list\ncallbacks.add( foo );\n\n// Fire the items on the list\ncallbacks.fire( \"hello\" ); // Outputs: \"foo: hello\"\ncallbacks.fire( \"world\" ); // Outputs: \"foo: world\"\n\n// Add another function to the list\nvar bar = function( value ){\n console.log( \"bar:\" + value );\n};\n\n// Add this function to the list\ncallbacks.add( bar );\n\n// Fire the items on the list again\ncallbacks.fire( \"hello again\" );\n// Outputs:\n// \"foo: hello again\"\n// \"bar: hello again\"",
"html": "",
"css": ""
}],
"categories": [
"callbacks-object",
"version/1.7"
]
},
{
"title": "callbacks.fireWith()",
"name": "callbacks.fireWith",
"type": "method",
"return": "Callbacks",
"signatures": [{
"arguments": [{
"name": "context",
"optional": "true",
"type": "Anything",
"desc": "A reference to the context in which the callbacks in the list should be fired."
},
{
"name": "args",
"optional": "true",
"type": "ArrayLikeObject",
"desc": "An array or array-like object of arguments to pass to the callbacks in the list. If omitted or undefined, no arguments will be passed."
}
],
"added": "1.7"
}],
"desc": "Call all callbacks in a list with the given context and arguments.",
"longdesc": "<p>This method returns the Callbacks object onto which it is attached (<code>this</code>).</p>",
"examples": [{
"desc": "Use <code>callbacks.fireWith()</code> to fire a list of callbacks with a specific context and an array of arguments:",
"code": "// A sample logging function to be added to a callbacks list\nvar log = function( value1, value2 ) {\n console.log( \"Received: \" + value1 + \",\" + value2 );\n};\n\nvar callbacks = $.Callbacks();\n\n// Add the log method to the callbacks list\ncallbacks.add( log );\n\n// Fire the callbacks on the list using the context \"window\"\n// and an arguments array\n\ncallbacks.fireWith( window, [ \"foo\",\"bar\" ] );\n// Outputs: \"Received: foo, bar\"",
"html": "",
"css": ""
}],
"categories": [
"callbacks-object",
"version/1.7"
]
},
{
"title": "callbacks.fired()",
"name": "callbacks.fired",
"type": "method",
"return": "Boolean",
"signatures": [{
"arguments": [],
"added": "1.7"
}],
"desc": "Determine if the callbacks have already been called at least once.",
"longdesc": "",
"examples": [{
"desc": "Use <code>callbacks.fired()</code> to determine if the callbacks in a list have been called at least once:",
"code": "// A sample logging function to be added to a callbacks list\nvar foo = function( value ) {\n console.log( \"foo:\" + value );\n};\n\nvar callbacks = $.Callbacks();\n\n// Add the function \"foo\" to the list\ncallbacks.add( foo );\n\n// Fire the items on the list\ncallbacks.fire( \"hello\" ); // Outputs: \"foo: hello\"\ncallbacks.fire( \"world\" ); // Outputs: \"foo: world\"\n\n// Test to establish if the callbacks have been called\nconsole.log( callbacks.fired() );",
"html": "",
"css": ""
}],
"categories": [
"callbacks-object",
"version/1.7"
]
},
{
"title": "callbacks.has()",
"name": "callbacks.has",
"type": "method",
"return": "Boolean",
"signatures": [{
"arguments": [{
"name": "callback",
"type": "Function",
"optional": "true",
"desc": "The callback to search for."
}],
"added": "1.7"
}],
"desc": "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.",
"longdesc": "",
"examples": [{
"desc": "Use <code>callbacks.has()</code> to check if a callback list contains a specific callback:",
"code": "// A sample logging function to be added to a callbacks list\nvar foo = function( value1, value2 ) {\n console.log( \"Received: \" + value1 + \",\" + value2 );\n};\n\n// A second function which will not be added to the list\nvar bar = function( value1, value2 ) {\n console.log( \"foobar\" );\n};\n\nvar callbacks = $.Callbacks();\n\n// Add the log method to the callbacks list\ncallbacks.add( foo );\n\n// Determine which callbacks are in the list\nconsole.log( callbacks.has( foo ) );\n// true\nconsole.log( callbacks.has( bar ) );\n// false",
"html": "",
"css": ""
}],
"categories": [
"callbacks-object",
"version/1.7"
]
},
{
"title": "callbacks.lock()",
"name": "callbacks.lock",
"type": "method",
"return": "Callbacks",
"signatures": [{
"arguments": [],
"added": "1.7"
}],
"desc": "Lock a callback list in its current state.",
"longdesc": "<p>This method returns the Callbacks object onto which it is attached (<code>this</code>).</p>\n <p>If the Callbacks object is created with the <code>\"memory\"</code> flag as its argument, additional functions may be added and fired after the callback list is locked.</p>",
"examples": [{
"desc": "Use <code>callbacks.lock()</code> to lock a callback list to avoid further changes being made to the list state:",
"code": "// A sample logging function to be added to a callbacks list\nvar foo = function( value ) {\n console.log( \"foo:\" + value );\n};\n\nvar callbacks = $.Callbacks();\n\n// Add the logging function to the callback list\ncallbacks.add( foo );\n\n// Fire the items on the list, passing an argument\ncallbacks.fire( \"hello\" );\n// Outputs \"foo: hello\"\n\n// Lock the callbacks list\ncallbacks.lock();\n\n// Try firing the items again\ncallbacks.fire( \"world\" );\n\n// As the list was locked, no items were called,\n// so \"world\" isn't logged",
"html": "",
"css": ""
},
{
"desc": "Use <code>callbacks.lock()</code> to lock a callback list with \"memory,\" and then resume using the list:",
"code": "// Simple function for logging results\nvar log = function( value ) {\n $( \"#log\" ).append( \"<p>\" + value + \"</p>\" );\n};\n\n// Two sample functions to be added to a callbacks list\nvar foo = function( value ) {\n log( \"foo: \" + value );\n};\nvar bar = function( value ) {\n log( \"bar: \" + value );\n};\n\n// Create the callbacks object with the \"memory\" flag\nvar callbacks = $.Callbacks( \"memory\" );\n\n// Add the foo logging function to the callback list\ncallbacks.add( foo );\n\n// Fire the items on the list, passing an argument\ncallbacks.fire( \"hello\" );\n// Outputs \"foo: hello\"\n\n// Lock the callbacks list\ncallbacks.lock();\n\n// Try firing the items again\ncallbacks.fire( \"world\" );\n// As the list was locked, no items were called,\n// so \"foo: world\" isn't logged\n\n// Add the foo function to the callback list again\ncallbacks.add( foo );\n\n// Try firing the items again\ncallbacks.fire( \"silentArgument\" );\n// Outputs \"foo: hello\" because the argument value was stored in memory\n\n// Add the bar function to the callback list\ncallbacks.add( bar );\n\ncallbacks.fire( \"youHadMeAtHello\" );\n// Outputs \"bar: hello\" because the list is still locked,\n// and the argument value is still stored in memory",
"html": "<div id=\"log\"></div>",
"css": ""
}
],
"categories": [
"callbacks-object",
"version/1.7"
]
},
{
"title": "callbacks.locked()",
"name": "callbacks.locked",
"type": "method",
"return": "Boolean",
"signatures": [{
"arguments": [],
"added": "1.7"
}],
"desc": "Determine if the callbacks list has been locked.",
"longdesc": "",
"examples": [{
"desc": "Use <code>callbacks.locked()</code> to determine the lock-state of a callback list:",
"code": "// A sample logging function to be added to a callbacks list\nvar foo = function( value ) {\n console.log( \"foo: \" + value );\n};\n\nvar callbacks = $.Callbacks();\n\n// Add the logging function to the callback list\ncallbacks.add( foo );\n\n// Fire the items on the list, passing an argument\ncallbacks.fire( \"hello\" );\n// Outputs \"foo: hello\"\n\n// Lock the callbacks list\ncallbacks.lock();\n\n// Test the lock-state of the list\nconsole.log ( callbacks.locked() );\n// true",
"html": "",
"css": ""
}],
"categories": [
"callbacks-object",
"version/1.7"
]
},
{
"title": "callbacks.remove()",
"name": "callbacks.remove",
"type": "method",
"return": "Callbacks",
"signatures": [{
"arguments": [{
"name": "callbacks",
"type": [
"Function",
"Array"
],
"desc": "A function, or array of functions, that are to be removed from the callback list."
}],
"added": "1.7"
}],
"desc": "Remove a callback or a collection of callbacks from a callback list.",
"longdesc": "<p>This method returns the Callbacks object onto which it is attached (<code>this</code>).</p>",
"examples": [{
"desc": "Use <code>callbacks.remove()</code> to remove callbacks from a callback list:",
"code": "// A sample logging function to be added to a callbacks list\nvar foo = function( value ) {\n console.log( \"foo: \" + value );\n};\n\nvar callbacks = $.Callbacks();\n\n// Add the function \"foo\" to the list\ncallbacks.add( foo );\n\n// Fire the items on the list\ncallbacks.fire( \"hello\" );\n// Outputs: \"foo: hello\"\n\n// Remove \"foo\" from the callback list\ncallbacks.remove( foo );\n\n// Fire the items on the list again\ncallbacks.fire( \"world\" );\n\n// Nothing output as \"foo\" is no longer in the list",
"html": "",
"css": ""
}],
"categories": [
"callbacks-object",
"version/1.7"
]
},
{
"title": ".change()",
"type": "method",
"name": "change",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"change\" JavaScript event, or trigger that event on an element.",
"longdesc": "<p>\n\t\t\tThis method is a shortcut for\n\t\t\t<code>\n\t\t\t\t.on( \"change\", handler )\n\t\t\t</code>\n\t\t\tin the first two variations, and\n\t\t\t<code>\n\t\t\t\t.trigger( \"change\" )\n\t\t\t</code>\n\t\t\tin the third.\n\t\t</p>\n\t\t<p>\n\t\t\tThe\n\t\t\t<code>\n\t\t\t\tchange\n\t\t\t</code>\n\t\t\tevent is sent to an element when its value changes. This event is limited to\n\t\t\t<code>\n\t\t\t\t&lt;input&gt;\n\t\t\t</code>\n\t\t\telements,\n\t\t\t<code>\n\t\t\t\t&lt;textarea&gt;\n\t\t\t</code>\n\t\t\tboxes and\n\t\t\t<code>\n\t\t\t\t&lt;select&gt;\n\t\t\t</code>\n\t\t\telements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.\n\t\t</p>\n\t\t<p>\n\t\t\tFor example, consider the HTML:\n\t\t</p>\n\t\t<pre>\n\t\t\t<code>\n\t\t\t\t&lt;form&gt;\n\t\t\t\t&lt;input class=\"target\" type=\"text\" value=\"Field 1\"&gt;\n\t\t\t\t&lt;select class=\"target\"&gt;\n\t\t\t\t&lt;option value=\"option1\" selected=\"selected\"&gt;Option 1&lt;/option&gt;\n\t\t\t\t&lt;option value=\"option2\"&gt;Option 2&lt;/option&gt;\n\t\t\t\t&lt;/select&gt;\n\t\t\t\t&lt;/form&gt;\n\t\t\t\t&lt;div id=\"other\"&gt;\n\t\t\t\tTrigger the handler\n\t\t\t\t&lt;/div&gt;\n\t\t\t</code>\n\t\t</pre>\n\t\t<p>\n\t\t\tThe event handler can be bound to the text input and the select box:\n\t\t</p>\n\t\t<pre>\n\t\t\t<code>\n\t\t\t\t$( \".target\" ).change(function() {\n\t\t\t\talert( \"Handler for .change() called.\" );\n\t\t\t\t});\n\t\t\t</code>\n\t\t</pre>\n\t\t<p>\n\t\t\tNow when the second option is selected from the dropdown, the alert is displayed. It is also displayed if you change the text in the field and then click away. If the field loses focus without the contents having changed, though, the event is not triggered. To trigger the event manually, apply\n\t\t\t<code>\n\t\t\t\t.change()\n\t\t\t</code>\n\t\t\twithout arguments:\n\t\t</p>\n\t\t<pre>\n\t\t\t<code>\n\t\t\t\t$( \"#other\" ).click(function() {\n\t\t\t\t$( \".target\" ).change();\n\t\t\t\t});\n\t\t\t</code>\n\t\t</pre>\n\t\t<p>\n\t\t\tAfter this code executes, clicks on\n\t\t\t<samp>\n\t\t\t\tTrigger the handler\n\t\t\t</samp>\n\t\t\twill also alert the message. The message will display twice, because the handler has been bound to the\n\t\t\t<code>\n\t\t\t\tchange\n\t\t\t</code>\n\t\t\tevent on both of the form elements.\n\t\t</p>\n\t\t<p>\n\t\t\tAs of jQuery 1.4, the\n\t\t\t<code>\n\t\t\t\tchange\n\t\t\t</code>\n\t\t\tevent bubbles in Internet Explorer, behaving consistently with the event in other modern browsers.\n\t\t</p>\n\t\t<div class=\"warning\">\n\t\t\t<p>\n\t\t\t\t<strong>\n\t\t\t\t\tNote:\n\t\t\t\t</strong>\n\t\t\t\tChanging the value of an input element using JavaScript, using\n\t\t\t\t<a href=\"/val\">\n\t\t\t\t\t<code>\n\t\t\t\t\t\t.val()\n\t\t\t\t\t</code>\n\t\t\t\t</a>\n\t\t\t\tfor example, won't fire the event.\n\t\t\t</p>\n\t\t</div>",
"note": [{
"type": "additional",
"text": "As the <code>.change()</code> method is just a shorthand for <code>.on( \"change\", handler )</code>, detaching is possible using <code>.off( \"change\" )</code>."
}],
"examples": [{
"desc": "Attaches a change event to the select that gets the text for each selected option and writes them in the div. It then triggers the event for the initial text draw.",
"code": "$( \"select\" )\n\t\t\t.change(function () {\n\t\t\tvar str = \"\";\n\t\t\t$( \"select option:selected\" ).each(function() {\n\t\t\tstr += $( this ).text() + \" \";\n\t\t\t});\n\t\t\t$( \"div\" ).text( str );\n\t\t\t})\n\t\t\t.change();",
"html": "<select name=\"sweets\" multiple=\"multiple\">\n\t\t\t<option>Chocolate</option>\n\t\t\t<option selected=\"selected\">Candy</option>\n\t\t\t<option>Taffy</option>\n\t\t\t<option selected=\"selected\">Caramel</option>\n\t\t\t<option>Fudge</option>\n\t\t\t<option>Cookie</option>\n\t\t\t</select>\n\t\t\t<div></div>",
"css": "div {\n\t\t\tcolor: red;\n\t\t\t}"
},
{
"desc": "To add a validity test to all text input elements:",
"code": "$( \"input[type='text']\" ).change(function() {\n\t\t\t// Check input( $( this ).val() ) for validity here\n\t\t\t});",
"html": "",
"css": ""
}
],
"categories": [
"events/form-events",
"forms",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ":checkbox Selector",
"type": "selector",
"name": "checkbox",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Selects all elements of type checkbox.",
"longdesc": "<p><code>$( \":checkbox\" )</code> is equivalent to <code>$( \"[type=checkbox]\" )</code>. As with other pseudo-class selectors (those that begin with a \":\") it is recommended to precede it with a tag name or some other selector; otherwise, the universal selector (\"*\") is implied. In other words, the bare <code>$(':checkbox')</code> is equivalent to <code>$( \"*:checkbox\" )</code>, so <code>$( \"input:checkbox\" )</code> should be used instead. </p>",
"note": [{
"type": "additional",
"text": "Because <code>:checkbox</code> is a jQuery extension and not part of the CSS specification, queries using <code>:checkbox</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>[type=\"checkbox\"]</code> instead."
}],
"examples": [{
"desc": "Finds all checkbox inputs.",
"code": "var input = $( \"form input:checkbox\" )\n .wrap( \"<span></span>\" )\n .parent()\n .css({\n background: \"yellow\",\n border: \"3px red solid\"\n });\n\n$( \"div\" )\n .text( \"For this type jQuery found \" + input.length + \".\" )\n .css( \"color\", \"red\" );\n\n// Prevent the form from submitting\n$( \"form\" ).submit(function( event ) {\n event.preventDefault();\n});",
"html": "<form>\n <input type=\"button\" value=\"Input Button\">\n <input type=\"checkbox\">\n\n <input type=\"checkbox\">\n <input type=\"file\">\n <input type=\"hidden\">\n\n <input type=\"image\">\n <input type=\"password\">\n <input type=\"radio\">\n\n <input type=\"reset\">\n <input type=\"submit\">\n <input type=\"text\">\n\n <select>\n <option>Option</option>\n </select>\n\n <textarea></textarea>\n <button>Button</button>\n</form>\n\n<div></div>",
"css": "textarea {\n height: 25px;\n }"
}],
"categories": [
"selectors/form-selectors",
"selectors/jquery-selector-extensions",
"version/1.0"
]
},
{
"title": ":checked Selector",
"type": "selector",
"name": "checked",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Matches all elements that are checked or selected.",
"longdesc": "<p>The <code>:checked</code> selector works for checkboxes, radio buttons, and options of <code>select</code> elements.</p>\n <p>To retrieve only the selected options of <code>select</code> elements, use the <a href=\"/selected-selector/\"><code>:selected</code></a> selector.</p>",
"examples": [{
"desc": "Determine how many input elements are checked.",
"code": "var countChecked = function() {\n var n = $( \"input:checked\" ).length;\n $( \"div\" ).text( n + (n === 1 ? \" is\" : \" are\") + \" checked!\" );\n};\ncountChecked();\n\n$( \"input[type=checkbox]\" ).on( \"click\", countChecked );",
"html": "<form>\n <p>\n <input type=\"checkbox\" name=\"newsletter\" value=\"Hourly\" checked=\"checked\">\n\n <input type=\"checkbox\" name=\"newsletter\" value=\"Daily\">\n <input type=\"checkbox\" name=\"newsletter\" value=\"Weekly\">\n\n <input type=\"checkbox\" name=\"newsletter\" value=\"Monthly\" checked>\n <input type=\"checkbox\" name=\"newsletter\" value=\"Yearly\">\n </p>\n</form>\n<div></div>",
"css": "div {\n color: red;\n }"
},
{
"desc": "Identify the checked radio input.",
"code": "$( \"input\" ).on( \"click\", function() {\n $( \"#log\" ).html( $( \"input:checked\" ).val() + \" is checked!\" );\n});",
"html": "<form>\n <div>\n <input type=\"radio\" name=\"fruit\" value=\"orange\" id=\"orange\">\n <label for=\"orange\">orange</label>\n </div>\n <div>\n <input type=\"radio\" name=\"fruit\" value=\"apple\" id=\"apple\">\n <label for=\"apple\">apple</label>\n </div>\n <div>\n <input type=\"radio\" name=\"fruit\" value=\"banana\" id=\"banana\">\n <label for=\"banana\">banana</label>\n </div>\n <div id=\"log\"></div>\n</form>",
"css": "input, label {\n line-height: 1.5em;\n }"
}
],
"categories": [
"selectors/form-selectors",
"version/1.0"
]
},
{
"title": "Child Selector (\"parent > child\")",
"type": "selector",
"name": "child",
"return": "",
"signatures": [{
"arguments": [{
"name": "parent",
"type": "Selector",
"desc": "Any valid selector."
},
{
"name": "child",
"type": "Selector",
"desc": "A selector to filter the child elements."
}
],
"added": "1.0"
}],
"desc": "Selects all direct child elements specified by \"child\" of elements specified by \"parent\".",
"longdesc": "<p>The child combinator (E <strong>&gt;</strong> F) can be thought of as a more specific form of the descendant combinator (E F) in that it selects only first-level descendants.</p>",
"examples": [{
"desc": "Places a border around all list items that are children of &lt;ul class=\"topnav\"&gt; .",
"code": "$( \"ul.topnav > li\" ).css( \"border\", \"3px double red\" );",
"html": "<ul class=\"topnav\">\n <li>Item 1</li>\n <li>Item 2\n <ul>\n <li>Nested item 1</li>\n <li>Nested item 2</li>\n <li>Nested item 3</li>\n </ul>\n </li>\n <li>Item 3</li>\n</ul>",
"css": "body {\n font-size: 14px;\n }"
}],
"categories": [
"selectors/hierarchy-selectors",
"version/1.0"
]
},
{
"title": ".children()",
"type": "method",
"name": "children",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "selector",
"optional": "true",
"type": "Selector",
"desc": "A string containing a selector expression to match elements against."
}],
"added": "1.0"
}],
"desc": "Get the children of each element in the set of matched elements, optionally filtered by a selector.",
"longdesc": "<p>Given a jQuery object that represents a set of DOM elements, the <code>.children()</code> method allows us to search through the children of these elements in the DOM tree and construct a new jQuery object from the matching elements. The <code>.children()</code> method differs from <code><a href=\"/find/\">.find()</a></code> in that <code>.children()</code> only travels a single level down the DOM tree while <code>.find()</code> can traverse down multiple levels to select descendant elements (grandchildren, etc.) as well. Note also that like most jQuery methods, <code>.children()</code> does not return text nodes; to get <em>all</em> children including text and comment nodes, use <code><a href=\"/contents/\">.contents()</a></code>.</p>\n <p>The <code>.children()</code> method optionally accepts a selector expression of the same type that we can pass to the <code>$()</code> function. If the selector is supplied, the elements will be filtered by testing whether they match it.</p>\n <p>Consider a page with a basic nested list on it:</p>\n <pre><code>\n&lt;ul class=\"level-1\"&gt;\n &lt;li class=\"item-i\"&gt;I&lt;/li&gt;\n &lt;li class=\"item-ii\"&gt;II\n &lt;ul class=\"level-2\"&gt;\n &lt;li class=\"item-a\"&gt;A&lt;/li&gt;\n &lt;li class=\"item-b\"&gt;B\n &lt;ul class=\"level-3\"&gt;\n &lt;li class=\"item-1\"&gt;1&lt;/li&gt;\n &lt;li class=\"item-2\"&gt;2&lt;/li&gt;\n &lt;li class=\"item-3\"&gt;3&lt;/li&gt;\n &lt;/ul&gt;\n &lt;/li&gt;\n &lt;li class=\"item-c\"&gt;C&lt;/li&gt;\n &lt;/ul&gt;\n &lt;/li&gt;\n &lt;li class=\"item-iii\"&gt;III&lt;/li&gt;\n&lt;/ul&gt;\n</code></pre>\n <p>If we begin at the level-2 list, we can find its children:</p>\n <pre><code>$( \"ul.level-2\" ).children().css( \"background-color\", \"red\" );</code></pre>\n <p>The result of this call is a red background behind items A, B, and C. Since we do not supply a selector expression, all of the children are part of the returned jQuery object. If we had supplied one, only the matching items among these three would be included.</p>",
"examples": [{
"desc": "Find all children of the clicked element.",
"code": "$( \"#container\" ).click(function ( event ) {\n $( \"*\" ).removeClass( \"hilite\" );\n var kids = $( event.target ).children();\n var len = kids.addClass( \"hilite\" ).length;\n\n $( \"#results span\" ).first().text( len );\n $( \"#results span\" ).last().text( event.target.tagName );\n\n event.preventDefault();\n});",
"html": "<div id=\"container\">\n <div>\n <p>This <span>is the <em>way</em> we</span>\n write <em>the</em> demo,</p>\n </div>\n\n <div>\n <a href=\"#\"><b>w</b>rit<b>e</b></a> the <span>demo,</span> <button>write\n the</button> demo,\n </div>\n\n <div>\n This <span>the way we <em>write</em> the <em>demo</em> so</span>\n <input type=\"text\" value=\"early\"> in\n </div>\n\n <p>\n <span>t</span>he <span>m</span>orning.\n <span id=\"results\">Found <span>0</span> children in <span>TAG</span>.</span>\n </p>\n</div>",
"css": "body {\n font-size: 16px;\n font-weight: bolder;\n }\n div {\n width: 130px;\n height: 82px;\n margin: 10px;\n float: left;\n border: 1px solid blue;\n padding: 4px;\n }\n #container {\n width: auto;\n height: 105px;\n margin: 0;\n float: none;\n border: none;\n }\n .hilite {\n border-color: red;\n }\n #results {\n display: block;\n color: red;\n }\n p, span, em, a, b, button {\n border: 1px solid transparent;\n }\n p {\n margin: 10px;\n }\n span {\n color: blue;\n }\n input {\n width: 100px;\n }"
},
{
"desc": "Find all children of each div.",
"code": "$( \"div\" ).children().css( \"border-bottom\", \"3px double red\" );",
"html": "<p>Hello (this is a paragraph)</p>\n\n<div><span>Hello Again (this span is a child of the a div)</span></div>\n<p>And <span>Again</span> (in another paragraph)</p>\n\n<div>And One Last <span>Time</span> (most text directly in a div)</div>",
"css": "body {\n font-size: 16px;\n font-weight: bolder;\n }\n span {\n color: blue;\n }\n p {\n margin: 5px 0;\n }"
},
{
"desc": "Find all children with a class \"selected\" of each div.",
"code": "$( \"div\" ).children( \".selected\" ).css( \"color\", \"blue\" );",
"html": "<div>\n <span>Hello</span>\n <p class=\"selected\">Hello Again</p>\n <div class=\"selected\">And Again</div>\n <p>And One Last Time</p>\n</div>",
"css": "body {\n font-size: 16px;\n font-weight: bolder;\n }\n p {\n margin: 5px 0;\n }"
}
],
"categories": [
"traversing/tree-traversal",
"version/1.0"
]
},
{
"title": "Class Selector (\".class\")",
"type": "selector",
"name": "class",
"return": "",
"signatures": [{
"arguments": [{
"name": "class",
"type": "String",
"desc": "A class to search for. An element can have multiple classes; only one of them must match."
}],
"added": "1.0"
}],
"desc": "Selects all elements with the given class.",
"longdesc": "<p>For class selectors, jQuery uses JavaScript's native <code>getElementsByClassName()</code> function if the browser supports it.</p>",
"examples": [{
"desc": "Finds the element with the class \"myClass\".",
"code": "$( \".myClass\" ).css( \"border\", \"3px solid red\" );",
"html": "<div class=\"notMe\">div class=\"notMe\"</div>\n<div class=\"myClass\">div class=\"myClass\"</div>\n<span class=\"myClass\">span class=\"myClass\"</span>",
"css": "div, span {\n width: 120px;\n height: 40px;\n float: left;\n padding: 10px;\n margin: 10px;\n background-color: #EEEEEE;\n }"
},
{
"desc": "Finds the element with both \"myclass\" and \"otherclass\" classes.",
"code": "$( \".myclass.otherclass\" ).css( \"border\", \"13px solid red\" );",
"html": "<div class=\"myclass\">div class=\"notMe\"</div>\n<div class=\"myclass otherclass\">div class=\"myClass\"</div>\n<span class=\"myclass otherclass\">span class=\"myClass\"</span>",
"css": "div, span {\n width: 120px;\n height: 40px;\n float: left;\n padding: 10px;\n margin: 10px;\n background-color: #EEEEEE;\n }"
}
],
"categories": [
"selectors/basic-css-selectors",
"version/1.0"
]
},
{
"title": ".clearQueue()",
"type": "method",
"name": "clearQueue",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "queueName",
"optional": "true",
"type": "String",
"desc": "A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue."
}],
"added": "1.4"
}],
"desc": "Remove from the queue all items that have not yet been run.",
"longdesc": "<p>When the <code>.clearQueue()</code> method is called, all functions on the queue that have not been executed are removed from the queue. When used without an argument, <code>.clearQueue()</code> removes the remaining functions from <code>fx</code>, the standard effects queue. In this way it is similar to <code>.stop(true)</code>. However, while the <code>.stop()</code> method is meant to be used only with animations, <code>.clearQueue()</code> can also be used to remove any function that has been added to a generic jQuery queue with the <code>.queue()</code> method. </p>",
"examples": [{
"desc": "Empty the queue.",
"code": "$( \"#start\" ).click(function() {\n var myDiv = $( \"div\" );\n myDiv.show( \"slow\" );\n myDiv.animate({\n left:\"+=200\"\n }, 5000 );\n\n myDiv.queue(function() {\n var that = $( this );\n that.addClass( \"newcolor\" );\n that.dequeue();\n });\n\n myDiv.animate({\n left:\"-=200\"\n }, 1500 );\n myDiv.queue(function() {\n var that = $( this );\n that.removeClass( \"newcolor\" );\n that.dequeue();\n });\n myDiv.slideUp();\n});\n\n$( \"#stop\" ).click(function() {\n var myDiv = $( \"div\" );\n myDiv.clearQueue();\n myDiv.stop();\n});",
"html": "<button id=\"start\">Start</button>\n<button id=\"stop\">Stop</button>\n<div></div>",
"css": "div {\n margin: 3px;\n width: 40px;\n height: 40px;\n position: absolute;\n left: 0px;\n top: 30px;\n background: green;\n display: none;\n }\n div.newcolor {\n background: blue;\n }"
}],
"categories": [
"effects/custom-effects",
"data",
"utilities",
"version/1.4"
]
},
{
"title": ".click()",
"type": "method",
"name": "click",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"click\" JavaScript event, or trigger that event on an element.",
"longdesc": "<p>This method is a shortcut for <code>.on( \"click\", handler )</code> in the first two variations, and <code>.trigger( \"click\" )</code> in the third.\n The <code>click</code> event is sent to an element when the mouse pointer is over the element, and the mouse button is pressed and released. Any HTML element can receive this event.\n For example, consider the HTML:</p>\n <pre><code>\n&lt;div id=\"target\"&gt;\n Click here\n&lt;/div&gt;\n&lt;div id=\"other\"&gt;\n Trigger the handler\n&lt;/div&gt;\n </code></pre>\n <figure>\n <img src=\"/resources/0042_05_03.png\" alt=\"\"/>\n <figcaption>Figure 1 - Illustration of the rendered HTML</figcaption>\n </figure>\n <p>The event handler can be bound to any <code>&lt;div&gt;</code>:</p>\n <pre><code>\n$( \"#target\" ).click(function() {\n alert( \"Handler for .click() called.\" );\n});\n </code></pre>\n <p>Now if we click on this element, the alert is displayed:</p>\n <p>\n <samp>Handler for .click() called.</samp>\n </p>\n <p>We can also trigger the event when a different element is clicked:</p>\n <pre><code>\n$( \"#other\" ).click(function() {\n $( \"#target\" ).click();\n});\n </code></pre>\n <p>After this code executes, clicking on <samp>Trigger the handler</samp> will also alert the message.</p>\n <p>The <code>click</code> event is only triggered after this exact series of events:</p>\n <ul>\n <li>The mouse button is depressed while the pointer is inside the element.</li>\n <li>The mouse button is released while the pointer is inside the element.</li>\n </ul>\n <p>This is usually the desired sequence before taking an action. If this is not required, the <code>mousedown</code> or <code>mouseup</code> event may be more suitable.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.click()</code> method is just a shorthand for <code>.on( \"click\", handler )</code>, detaching is possible using <code>.off( \"click\" )</code>."
}],
"examples": [{
"desc": "Hide paragraphs on a page when they are clicked:",
"code": "$( \"p\" ).click(function() {\n $( this ).slideUp();\n});",
"html": "<p>First Paragraph</p>\n<p>Second Paragraph</p>\n<p>Yet one more Paragraph</p>",
"css": "p {\n color: red;\n margin: 5px;\n cursor: pointer;\n }\n p:hover {\n background: yellow;\n }"
},
{
"desc": "Trigger the click event on all of the paragraphs on the page:",
"code": "$( \"p\" ).click();",
"html": "",
"css": ""
}
],
"categories": [
"events/mouse-events",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ".clone()",
"type": "method",
"name": "clone",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "withDataAndEvents",
"optional": "true",
"type": "Boolean",
"default": "false",
"desc": "A Boolean indicating whether event handlers should be copied along with the elements. As of jQuery 1.4, element data will be copied as well."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "withDataAndEvents",
"optional": "true",
"type": "Boolean",
"default": "false",
"desc": "A Boolean indicating whether event handlers and data should be copied along with the elements. The default value is <code>false</code>. <em>*In jQuery 1.5.0 the default value was incorrectly <code>true</code>; it was changed back to <code>false</code> in 1.5.1 and up.</em>"
},
{
"name": "deepWithDataAndEvents",
"optional": "true",
"type": "Boolean",
"default": "value of withDataAndEvents",
"desc": "A Boolean indicating whether event handlers and data for all children of the cloned element should be copied. By default its value matches the first argument's value (which defaults to <code>false</code>)."
}
],
"added": "1.5"
}
],
"desc": "Create a deep copy of the set of matched elements.",
"longdesc": "<p>The <code>.clone()</code> method performs a <em>deep</em> copy of the set of matched elements, meaning that it copies the matched elements as well as all of their descendant elements and text nodes.</p>\n <div class=\"warning\">\n <p><strong>Note:</strong> For performance reasons, the dynamic state of certain form elements (e.g., user data typed into <code>textarea</code> and user selections made to a <code>select</code>) is not copied to the cloned elements. When cloning <code>input</code> elements, the dynamic state of the element (e.g., user data typed into text inputs and user selections made to a checkbox) is retained in the cloned elements.</p>\n </div>\n <p>When used in conjunction with one of the insertion methods, <code>.clone()</code> is a convenient way to duplicate elements on a page. Consider the following HTML:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;div class=\"hello\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"goodbye\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>As shown in the discussion for <code><a href=\"/append/\">.append()</a></code>, normally when an element is inserted somewhere in the DOM, it is moved from its old location. So, given the code:</p>\n <pre><code>\n$( \".hello\" ).appendTo( \".goodbye\" );\n </code></pre>\n <p>The resulting DOM structure would be:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;div class=\"goodbye\"&gt;\n Goodbye\n &lt;div class=\"hello\"&gt;Hello&lt;/div&gt;\n &lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>To prevent this and instead create a copy of the element, you could write the following:</p>\n <pre><code>\n$( \".hello\" ).clone().appendTo( \".goodbye\" );\n </code></pre>\n <p>This would produce:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;div class=\"hello\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"goodbye\"&gt;\n Goodbye\n &lt;div class=\"hello\"&gt;Hello&lt;/div&gt;\n &lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <div class=\"warning\">\n <p><strong>Note:</strong> When using the <code>.clone()</code> method, you can modify the cloned elements or their contents before (re-)inserting them into the document.</p>\n </div>\n <p>Normally, any event handlers bound to the original element are <em>not</em> copied to the clone. The optional <code>withDataAndEvents</code> parameter allows us to change this behavior, and to instead make copies of all of the event handlers as well, bound to the new copy of the element. As of jQuery 1.4, all element data (attached by the <code>.data()</code> method) is also copied to the new copy. </p>\n <p>However, objects and arrays within element data are not copied and will continue to be shared between the cloned element and the original element. To deep copy all data, copy each one manually:</p>\n <pre><code>\n// Original element with attached data\nvar $elem = $( \"#elem\" ).data( \"arr\", [ 1 ] ),\n $clone = $elem.clone( true )\n // Deep copy to prevent data sharing\n .data( \"arr\", $.extend( [], $elem.data( \"arr\" ) ) );\n </code></pre>\n <p>As of jQuery 1.5, <code>withDataAndEvents</code> can be optionally enhanced with <code>deepWithDataAndEvents </code> to copy the events and data for all children of the cloned element.</p>\n <div class=\"warning\">\n <p><strong>Note:</strong> Using <code>.clone()</code> has the side-effect of producing elements with duplicate <code>id</code> attributes, which are supposed to be unique. Where possible, it is recommended to avoid cloning elements with this attribute or using <code>class</code> attributes as identifiers instead.</p>\n </div>",
"examples": [{
"desc": "Clones all b elements (and selects the clones) and prepends them to all paragraphs.",
"code": "$( \"b\" ).clone().prependTo( \"p\" );",
"html": "<b>Hello</b><p>, how are you?</p>",
"css": ""
}],
"categories": [
"manipulation/copying",
"version/1.0",
"version/1.5"
]
},
{
"entries": [{
"title": ".closest()",
"type": "method",
"name": "closest",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "selector",
"type": "Selector",
"desc": "A string containing a selector expression to match elements against."
}],
"added": "1.3"
},
{
"arguments": [{
"name": "selector",
"type": "Selector",
"desc": "A string containing a selector expression to match elements against."
},
{
"name": "context",
"optional": "true",
"type": "Element",
"desc": "A DOM element within which a matching element may be found."
}
],
"added": "1.4"
},
{
"arguments": [{
"name": "selection",
"type": "jQuery",
"desc": "A jQuery object to match elements against."
}],
"added": "1.6"
},
{
"arguments": [{
"name": "element",
"type": "Element",
"desc": "An element to match elements against."
}],
"added": "1.6"
}
],
"desc": "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.",
"longdesc": "<p>Given a jQuery object that represents a set of DOM elements, the <code>.closest()</code> method searches through these elements and their ancestors in the DOM tree and constructs a new jQuery object from the matching elements. The <a href=\"/parents/\"><code>.parents()</code></a> and <code>.closest()</code> methods are similar in that they both traverse up the DOM tree. The differences between the two, though subtle, are significant:</p>\n <table>\n <thead>\n <tr>\n <th>\n <code>.closest()</code>\n </th>\n <th>\n <a href=\"/parents/\">\n <code>.parents()</code>\n </a>\n </th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>Begins with the current element</td>\n <td>Begins with the parent element</td>\n </tr>\n <tr>\n <td>Travels up the DOM tree until it finds a match for the supplied selector</td>\n <td>Travels up the DOM tree to the document's root element, adding each ancestor element to a temporary collection; it then filters that collection based on a selector if one is supplied </td>\n </tr>\n <tr>\n <td>The returned jQuery object contains zero or one element for each element in the original set, in document order</td>\n <td>The returned jQuery object contains zero or more elements for each element in the original set, in reverse document order</td>\n </tr>\n </tbody>\n </table>\n <pre><code>\n&lt;ul id=\"one\" class=\"level-1\"&gt;\n &lt;li class=\"item-i\"&gt;I&lt;/li&gt;\n &lt;li id=\"ii\" class=\"item-ii\"&gt;II\n &lt;ul class=\"level-2\"&gt;\n &lt;li class=\"item-a\"&gt;A&lt;/li&gt;\n &lt;li class=\"item-b\"&gt;B\n &lt;ul class=\"level-3\"&gt;\n &lt;li class=\"item-1\"&gt;1&lt;/li&gt;\n &lt;li class=\"item-2\"&gt;2&lt;/li&gt;\n &lt;li class=\"item-3\"&gt;3&lt;/li&gt;\n &lt;/ul&gt;\n &lt;/li&gt;\n &lt;li class=\"item-c\"&gt;C&lt;/li&gt;\n &lt;/ul&gt;\n &lt;/li&gt;\n &lt;li class=\"item-iii\"&gt;III&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>Suppose we perform a search for <code>&lt;ul&gt;</code> elements starting at item A:</p>\n <pre><code>\n$( \"li.item-a\" )\n .closest( \"ul\" )\n .css( \"background-color\", \"red\" );\n </code></pre>\n <p>This will change the color of the level-2 <code>&lt;ul&gt;</code>, since it is the first encountered when traveling up the DOM tree.</p>\n <p>Suppose we search for an <code>&lt;li&gt;</code> element instead:</p>\n <pre><code>\n$( \"li.item-a\" )\n .closest( \"li\" )\n .css( \"background-color\", \"red\" );\n </code></pre>\n <p>This will change the color of list item A. The <code>.closest()</code> method begins its search <em>with the element itself</em> before progressing up the DOM tree, and stops when item A matches the selector.</p>\n <p>We can pass in a DOM element as the context within which to search for the closest element.</p>\n <pre><code>\nvar listItemII = document.getElementById( \"ii\" );\n$( \"li.item-a\" )\n .closest( \"ul\", listItemII )\n .css( \"background-color\", \"red\" );\n$( \"li.item-a\" )\n .closest( \"#one\", listItemII )\n .css( \"background-color\", \"green\" );\n </code></pre>\n <p>This will change the color of the level-2 <code>&lt;ul&gt;</code>, because it is both the first <code>&lt;ul&gt;</code> ancestor of list item A and a descendant of list item II. It will not change the color of the level-1 <code>&lt;ul&gt;</code>, however, because it is not a descendant of list item II.</p>",
"examples": [{
"desc": "Show how event delegation can be done with closest. The closest list element toggles a yellow background when it or its descendent is clicked.",
"code": "$( document ).on( \"click\", function( event ) {\n $( event.target ).closest( \"li\" ).toggleClass( \"highlight\" );\n});",
"html": "<ul>\n <li><b>Click me!</b></li>\n <li>You can also <b>Click me!</b></li>\n</ul>",
"css": "li {\n margin: 3px;\n padding: 3px;\n background: #EEEEEE;\n }\n li.highlight {\n background: yellow;\n }"
},
{
"desc": "Pass a jQuery object to closest. The closest list element toggles a yellow background when it or its descendent is clicked.",
"code": "var listElements = $( \"li\" ).css( \"color\", \"blue\" );\n$( document ).on( \"click\", function( event ) {\n $( event.target ).closest( listElements ).toggleClass( \"highlight\" );\n});",
"html": "<ul>\n <li><b>Click me!</b></li>\n <li>You can also <b>Click me!</b></li>\n</ul>",
"css": "li {\n margin: 3px;\n padding: 3px;\n background: #EEEEEE;\n }\n li.highlight {\n background: yellow;\n }"
}
],
"categories": [
"traversing/tree-traversal",
"version/1.3",
"version/1.4",
"version/1.6"
]
},
{
"title": "",
"type": "method",
"name": "closest",
"return": "Array",
"deprecated": "1.7",
"removed": "1.8",
"signatures": [{
"arguments": [{
"name": "selectors",
"type": "Array",
"desc": "An array or string containing a selector expression to match elements against (can also be a jQuery object)."
},
{
"name": "context",
"optional": "true",
"type": "Element",
"desc": "A DOM element within which a matching element may be found."
}
],
"added": "1.4"
}],
"desc": "Get an array of all the elements and selectors matched against the current element up through the DOM tree.",
"longdesc": "<div class=\"warning\"><strong>This signature (only!) is deprecated as of jQuery 1.7 and <em>removed</em> in jQuery 1.8</strong>. It was primarily meant to be used internally or by plugin authors.</div>",
"examples": [],
"categories": [
"traversing/tree-traversal",
"version/1.3",
"version/1.4",
"version/1.6"
]
}
]
},
{
"title": ":contains() Selector",
"type": "selector",
"name": "contains",
"return": "",
"signatures": [{
"arguments": [{
"name": "text",
"type": "String",
"desc": "A string of text to look for. It's case sensitive."
}],
"added": "1.1.4"
}],
"desc": "Select all elements that contain the specified text.",
"longdesc": "<p>The matching text can appear directly within the selected element, in any of that element's descendants, or a combination thereof. As with attribute value selectors, text inside the parentheses of <code>:contains()</code> can be written as a bare word or surrounded by quotation marks. The text must have matching case to be selected.</p>",
"examples": [{
"desc": "Finds all divs containing \"John\" and underlines them.",
"code": "$( \"div:contains('John')\" ).css( \"text-decoration\", \"underline\" );",
"html": "<div>John Resig</div>\n<div>George Martin</div>\n<div>Malcom John Sinclair</div>\n<div>J. Ohn</div>",
"css": ""
}],
"categories": [
"selectors/content-filter-selector",
"version/1.1.4"
]
},
{
"title": ".contents()",
"type": "method",
"name": "contents",
"return": "jQuery",
"signatures": [{
"arguments": [],
"added": "1.2"
}],
"desc": "Get the children of each element in the set of matched elements, including text and comment nodes.",
"longdesc": "<p>Given a jQuery object that represents a set of DOM elements, the <code>.contents()</code> method allows us to search through the immediate children of these elements in the DOM tree and construct a new jQuery object from the matching elements. The <code>.contents()</code> and <code>.children()</code> methods are similar, except that the former includes text nodes and comment nodes as well as HTML elements in the resulting jQuery object. Please note that most jQuery operations don't support text nodes and comment nodes. The few that do will have an explicit note on their API documentation page.</p>\n <p>The <code>.contents()</code> method can also be used to get the content document of an iframe, if the iframe is on the same domain as the main page.</p>\n <p>Consider a simple <code>&lt;div&gt;</code> with a number of text nodes, each of which is separated by two line break elements (<code>&lt;br&gt;</code>):</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed\n do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n &lt;br&gt;&lt;br&gt;\n Ut enim ad minim veniam, quis nostrud exercitation ullamco\n laboris nisi ut aliquip ex ea commodo consequat.\n &lt;br&gt;&lt;br&gt;\n Duis aute irure dolor in reprehenderit in voluptate velit\n esse cillum dolore eu fugiat nulla pariatur.\n&lt;/div&gt;\n </code></pre>\n <p>We can employ the <code>.contents()</code> method to help convert this blob of text into three well-formed paragraphs:</p>\n <pre><code>\n$( \".container\" )\n .contents()\n .filter(function() {\n return this.nodeType === 3;\n })\n .wrap( \"&lt;p&gt;&lt;/p&gt;\" )\n .end()\n .filter( \"br\" )\n .remove();\n </code></pre>\n <p>This code first retrieves the contents of <code>&lt;div class=\"container\"&gt;</code> and then filters it for text nodes, which are wrapped in paragraph tags. This is accomplished by testing the <a href=\"https://developer.mozilla.org/docs/en/DOM/Node.nodeType\"><code>.nodeType</code> property</a> of the element. This DOM property holds a numeric code indicating the node's type; text nodes use the code 3. The contents are again filtered, this time for <code>&lt;br /&gt;</code> elements, and these elements are removed.</p>",
"examples": [{
"desc": "Find all the text nodes inside a paragraph and wrap them with a bold tag.",
"code": "$( \"p\" )\n .contents()\n .filter(function(){\n return this.nodeType !== 1;\n })\n .wrap( \"<b></b>\" );",
"html": "<p>Hello <a href=\"https://johnresig.com/\">John</a>, how are you doing?</p>",
"css": ""
},
{
"desc": "Change the background color of links inside of an iframe.",
"code": "$( \"#frameDemo\" ).contents().find( \"a\" ).css( \"background-color\", \"#BADA55\" );",
"html": "<iframe src=\"https://api.jquery.com/\" width=\"80%\" height=\"600\" id=\"frameDemo\"></iframe>",
"css": ""
}
],
"categories": [
"traversing/miscellaneous-traversal",
"version/1.2"
]
},
{
"title": ".context",
"type": "property",
"name": "context",
"return": "Element",
"deprecated": "1.10",
"removed": "3.0",
"signatures": [{
"arguments": [],
"added": "1.3"
}],
"desc": "The DOM node context originally passed to <code>jQuery()</code>; if none was passed then context will likely be the document.",
"longdesc": "<div class=\"warning\">\n <p>Note: This API has been removed in jQuery 3.0.</p>\n </div>\n <p>The <code>.live()</code> method for binding event handlers uses this property to determine the root element to use for its event delegation needs.</p>\n <p>The value of this property is typically equal to <code>document</code>, as this is the default context for jQuery objects if none is supplied. The context may differ if, for example, the object was created by searching within an <code>&lt;iframe&gt;</code> or XML document.</p>\n <p>Note that the context property may only apply to the elements originally selected by <code>jQuery()</code>, as it is possible for the user to add elements to the collection via methods such as <code>.add()</code> and these may have a different context.</p>",
"examples": [{
"desc": "Determine the exact context used.",
"code": "$( \"ul\" )\n .append( \"<li>\" + $( \"ul\" ).context + \"</li>\" )\n .append( \"<li>\" + $( \"ul\", document.body ).context.nodeName + \"</li>\" );",
"html": "",
"css": ""
}],
"categories": [
"internals",
"properties/jquery-object-instance-properties",
"version/1.3",
"deprecated/deprecated-1.10",
"removed"
]
},
{
"title": ".contextmenu()",
"type": "method",
"name": "contextmenu",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"contextmenu\" JavaScript event, or trigger that event on an element.",
"longdesc": "<p>This method is a shortcut for <code>.on( \"contextmenu\", handler )</code> in the first two variations, and <code>.trigger( \"contextmenu\" )</code> in the third.\n The <code>contextmenu</code> event is sent to an element when the right button of the mouse is clicked on it, but before the context menu is displayed. In case the context menu key is pressed, the event is triggered on the <code>html</code> element or the currently focused element. Any HTML element can receive this event.\n For example, consider the HTML:</p>\n <pre><code>\n&lt;div id=\"target\"&gt;\n Right-click here\n&lt;/div&gt;\n </code></pre>\n <p>The event handler can be bound to the <code>&lt;div&gt;</code> as follows:</p>\n <pre><code>\n$( \"#target\" ).contextmenu(function() {\n alert( \"Handler for .contextmenu() called.\" );\n});\n </code></pre>\n <p>Now right-clicking on this element displays the alert:</p>\n <p>\n <samp>Handler for .contextmenu() called.</samp>\n </p>\n <p>To trigger the event manually, call <code>.contextmenu()</code> without an argument:</p>\n <pre><code>\n$( \"#target\" ).contextmenu();\n </code></pre>",
"note": [{
"type": "additional",
"text": "As the <code>.contextmenu()</code> method is just a shorthand for <code>.on( \"contextmenu\", handler )</code>, detaching is possible using <code>.off( \"contextmenu\" )</code>."
}],
"examples": [{
"desc": "To show a \"Hello World!\" alert box when the contextmenu event is triggered on a paragraph on the page:",
"code": "$( \"p\" ).contextmenu(function() {\n alert( \"Hello World!\" );\n});",
"html": "",
"css": ""
},
{
"desc": "Right click to toggle background color.",
"code": "var div = $( \"div\" ).first();\ndiv.contextmenu(function() {\n div.toggleClass( \"contextmenu\" );\n});",
"html": "<div></div>\n<span>Right click the block</span>",
"css": "div {\n background: blue;\n color: white;\n height: 100px;\n width: 150px;\n }\n div.contextmenu {\n background: yellow;\n color: black;\n }"
}
],
"categories": [
"events/mouse-events",
"version/1.0",
"version/1.4.3"
]
},
{
"entries": [{
"title": ".css()",
"type": "method",
"name": "css",
"return": "String",
"signatures": [{
"arguments": [{
"name": "propertyName",
"type": "String",
"desc": "A CSS property."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "propertyNames",
"type": "Array",
"desc": "An array of one or more CSS properties."
}],
"added": "1.9"
}
],
"desc": "Get the computed style properties for the first element in the set of matched elements.",
"longdesc": "<p>The <code>.css()</code> method is a convenient way to get a computed style property from the first matched element, especially in light of the different ways browsers access most of those properties (the <code>getComputedStyle()</code> method in standards-based browsers versus the <code>currentStyle</code> and <code>runtimeStyle</code> properties in Internet Explorer prior to version 9) and the different terms browsers use for certain properties. For example, Internet Explorer's DOM implementation refers to the <code>float</code> property as <code>styleFloat</code>, while W3C standards-compliant browsers refer to it as <code>cssFloat</code>. For consistency, you can simply use <code>\"float\"</code>, and jQuery will translate it to the correct value for each browser.</p>\n <p>Also, jQuery can equally interpret the CSS and DOM formatting of multiple-word properties. For example, jQuery understands and returns the correct value for both <code>.css( \"background-color\" )</code> and <code>.css( \"backgroundColor\" )</code>. This means mixed case has a special meaning, <code>.css( \"WiDtH\" )</code> won't do the same as <code>.css( \"width\" )</code>, for example.</p>\n\t <p>Note that the <em>computed style</em> of an element may not be the same as the value specified for that element in a style sheet. For example, computed styles of dimensions are almost always pixels, but they can be specified as em, ex, px or % in a style sheet. Different browsers may return CSS color values that are logically but not textually equal, e.g., #FFF, #ffffff, and rgb(255,255,255).</p>\n <p>Retrieval of shorthand CSS properties (e.g., <code>margin</code>, <code>background</code>, <code>border</code>), although functional with some browsers, is not guaranteed. For example, if you want to retrieve the rendered <code>border-width</code>, use: <code>$( elem ).css( \"borderTopWidth\" )</code>, <code>$( elem ).css( \"borderBottomWidth\" )</code>, and so on.</p>\n <p>An element should be connected to the DOM when calling <code>.css()</code> on it. If it isn't, jQuery may throw an error.</p>\n <p><strong>As of jQuery 1.9</strong>, passing an array of style properties to <code>.css()</code> will result in an object of property-value pairs. For example, to retrieve all four rendered <code>border-width</code> values, you could use <code>$( elem ).css([ \"borderTopWidth\", \"borderRightWidth\", \"borderBottomWidth\", \"borderLeftWidth\" ])</code>. </p>",
"examples": [{
"desc": "Get the background color of a clicked div.",
"code": "$( \"div\" ).click(function() {\n var color = $( this ).css( \"background-color\" );\n $( \"#result\" ).html( \"That div is <span style='color:\" +\n color + \";'>\" + color + \"</span>.\" );\n});",
"html": "<span id=\"result\">&nbsp;</span>\n<div style=\"background-color:blue;\"></div>\n<div style=\"background-color:rgb(15,99,30);\"></div>\n<div style=\"background-color:#123456;\"></div>\n<div style=\"background-color:#f11;\"></div>",
"css": "div {\n width: 60px;\n height: 60px;\n margin: 5px;\n float: left;\n }"
},
{
"desc": "Get the width, height, text color, and background color of a clicked div.",
"code": "$( \"div\" ).click(function() {\n var html = [ \"The clicked div has the following styles:\" ];\n\n var styleProps = $( this ).css([\n \"width\", \"height\", \"color\", \"background-color\"\n ]);\n $.each( styleProps, function( prop, value ) {\n html.push( prop + \": \" + value );\n });\n\n $( \"#result\" ).html( html.join( \"<br>\" ) );\n});",
"html": "<p id=\"result\">&nbsp;</p>\n<div id=\"box1\">1</div>\n<div id=\"box2\">2</div>\n<div id=\"box3\">3</div>\n<div id=\"box4\">4</div>",
"css": "div {\n height: 50px;\n margin: 5px;\n padding: 5px;\n float: left;\n }\n #box1 {\n width: 50px;\n color: yellow;\n background-color: blue;\n }\n #box2 {\n width: 80px;\n color: rgb(255, 255, 255);\n background-color: rgb(15, 99, 30);\n }\n #box3 {\n width: 40px;\n color: #fcc;\n background-color: #123456;\n }\n #box4 {\n width: 70px;\n background-color: #f11;\n }"
}
],
"categories": [
"css",
"manipulation/style-properties",
"version/1.0",
"version/1.4",
"version/1.9"
]
},
{
"title": "",
"type": "method",
"name": "css",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "propertyName",
"type": "String",
"desc": "A CSS property name."
},
{
"name": "value",
"type": [
"String",
"Number"
],
"desc": "A value to set for the property."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "propertyName",
"type": "String",
"desc": "A CSS property name."
},
{
"name": "function",
"type": "Function",
"desc": "A function returning the value to set. <code>this</code> is the current element. Receives the index position of the element in the set and the old value as arguments.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "value",
"type": "String"
}
]
}
],
"added": "1.4"
},
{
"arguments": [{
"name": "properties",
"type": "PlainObject",
"desc": "An object of property-value pairs to set."
}],
"added": "1.0"
}
],
"desc": "Set one or more CSS properties for the set of matched elements.",
"longdesc": "<p>As with the <code>.prop()</code> method, the <code>.css()</code> method makes setting properties of elements quick and easy. This method can take either a property name and value as separate parameters, or a single object of key-value pairs.</p>\n <p>Also, jQuery can equally interpret the CSS and DOM formatting of multiple-word properties. For example, jQuery understands and returns the correct value for both <code>.css({ \"background-color\": \"#ffe\", \"border-left\": \"5px solid #ccc\" })</code> and <code>.css({backgroundColor: \"#ffe\", borderLeft: \"5px solid #ccc\" })</code>. Notice that with the DOM notation, quotation marks around the property names are optional, but with CSS notation they're required due to the hyphen in the name.</p>\n <p>When a number is passed as the value, jQuery will convert it to a string and add <code>px</code> to the end of that string. If the property requires units other than <code>px</code>, convert the value to a string and add the appropriate units before calling the method.</p>\n <p>When using <code>.css()</code> as a setter, jQuery modifies the element's <code>style</code> property. For example, <code>$( \"#mydiv\" ).css( \"color\", \"green\" )</code> is equivalent to <code>document.getElementById( \"mydiv\" ).style.color = \"green\"</code>. Setting the value of a style property to an empty string — e.g. <code>$( \"#mydiv\" ).css( \"color\", \"\" )</code> — removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's <code>.css()</code> method, or through direct DOM manipulation of the <code>style</code> property. As a consequence, the element's style for that property will be restored to whatever value was applied. So, this method can be used to cancel any style modification you have previously performed. It does not, however, remove a style that has been applied with a CSS rule in a stylesheet or <code>&lt;style&gt;</code> element. <strong>Warning:</strong> one notable exception is that, for IE 8 and below, removing a shorthand property such as <code>border</code> or <code>background</code> will remove that style entirely from the element, regardless of what is set in a stylesheet or <code>&lt;style&gt;</code> element.</p>\n <p><strong>Note:</strong> <code>.css()</code> ignores <code>!important</code> declarations. So, the statement <code>$( \"p\" ).css( \"color\", \"red !important\" )</code> does not turn the color of all paragraphs in the page to red. It's strongly advised to use classes instead; otherwise use a jQuery plugin.</p>\n <p>As of jQuery 1.8, the <code>.css()</code> setter will automatically take care of prefixing the property name. For example, take <code>.css( \"user-select\", \"none\" )</code> in Chrome/Safari will set it as <code>-webkit-user-select</code>, Firefox will use <code>-moz-user-select</code>, and IE10 will use <code>-ms-user-select</code>.</p>\n <p>As of jQuery 1.6, <code>.css()</code> accepts relative values similar to <code>.animate()</code>. Relative values are a string starting with <code>+=</code> or <code>-=</code> to increment or decrement the current value. For example, if an element's padding-left was 10px, <code>.css( \"padding-left\", \"+=15\" )</code> would result in a total padding-left of 25px.</p>\n <p>As of jQuery 1.4, <code>.css()</code> allows us to pass a function as the property value:</p>\n <pre><code>\n$( \"div.example\" ).css( \"width\", function( index ) {\n return index * 50;\n});\n </code></pre>\n <p>This example sets the widths of the matched elements to incrementally larger values.</p>\n <p><strong>Note: </strong>If nothing is returned in the setter function (ie. <code>function( index, style ){} )</code>, or if <code>undefined</code> is returned, the current value is not changed. This is useful for selectively setting values only when certain criteria are met.</p>",
"examples": [{
"desc": "Change the color of any paragraph to red on mouseover event.",
"code": "$( \"p\" ).on( \"mouseover\", function() {\n $( this ).css( \"color\", \"red\" );\n});",
"html": "<p>Just roll the mouse over me.</p>\n\n <p>Or me to see a color change.</p>",
"css": "p {\n color: blue;\n width: 200px;\n font-size: 14px;\n }"
},
{
"desc": "Increase the width of #box by 200 pixels the first time it is clicked.",
"code": "$( \"#box\" ).one( \"click\", function() {\n $( this ).css( \"width\", \"+=200\" );\n});",
"html": "<div id=\"box\">Click me to grow</div>",
"css": "#box {\n background: black;\n color: snow;\n width: 100px;\n padding: 10px;\n }"
},
{
"desc": "Highlight a clicked word in the paragraph.",
"code": "var words = $( \"p\" ).first().text().split( /\\s+/ );\nvar text = words.join( \"</span> <span>\" );\n$( \"p\" ).first().html( \"<span>\" + text + \"</span>\" );\n$( \"span\" ).on( \"click\", function() {\n $( this ).css( \"background-color\", \"yellow\" );\n});",
"html": "<p>\n Once upon a time there was a man\n who lived in a pizza parlor. This\n man just loved pizza and ate it all\n the time. He went on to be the\n happiest man in the world. The end.\n</p>",
"css": "p {\n color: blue;\n font-weight: bold;\n cursor: pointer;\n }"
},
{
"desc": "Change the font weight and background color on mouseenter and mouseleave.",
"code": "$( \"p\" )\n .on( \"mouseenter\", function() {\n $( this ).css({\n \"background-color\": \"yellow\",\n \"font-weight\": \"bolder\"\n });\n })\n .on( \"mouseleave\", function() {\n var styles = {\n backgroundColor : \"#ddd\",\n fontWeight: \"\"\n };\n $( this ).css( styles );\n });",
"html": "<p>Move the mouse over a paragraph.</p>\n<p>Like this one or the one above.</p>",
"css": "p {\n color: green;\n }"
},
{
"desc": "Increase the size of a div when you click it.",
"code": "$( \"div\" ).on( \"click\", function() {\n $( this ).css({\n width: function( index, value ) {\n return parseFloat( value ) * 1.2;\n },\n height: function( index, value ) {\n return parseFloat( value ) * 1.2;\n }\n });\n});",
"html": "<div>click</div>\n<div>click</div>",
"css": "div {\n width: 20px;\n height: 15px;\n background-color: #f33;\n }"
}
],
"categories": [
"css",
"manipulation/style-properties",
"version/1.0",
"version/1.4"
]
}
]
},
{
"entries": [{
"title": ".data()",
"type": "method",
"name": "data",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "key",
"type": "String",
"desc": "A string naming the piece of data to set."
},
{
"name": "value",
"type": "Anything",
"desc": "The new data value; this can be any Javascript type except <code>undefined</code>."
}
],
"added": "1.2.3"
},
{
"arguments": [{
"name": "obj",
"type": "Object",
"desc": "An object of key-value pairs of data to update."
}],
"added": "1.4.3"
}
],
"desc": "Store arbitrary data associated with the matched elements.",
"longdesc": "<p>The <code>.data()</code> method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore from memory leaks.</p>\n <p>We can set several distinct values for a single element and retrieve them later:</p>\n <pre><code>\n$( \"body\" ).data( \"foo\", 52 );\n$( \"body\" ).data( \"bar\", { isManual: true } );\n$( \"body\" ).data( { baz: [ 1, 2, 3 ] } );\n$( \"body\" ).data( \"foo\" ); // 52\n$( \"body\" ).data(); // { foo: 52, bar: { isManual: true }, baz: [ 1, 2, 3 ] }\n </code></pre>\n <p>Using the <code>data()</code> method to update data does not affect attributes in the DOM. To set a <code>data-*</code> attribute value, use <code><a href=\"/attr/\">attr</a></code>.</p>\n <p>Prior to jQuery 1.4.3, <code>.data( obj )</code> completely replaced all data. Since jQuery 1.4.3, data is instead extended by shallow merge.</p>\n <p>Since <strong>jQuery 3</strong>, every two-character sequence of \"-\" (U+002D) followed by a lowercase ASCII letter in a key is replaced by the uppercase version of the letter, in alignment with the <a href=\"https://html.spec.whatwg.org/multipage/dom.html#dom-dataset\">HTML dataset API</a>. A statement like <code>$( \"body\" ).data( { \"my-name\": \"aValue\" } ).data();</code> will return <code>{ myName: \"aValue\" }</code>.</p>\n <p>Due to the way browsers interact with plugins and external code, the <code>.data()</code> method cannot be used on <code>&lt;object&gt;</code> (unless it's a Flash plugin), <code>&lt;applet&gt;</code> or <code>&lt;embed&gt;</code> elements.</p>",
"note": [{
"type": "additional",
"text": "Note that this method currently does not provide cross-platform support for setting data on XML documents, as Internet Explorer does not allow data to be attached via expando properties."
},
{
"type": "additional",
"text": "<code>undefined</code> is not recognized as a data value. Calls such as <code>.data( \"name\", undefined )</code> will return the corresponding data for \"name\", and is therefore the same as <code>.data( \"name\" )</code>."
}
],
"examples": [{
"desc": "Store then retrieve a value from the div element.",
"code": "$( \"div\" ).data( \"test\", { first: 16, last: \"pizza!\" } );\n$( \"span\" ).first().text( $( \"div\" ).data( \"test\" ).first );\n$( \"span\" ).last().text( $( \"div\" ).data( \"test\" ).last );",
"html": "<div>\n The values stored were\n <span></span>\n and\n <span></span>\n</div>",
"css": "div {\n color: blue;\n }\n span {\n color: red;\n }"
}],
"categories": [
"data",
"miscellaneous/data-storage",
"version/1.2.3",
"version/1.4",
"version/1.4.3"
]
},
{
"title": "",
"type": "method",
"name": "data",
"return": "Object",
"signatures": [{
"arguments": [{
"name": "key",
"type": "String",
"desc": "Name of the data stored."
}],
"added": "1.2.3"
},
{
"arguments": [],
"added": "1.4"
}
],
"desc": "Return arbitrary data associated with the first element in the jQuery collection, as set by data() or by an HTML5 <code>data-*</code> attribute.",
"longdesc": "<p>The <code>.data()</code> method allows us to read data previously associated with DOM elements. We can retrieve several distinct values for a single element one at a time, or as a set:</p>\n <pre><code>\nvar elem = document.createElement( \"span\" );\n$( elem ).data( \"foo\" ); // undefined\n$( elem ).data(); // {}\n\n$( elem ).data( \"foo\", 42 );\n$( elem ).data( \"foo\" ); // 42\n$( elem ).data(); // { foo: 42 }\n </code></pre>\n <p>Calling <code>.data()</code> with no parameters returns a JavaScript object containing each stored value as a property. The object can be used directly to get data values (but note that property names originally containing dashes will have been modified as described below).</p>\n <p>Since <strong>jQuery 3</strong>, every two-character sequence of \"-\" (U+002D) followed by a lowercase ASCII letter in a key is replaced by the uppercase version of the letter, in alignment with the <a href=\"https://html.spec.whatwg.org/multipage/dom.html#dom-dataset\">HTML dataset API</a>. A statement like <code>$( \"body\" ).data( { \"my-name\": \"aValue\" } ).data();</code> will return <code>{ myName: \"aValue\" }</code>.</p>\n <h4 id=\"data-html5\">\n <a href=\"#data-html5\">HTML5 <code>data-*</code> Attributes</a>\n </h4>\n <p>Since jQuery 1.4.3, <a href=\"https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes\"><code>data-*</code> attributes</a> are used to initialize jQuery data. An element's <code>data-*</code> attributes are retrieved the first time the <code>data()</code> method is invoked upon it, and then are no longer accessed or mutated (all values are stored internally by jQuery).</p>\n <p>Every attempt is made to convert the attribute's string value to a JavaScript value (this includes booleans, numbers, objects, arrays, and null). A string is only converted to a number if doing so doesn't change its representation (for example, the string \"100\" is converted to the number 100, but \"1E02\" and \"100.000\" are left as strings because their numeric value of 100 serializes to \"100\"). When a string starts with '{' or '[', then <code>jQuery.parseJSON</code> is used to parse it; it must follow <a href=\"https://en.wikipedia.org/wiki/JSON#Data_types.2C_syntax_and_example\">valid JSON syntax</a> <em>including quoted property names</em>. A string not parseable as a JavaScript value is not converted.</p>\n <p>To retrieve a <code>data-*</code> attribute value as an unconverted string, use the <code><a href=\"/attr/\">attr()</a></code> method.</p>\n <p>Since jQuery 1.6, dashes in <code>data-*</code> attribute names have been processed in alignment with the <a href=\"https://html.spec.whatwg.org/multipage/dom.html#dom-dataset\">HTML dataset API</a>.</p>\n <p>For example, given the following HTML:</p>\n <pre><code>&lt;div data-role=\"page\" data-last-value=\"43\" data-hidden=\"true\" data-options='{\"name\":\"John\"}'&gt;&lt;/div&gt;</code></pre>\n <p>The following comparisons are all true:</p>\n <pre><code>\n$( \"div\" ).data( \"role\" ) === \"page\";\n$( \"div\" ).data( \"lastValue\" ) === 43;\n$( \"div\" ).data( \"hidden\" ) === true;\n$( \"div\" ).data( \"options\" ).name === \"John\";\n </code></pre>",
"note": [{
"type": "additional",
"text": "Note that this method currently does not provide cross-platform support for setting data on XML documents, as Internet Explorer does not allow data to be attached via expando properties."
}],
"examples": [{
"desc": "Get the data named \"blah\" stored at for an element.",
"code": "$( \"button\" ).click(function() {\n var value;\n\n switch ( $( \"button\" ).index( this ) ) {\n case 0 :\n value = $( \"div\" ).data( \"blah\" );\n break;\n case 1 :\n $( \"div\" ).data( \"blah\", \"hello\" );\n value = \"Stored!\";\n break;\n case 2 :\n $( \"div\" ).data( \"blah\", 86 );\n value = \"Stored!\";\n break;\n case 3 :\n $( \"div\" ).removeData( \"blah\" );\n value = \"Removed!\";\n break;\n }\n\n $( \"span\" ).text( \"\" + value );\n});",
"html": "<div>A div</div>\n<button>Get \"blah\" from the div</button>\n<button>Set \"blah\" to \"hello\"</button>\n<button>Set \"blah\" to 86</button>\n<button>Remove \"blah\" from the div</button>\n<p>The \"blah\" value of this div is <span>?</span></p>",
"css": "div {\n margin: 5px;\n background: yellow;\n }\n button {\n margin: 5px;\n font-size: 14px;\n }\n p {\n margin: 5px;\n color: blue;\n }\n span {\n color: red;\n }"
}],
"categories": [
"data",
"miscellaneous/data-storage",
"version/1.2.3",
"version/1.4",
"version/1.4.3"
]
}
]
},
{
"title": ".dblclick()",
"type": "method",
"name": "dblclick",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"dblclick\" JavaScript event, or trigger that event on an element.",
"longdesc": "<p>This method is a shortcut for <code>.on( \"dblclick\", handler )</code> in the first two variations, and <code>.trigger( \"dblclick\" )</code> in the third.\n The <code>dblclick</code> event is sent to an element when the element is double-clicked. Any HTML element can receive this event.\n For example, consider the HTML:</p>\n <pre><code>\n&lt;div id=\"target\"&gt;\n Double-click here\n&lt;/div&gt;\n&lt;div id=\"other\"&gt;\n Trigger the handler\n&lt;/div&gt;\n </code></pre>\n <figure>\n <img src=\"/resources/0042_05_04.png\" alt=\"\"/>\n <figcaption>Figure 1 - Illustration of the rendered HTML</figcaption>\n </figure>\n <p>The event handler can be bound to any <code>&lt;div&gt;</code>:</p>\n <pre><code>\n$( \"#target\" ).dblclick(function() {\n alert( \"Handler for .dblclick() called.\" );\n});\n </code></pre>\n <p>Now double-clicking on this element displays the alert:</p>\n <p>\n <samp>Handler for .dblclick() called.</samp>\n </p>\n <p>To trigger the event manually, call <code>.dblclick()</code> without an argument:</p>\n <pre><code>\n$( \"#other\" ).click(function() {\n $( \"#target\" ).dblclick();\n});\n </code></pre>\n <p>After this code executes, (single) clicks on <samp>Trigger the handler</samp> will also alert the message.</p>\n <p>The <code>dblclick</code> event is only triggered after this exact series of events:</p>\n <ul>\n <li>The mouse button is depressed while the pointer is inside the element.</li>\n <li>The mouse button is released while the pointer is inside the element.</li>\n <li>The mouse button is depressed again while the pointer is inside the element, within a time window that is system-dependent.</li>\n <li>The mouse button is released while the pointer is inside the element.</li>\n </ul>\n <p>It is inadvisable to bind handlers to both the <code>click</code> and <code>dblclick</code> events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two <code>click</code> events before the <code>dblclick</code> and others only one. Double-click sensitivity (maximum time between clicks that is detected as a double click) can vary by operating system and browser, and is often user-configurable.\n </p>",
"note": [{
"type": "additional",
"text": "As the <code>.dblclick()</code> method is just a shorthand for <code>.on( \"dblclick\", handler )</code>, detaching is possible using <code>.off( \"dblclick\" )</code>."
}],
"examples": [{
"desc": "To bind a \"Hello World!\" alert box to the dblclick event on every paragraph on the page:",
"code": "$( \"p\" ).dblclick(function() {\n alert( \"Hello World!\" );\n});",
"html": "",
"css": ""
},
{
"desc": "Double click to toggle background color.",
"code": "var divdbl = $( \"div\" ).first();\ndivdbl.dblclick(function() {\n divdbl.toggleClass( \"dbl\" );\n});",
"html": "<div></div>\n<span>Double click the block</span>",
"css": "div {\n background: blue;\n color: white;\n height: 100px;\n width: 150px;\n }\n div.dbl {\n background: yellow;\n color: black;\n }"
}
],
"categories": [
"events/mouse-events",
"version/1.0",
"version/1.4.3"
]
},
{
"title": "deferred.always()",
"name": "deferred.always",
"type": "method",
"return": "Deferred",
"signatures": [{
"arguments": [{
"name": "alwaysCallbacks",
"type": "Function",
"desc": "A function, or array of functions, that is called when the Deferred is resolved or rejected."
},
{
"name": "alwaysCallbacks",
"type": "Function",
"optional": "true",
"desc": "Optional additional functions, or arrays of functions, that are called when the Deferred is resolved or rejected."
}
],
"added": "1.6"
}],
"desc": "Add handlers to be called when the Deferred object is either resolved or rejected.",
"longdesc": "<p>The argument can be either a single function or an array of functions. When the Deferred is resolved or rejected, the <code>alwaysCallbacks</code> are called. Since <code>deferred.always()</code> returns the Deferred object, other methods of the Deferred object can be chained to this one, including additional <code>.always()</code> methods. When the Deferred is resolved or rejected, callbacks are executed in the order they were added, using the arguments provided to the <a href=\"/deferred.resolve/\"><code>resolve</code></a>, <a href=\"/deferred.reject/\"><code>reject</code></a>, <a href=\"/deferred.resolveWith/\"><code>resolveWith</code></a> or <a href=\"/deferred.rejectWith/\"><code>rejectWith</code></a> method calls. For more information, see the documentation for <a href=\"/category/deferred-object/\">Deferred object</a>.</p>\n <p><strong>Note:</strong> The <code>deferred.always()</code> method receives the arguments that were used to <code>.resolve()</code> or <code>.reject()</code> the <code>Deferred</code> object, which are often very different. For this reason, it's best to use it only for actions that do not require inspecting the arguments. In all other cases, use explicit <a href=\"/deferred.done/\"><code>.done()</code></a> or <a href=\"/deferred.fail/\"><code>.fail()</code></a> handlers since the arguments will have well-known orders.</p>",
"examples": [{
"desc": "Since the <a href=\"/jQuery.get/\"><code>jQuery.get()</code></a> method returns a <code>jqXHR</code> object, which is derived from a Deferred object, we can attach a callback for both success and error using the <code>deferred.always()</code> method.",
"code": "$.get( \"test.php\" ).always(function() {\n alert( \"$.get completed with success or error callback arguments\" );\n});",
"html": "",
"css": ""
}],
"categories": [
"deferred-object",
"version/1.6"
]
},
{
"title": "deferred.catch()",
"name": "deferred.catch",
"type": "method",
"return": "Promise",
"signatures": [{
"arguments": [{
"name": "failFilter",
"type": "Function",
"desc": "A function that is called when the Deferred is rejected."
}],
"added": "3.0"
}],
"desc": "Add handlers to be called when the Deferred object is rejected.",
"longdesc": "<p><code>deferred.catch( fn )</code> is an alias to <a href=\"/deferred.then/\"><code>deferred.then( null, fn )</code></a>. Read its page for more information.</p>",
"examples": [{
"desc": "Since the <a href=\"/jQuery.get/\"><code>jQuery.get</code></a> method returns a jqXHR object, which is derived from a Deferred object, we can add rejection handlers using the <code>.catch</code> method.",
"code": "$.get( \"test.php\" )\n .then( function() {\n alert( \"$.get succeeded\" );\n } )\n .catch( function() {\n alert( \"$.get failed!\" );\n } );",
"html": "",
"css": ""
}],
"categories": [
"deferred-object",
"version/3.0"
]
},
{
"title": "deferred.done()",
"name": "deferred.done",
"type": "method",
"return": "Deferred",
"signatures": [{
"arguments": [{
"name": "doneCallbacks",
"type": "Function",
"desc": "A function, or array of functions, that are called when the Deferred is resolved."
},
{
"name": "doneCallbacks",
"type": "Function",
"optional": "true",
"desc": "Optional additional functions, or arrays of functions, that are called when the Deferred is resolved."
}
],
"added": "1.5"
}],
"desc": "Add handlers to be called when the Deferred object is resolved.",
"longdesc": "<p>The <code>deferred.done()</code> method accepts one or more arguments, all of which can be either a single function or an array of functions. When the Deferred is resolved, the doneCallbacks are called. Callbacks are executed in the order they were added. Since <code>deferred.done()</code> returns the deferred object, other methods of the deferred object can be chained to this one, including additional <code>.done()</code> methods. When the Deferred is resolved, doneCallbacks are executed using the arguments provided to the <a href=\"/deferred.resolve/\"><code>resolve</code></a> or <a href=\"/deferred.resolveWith/\"><code>resolveWith</code></a> method call in the order they were added. For more information, see the documentation for <a href=\"/category/deferred-object/\">Deferred object</a>.</p>",
"examples": [{
"desc": "Since the <a href=\"/jQuery.get/\"><code>jQuery.get</code></a> method returns a jqXHR object, which is derived from a Deferred object, we can attach a success callback using the <code>.done()</code> method.",
"code": "$.get( \"test.php\" ).done(function() {\n alert( \"$.get succeeded\" );\n});",
"html": "",
"css": ""
},
{
"desc": "Resolve a Deferred object when the user clicks a button, triggering a number of callback functions:",
"code": "// 3 functions to call when the Deferred object is resolved\nfunction fn1() {\n $( \"p\" ).append( \" 1 \" );\n}\nfunction fn2() {\n $( \"p\" ).append( \" 2 \" );\n}\nfunction fn3( n ) {\n $( \"p\" ).append( n + \" 3 \" + n );\n}\n\n// Create a deferred object\nvar dfd = $.Deferred();\n\n// Add handlers to be called when dfd is resolved\ndfd\n// .done() can take any number of functions or arrays of functions\n .done( [ fn1, fn2 ], fn3, [ fn2, fn1 ] )\n// We can chain done methods, too\n .done(function( n ) {\n $( \"p\" ).append( n + \" we're done.\" );\n });\n\n// Resolve the Deferred object when the button is clicked\n$( \"button\" ).on( \"click\", function() {\n dfd.resolve( \"and\" );\n});",
"html": "<button>Go</button>\n<p>Ready...</p>",
"css": ""
}
],
"categories": [
"deferred-object",
"version/1.5"
]
},
{
"title": "deferred.fail()",
"name": "deferred.fail",
"type": "method",
"return": "Deferred",
"signatures": [{
"arguments": [{
"name": "failCallbacks",
"type": "Function",
"desc": "A function, or array of functions, that are called when the Deferred is rejected."
},
{
"name": "failCallbacks",
"type": "Function",
"optional": "true",
"desc": "Optional additional functions, or arrays of functions, that are called when the Deferred is rejected."
}
],
"added": "1.5"
}],
"desc": "Add handlers to be called when the Deferred object is rejected.",
"longdesc": "<p>The <code>deferred.fail()</code> method accepts one or more arguments, all of which can be either a single function or an array of functions. When the Deferred is rejected, the failCallbacks are called. Callbacks are executed in the order they were added. Since <code>deferred.fail()</code> returns the deferred object, other methods of the deferred object can be chained to this one, including additional <code>deferred.fail()</code> methods. The failCallbacks are executed using the arguments provided to the <a href=\"/deferred.reject/\"><code>deferred.reject()</code></a> or <a href=\"/deferred.rejectWith/\"><code>deferred.rejectWith()</code></a> method call in the order they were added. For more information, see the documentation for <a href=\"/category/deferred-object/\">Deferred object</a>.</p>",
"examples": [{
"desc": "Since the <a href=\"/jQuery.get/\"><code>jQuery.get</code></a> method returns a jqXHR object, which is derived from a Deferred, you can attach a success and failure callback using the <code>deferred.done()</code> and <code>deferred.fail()</code> methods.",
"code": "$.get( \"test.php\" )\n .done(function() {\n alert( \"$.get succeeded\" );\n })\n .fail(function() {\n alert( \"$.get failed!\" );\n });",
"html": "",
"css": ""
}],
"categories": [
"deferred-object",
"version/1.5"
]
},
{
"title": "deferred.isRejected()",
"name": "deferred.isRejected",
"type": "method",
"return": "Boolean",
"deprecated": "1.7",
"removed": "1.8",
"signatures": [{
"arguments": [],
"added": "1.5"
}],
"desc": "Determine whether a Deferred object has been rejected.",
"longdesc": "<div class=\"warning\">\n <p>Note: This API has been removed in jQuery 1.8; please use <a href=\"/deferred.state/\"><code>deferred.state()</code></a> instead.</p>\n </div>\n <p>Returns <code>true</code> if the Deferred object is in the rejected state, meaning that either <a href=\"h/deferred.reject/\"><code>deferred.reject()</code></a> or <a href=\"/deferred.rejectWith/\"><code>deferred.rejectWith()</code></a> has been called for the object and the failCallbacks have been called (or are in the process of being called).</p>\n <p>Note that a Deferred object can be in one of three states: pending, resolved, or rejected; use <a href=\"/deferred.isResolved/\"><code>deferred.isResolved()</code></a> to determine whether the Deferred object is in the resolved state. These methods are primarily useful for debugging, for example to determine whether a Deferred has already been resolved even though you are inside code that intended to reject it.</p>",
"examples": [],
"categories": [
"deferred-object",
"version/1.5",
"deprecated/deprecated-1.7",
"removed"
]
},
{
"title": "deferred.isResolved()",
"name": "deferred.isResolved",
"type": "method",
"return": "Boolean",
"deprecated": "1.7",
"removed": "1.8",
"signatures": [{
"arguments": [],
"added": "1.5"
}],
"desc": "Determine whether a Deferred object has been resolved.",
"longdesc": "<div class=\"warning\">\n <p>Note: This API has been removed in jQuery 1.8; please use <a href=\"/deferred.state/\"><code>deferred.state()</code></a> instead.</p>\n </div>\n <p>Returns <code>true</code> if the Deferred object is in the resolved state, meaning that either <a href=\"/deferred.resolve/\"><code>deferred.resolve()</code></a> or <a href=\"/deferred.resolveWith/\"><code>deferred.resolveWith()</code></a> has been called for the object and the doneCallbacks have been called (or are in the process of being called).</p>\n <p>Note that a Deferred object can be in one of three states: pending, resolved, or rejected; use <a href=\"/deferred.isRejected/\"><code>deferred.isRejected()</code></a> to determine whether the Deferred object is in the rejected state. These methods are primarily useful for debugging, for example to determine whether a Deferred has already been resolved even though you are inside code that intended to reject it.</p>",
"examples": [],
"categories": [
"deferred-object",
"version/1.5",
"deprecated/deprecated-1.7",
"removed"
]
},
{
"title": "deferred.notify()",
"name": "deferred.notify",
"type": "method",
"return": "Deferred",
"signatures": [{
"arguments": [{
"name": "args",
"type": "Object",
"desc": "Optional arguments that are passed to the progressCallbacks."
}],
"added": "1.7"
}],
"desc": "Call the progressCallbacks on a Deferred object with the given <code>args</code>.",
"longdesc": "<p>Normally, only the creator of a Deferred should call this method; you can prevent other code from changing the Deferred's state or reporting status by returning a restricted Promise object through deferred.promise().</p>\n <p>When <code>deferred.notify</code> is called, any progressCallbacks added by <a href=\"/deferred.then/\"><code>deferred.then</code></a> or <a href=\"/deferred.progress/\"><code>deferred.progress</code></a> are called. Callbacks are executed in the order they were added. Each callback is passed the <code>args</code> from the <code>.notify()</code>. Any calls to <code>.notify()</code> after a Deferred is resolved or rejected (or any progressCallbacks added after that) are ignored. For more information, see the documentation for <a href=\"/category/deferred-object/\">Deferred object</a>.</p>",
"examples": [],
"categories": [
"deferred-object",
"version/1.7"
]
},
{
"title": "deferred.notifyWith()",
"name": "deferred.notifyWith",
"type": "method",
"return": "Deferred",
"signatures": [{
"arguments": [{
"name": "context",
"type": "Object",
"desc": "Context passed to the progressCallbacks as the <code>this</code> object."
},
{
"name": "args",
"type": "Array",
"optional": "true",
"desc": "An optional array of arguments that are passed to the progressCallbacks."
}
],
"added": "1.7"
}],
"desc": "Call the progressCallbacks on a Deferred object with the given context and <code>args</code>.",
"longdesc": "<p>Normally, only the creator of a Deferred should call this method; you can prevent other code from changing the Deferred's state or reporting status by returning a restricted Promise object through deferred.promise().</p>\n <p>When <code>deferred.notifyWith</code> is called, any progressCallbacks added by <a href=\"/deferred.then/\"><code>deferred.then</code></a> or <a href=\"/deferred.progress/\"><code>deferred.progress</code></a> are called. Callbacks are executed in the order they were added. Each callback is passed the <code>args</code> from the <code>.notifyWith()</code>. Any calls to <code>.notifyWith()</code> after a Deferred is resolved or rejected (or any progressCallbacks added after that) are ignored. For more information, see the documentation for <a href=\"/category/deferred-object/\">Deferred object</a>.</p>",
"examples": [],
"categories": [
"deferred-object",
"version/1.7"
]
},
{
"title": "deferred.pipe()",
"name": "deferred.pipe",
"type": "method",
"return": "Promise",
"deprecated": "1.8",
"signatures": [{
"arguments": [{
"name": "doneFilter",
"type": "Function",
"optional": "true",
"desc": "An optional function that is called when the Deferred is resolved."
},
{
"name": "failFilter",
"type": "Function",
"optional": "true",
"desc": "An optional function that is called when the Deferred is rejected."
}
],
"added": "1.6"
},
{
"arguments": [{
"name": "doneFilter",
"type": "Function",
"optional": "true",
"desc": "An optional function that is called when the Deferred is resolved."
},
{
"name": "failFilter",
"type": "Function",
"optional": "true",
"desc": "An optional function that is called when the Deferred is rejected."
},
{
"name": "progressFilter",
"type": "Function",
"optional": "true",
"desc": "An optional function that is called when progress notifications are sent to the Deferred."
}
],
"added": "1.7"
}
],
"desc": "Utility method to filter and/or chain Deferreds.",
"longdesc": "<p><strong>Deprecation Notice:</strong>As of jQuery 1.8, the deferred.pipe() method is deprecated. The <code>deferred.then()</code> method, which replaces it, should be used instead.</p>\n <p>The <code>deferred.pipe()</code> method returns a new promise that filters the status and values of a deferred through a function. The <code>doneFilter</code> and <code>failFilter</code> functions filter the original deferred's resolved / rejected status and values. <strong>As of jQuery 1.7</strong>, the method also accepts a <code>progressFilter</code> function to filter any calls to the original deferred's <code>notify</code> or <code>notifyWith</code> methods. These filter functions can return a new value to be passed along to the piped promise's <code>done()</code> or <code>fail()</code> callbacks, or they can return another observable object (Deferred, Promise, etc) which will pass its resolved / rejected status and values to the piped promise's callbacks. If the filter function used is <code>null</code>, or not specified, the piped promise will be resolved or rejected with the same values as the original.</p>",
"examples": [{
"desc": "Filter resolve value:",
"code": "var defer = $.Deferred(),\n filtered = defer.pipe(function( value ) {\n return value * 2;\n });\n\ndefer.resolve( 5 );\nfiltered.done(function( value ) {\n alert( \"Value is ( 2*5 = ) 10: \" + value );\n});",
"html": "",
"css": ""
},
{
"desc": "Filter reject value:",
"code": "var defer = $.Deferred(),\n filtered = defer.pipe( null, function( value ) {\n return value * 3;\n });\n\ndefer.reject( 6 );\nfiltered.fail(function( value ) {\n alert( \"Value is ( 3*6 = ) 18: \" + value );\n});",
"html": "",
"css": ""
},
{
"desc": "Chain tasks:",
"code": "var request = $.ajax( url, { dataType: \"json\" } ),\n chained = request.pipe(function( data ) {\n return $.ajax( url2, { data: { user: data.userId } } );\n });\n\nchained.done(function( data ) {\n // data retrieved from url2 as provided by the first request\n});",
"html": "",
"css": ""
}
],
"categories": [
"deferred-object",
"version/1.6",
"version/1.7",
"version/1.8",
"deprecated/deprecated-1.8"
]
},
{
"title": "deferred.progress()",
"name": "deferred.progress",
"type": "method",
"return": "Deferred",
"signatures": [{
"arguments": [{
"name": "progressCallbacks",
"type": [
"Function",
"Array"
],
"desc": "A function, or array of functions, to be called when the Deferred generates progress notifications."
},
{
"name": "progressCallbacks",
"optional": "true",
"type": [
"Function",
"Array"
],
"desc": "Optional additional functions, or arrays of functions, to be called when the Deferred generates progress notifications."
}
],
"added": "1.7"
}],
"desc": "Add handlers to be called when the Deferred object generates progress notifications.",
"longdesc": "<p>The <code>deferred.progress()</code> method accepts one or more arguments, all of which can be either a single function or an array of functions. When the Deferred generates progress notifications by calling <code>notify</code> or <code>notifyWith</code>, the <code>progressCallbacks</code> are called. Since <code>deferred.progress()</code> returns the Deferred object, other methods of the Deferred object can be chained to this one. When the Deferred is resolved or rejected, progress callbacks will no longer be called, with the exception that any <code>progressCallbacks</code> added after the Deferred enters the resolved or rejected state are executed immediately when they are added, using the arguments that were passed to the <code>.notify()</code> or <code>notifyWith()</code> call. For more information, see the documentation for <a href=\"/jQuery.Deferred/\">jQuery.Deferred()</a>.</p>",
"examples": [],
"categories": [
"deferred-object",
"version/1.7"
]
},
{
"title": "deferred.promise()",
"name": "deferred.promise",
"type": "method",
"return": "Promise",
"signatures": [{
"arguments": [{
"name": "target",
"type": "Object",
"optional": "true",
"desc": "Object onto which the promise methods have to be attached"
}],
"added": "1.5"
}],
"desc": "Return a Deferred's Promise object.",
"longdesc": "<p>The <code>deferred.promise()</code> method allows an asynchronous function to prevent other code from interfering with the progress or status of its internal request. The Promise exposes only the Deferred methods needed to attach additional handlers or determine the state (<code>then</code>, <code>done</code>, <code>fail</code>, <code>always</code>, <code>pipe</code>, <code>progress</code>, <code>state</code> and <code>promise</code>), but not ones that change the state (<code>resolve</code>, <code>reject</code>, <code>notify</code>, <code>resolveWith</code>, <code>rejectWith</code>, and <code>notifyWith</code>).</p>\n <p>If <code>target</code> is provided, <code>deferred.promise()</code> will attach the methods onto it and then return this object rather than create a new one. This can be useful to attach the Promise behavior to an object that already exists.</p>\n <p>If you are creating a Deferred, keep a reference to the Deferred so that it can be resolved or rejected at some point. Return <em>only</em> the Promise object via <code>deferred.promise()</code> so other code can register callbacks or inspect the current state.</p>\n <p>For more information, see the documentation for <a href=\"/category/deferred-object/\">Deferred object</a>.</p>",
"examples": [{
"desc": "Create a Deferred and set two timer-based functions to either resolve or reject the Deferred after a random interval. Whichever one fires first \"wins\" and will call one of the callbacks. The second timeout has no effect since the Deferred is already complete (in a resolved or rejected state) from the first timeout action. Also set a timer-based progress notification function, and call a progress handler that adds \"working...\" to the document body.",
"code": "function asyncEvent() {\n var dfd = jQuery.Deferred();\n\n // Resolve after a random interval\n setTimeout(function() {\n dfd.resolve( \"hurray\" );\n }, Math.floor( 400 + Math.random() * 2000 ) );\n\n // Reject after a random interval\n setTimeout(function() {\n dfd.reject( \"sorry\" );\n }, Math.floor( 400 + Math.random() * 2000 ) );\n\n // Show a \"working...\" message every half-second\n setTimeout(function working() {\n if ( dfd.state() === \"pending\" ) {\n dfd.notify( \"working... \" );\n setTimeout( working, 500 );\n }\n }, 1 );\n\n // Return the Promise so caller can't change the Deferred\n return dfd.promise();\n}\n\n// Attach a done, fail, and progress handler for the asyncEvent\n$.when( asyncEvent() ).then(\n function( status ) {\n alert( status + \", things are going well\" );\n },\n function( status ) {\n alert( status + \", you fail this time\" );\n },\n function( status ) {\n $( \"body\" ).append( status );\n }\n);",
"html": "",
"css": ""
},
{
"desc": "Use the target argument to promote an existing object to a Promise:",
"code": "// Existing object\nvar obj = {\n hello: function( name ) {\n alert( \"Hello \" + name );\n }\n },\n // Create a Deferred\n defer = $.Deferred();\n\n// Set object as a promise\ndefer.promise( obj );\n\n// Resolve the deferred\ndefer.resolve( \"John\" );\n\n// Use the object as a Promise\nobj.done(function( name ) {\n obj.hello( name ); // Will alert \"Hello John\"\n}).hello( \"Karl\" ); // Will alert \"Hello Karl\"",
"html": "",
"css": ""
}
],
"categories": [
"deferred-object",
"version/1.5"
]
},
{
"title": "deferred.reject()",
"name": "deferred.reject",
"type": "method",
"return": "Deferred",
"signatures": [{
"arguments": [{
"name": "args",
"type": "Anything",
"optional": "true",
"desc": "Optional arguments that are passed to the failCallbacks."
}],
"added": "1.5"
}],
"desc": "Reject a Deferred object and call any failCallbacks with the given <code>args</code>.",
"longdesc": "<p>Normally, only the creator of a Deferred should call this method; you can prevent other code from changing the Deferred's state by returning a restricted Promise object through <a href=\"/deferred.promise/\"><code>deferred.promise()</code></a>.</p>\n <p>When the Deferred is rejected, any failCallbacks added by <a href=\"/deferred.then/\"><code>deferred.then()</code></a> or <a href=\"/deferred.fail/\"><code>deferred.fail()</code></a> are called. Callbacks are executed in the order they were added. Each callback is passed the <code>args</code> from the <code>deferred.reject()</code> call. Any failCallbacks added after the Deferred enters the rejected state are executed immediately when they are added, using the arguments that were passed to the <code>deferred.reject()</code> call. For more information, see the documentation for <a href=\"/jQuery.Deferred/\">jQuery.Deferred()</a>.</p>",
"examples": [],
"categories": [
"deferred-object",
"version/1.5"
]
},
{
"title": "deferred.rejectWith()",
"name": "deferred.rejectWith",
"type": "method",
"return": "Deferred",
"signatures": [{
"arguments": [{
"name": "context",
"type": "Object",
"desc": "Context passed to the failCallbacks as the <code>this</code> object."
},
{
"name": "args",
"type": "Array",
"optional": "true",
"desc": "An optional array of arguments that are passed to the failCallbacks."
}
],
"added": "1.5"
}],
"desc": "Reject a Deferred object and call any failCallbacks with the given <code>context</code> and <code>args</code>.",
"longdesc": "<p>Normally, only the creator of a Deferred should call this method; you can prevent other code from changing the Deferred's state by returning a restricted Promise object through <a href=\"/deferred.promise/\"><code>deferred.promise()</code></a>.</p>\n <p>When the Deferred is rejected, any failCallbacks added by <a href=\"/deferred.then/\"><code>deferred.then</code></a> or <a href=\"/deferred.fail/\"><code>deferred.fail</code></a> are called. Callbacks are executed in the order they were added. Each callback is passed the <code>args</code> from the <code>deferred.reject()</code> call. Any failCallbacks added after the Deferred enters the rejected state are executed immediately when they are added, using the arguments that were passed to the <code>.reject()</code> call. For more information, see the documentation for <a href=\"/category/deferred-object/\">Deferred object</a>.</p>",
"examples": [],
"categories": [
"deferred-object",
"version/1.5"
]
},
{
"title": "deferred.resolve()",
"name": "deferred.resolve",
"type": "method",
"return": "Deferred",
"signatures": [{
"arguments": [{
"name": "args",
"type": "Anything",
"optional": "true",
"desc": "Optional arguments that are passed to the doneCallbacks."
}],
"added": "1.5"
}],
"desc": "Resolve a Deferred object and call any doneCallbacks with the given <code>args</code>.",
"longdesc": "<p>Normally, only the creator of a Deferred should call this method; you can prevent other code from changing the Deferred's state by returning a restricted Promise object through <a href=\"/deferred.promise/\"><code>deferred.promise()</code></a>.</p>\n <p>When the Deferred is resolved, any doneCallbacks added by <a href=\"/deferred.then/\"><code>deferred.then()</code></a> or <a href=\"/deferred.done/\"><code>deferred.done()</code></a> are called. Callbacks are executed in the order they were added. Each callback is passed the <code>args</code> from the <code>deferred.resolve()</code>. Any doneCallbacks added after the Deferred enters the resolved state are executed immediately when they are added, using the arguments that were passed to the <code>deferred.resolve()</code> call. For more information, see the documentation for <a href=\"/jQuery.Deferred/\">jQuery.Deferred()</a>.</p>",
"examples": [],
"categories": [
"deferred-object",
"version/1.5"
]
},
{
"title": "deferred.resolveWith()",
"name": "deferred.resolveWith",
"type": "method",
"return": "Deferred",
"signatures": [{
"arguments": [{
"name": "context",
"type": "Object",
"desc": "Context passed to the doneCallbacks as the <code>this</code> object."
},
{
"name": "args",
"type": "Array",
"optional": "true",
"desc": "An optional array of arguments that are passed to the doneCallbacks."
}
],
"added": "1.5"
}],
"desc": "Resolve a Deferred object and call any doneCallbacks with the given <code>context</code> and <code>args</code>.",
"longdesc": "<p>Normally, only the creator of a Deferred should call this method; you can prevent other code from changing the Deferred's state by returning a restricted Promise object through <a href=\"/deferred.promise/\"><code>deferred.promise()</code></a>.</p>\n <p>When the Deferred is resolved, any doneCallbacks added by <a href=\"/deferred.then/\"><code>deferred.then</code></a> or <a href=\"/deferred.done/\"><code>deferred.done</code></a> are called. Callbacks are executed in the order they were added. Each callback is passed the <code>args</code> from the <code>.resolve()</code>. Any doneCallbacks added after the Deferred enters the resolved state are executed immediately when they are added, using the arguments that were passed to the <code>.resolve()</code> call. For more information, see the documentation for <a href=\"/category/deferred-object/\">Deferred object</a>.</p>",
"examples": [],
"categories": [
"deferred-object",
"version/1.5"
]
},
{
"title": "deferred.state()",
"name": "deferred.state",
"type": "method",
"return": "String",
"signatures": [{
"arguments": [],
"added": "1.7"
}],
"desc": "Determine the current state of a Deferred object.",
"longdesc": "<p>The deferred.state() method returns a string representing the current state of the Deferred object. The Deferred object can be in one of three states:</p>\n <ul>\n <li><strong>\"pending\"</strong>: The Deferred object is not yet in a completed state (neither \"rejected\" nor \"resolved\").</li>\n <li><strong>\"resolved\"</strong>: The Deferred object is in the resolved state, meaning that either <a href=\"/deferred.resolve/\"><code>deferred.resolve()</code></a> or <a href=\"/deferred.resolveWith/\"><code>deferred.resolveWith()</code></a> has been called for the object and the doneCallbacks have been called (or are in the process of being called). </li>\n <li><strong>\"rejected\"</strong>: The Deferred object is in the rejected state, meaning that either <a href=\"/deferred.reject/\"><code>deferred.reject()</code></a> or <a href=\"/deferred.rejectWith/\"><code>deferred.rejectWith()</code></a> has been called for the object and the failCallbacks have been called (or are in the process of being called).</li>\n </ul>\n <p>This method is primarily useful for debugging to determine, for example, whether a Deferred has already been resolved even though you are inside code that intended to reject it.</p>",
"examples": [],
"categories": [
"deferred-object",
"version/1.7"
]
},
{
"title": "deferred.then()",
"name": "deferred.then",
"type": "method",
"return": "Promise",
"signatures": [{
"arguments": [{
"name": "doneFilter",
"type": "Function",
"desc": "A function that is called when the Deferred is resolved."
},
{
"name": "failFilter",
"type": "Function",
"optional": "true",
"desc": "An optional function that is called when the Deferred is rejected."
},
{
"name": "progressFilter",
"type": "Function",
"optional": "true",
"desc": "An optional function that is called when progress notifications are sent to the Deferred."
}
],
"added": "1.8"
},
{
"arguments": [{
"name": "doneCallbacks",
"type": "Function",
"desc": "A function, or array of functions, called when the Deferred is resolved."
},
{
"name": "failCallbacks",
"type": "Function",
"desc": "A function, or array of functions, called when the Deferred is rejected."
}
],
"added": "1.5"
},
{
"arguments": [{
"name": "doneCallbacks",
"type": "Function",
"desc": "A function, or array of functions, called when the Deferred is resolved."
},
{
"name": "failCallbacks",
"type": "Function",
"desc": "A function, or array of functions, called when the Deferred is rejected."
},
{
"name": "progressCallbacks",
"type": "Function",
"optional": "true",
"desc": "A function, or array of functions, called when the Deferred notifies progress."
}
],
"added": "1.7"
}
],
"desc": "Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.",
"longdesc": "<p>\n\t\t\t<strong>\n\t\t\t\tPrior to jQuery 1.8\n\t\t\t</strong>\n\t\t\t, the arguments could be a function or an array of functions.\n\t\t</p>\n\t\t<p>\n\t\t\tFor all signatures, the arguments can be\n\t\t\t<code>\n\t\t\t\tnull\n\t\t\t</code>\n\t\t\tif no callback of that type is desired. Alternatively, use\n\t\t\t<code>\n\t\t\t\t.done()\n\t\t\t</code>\n\t\t\t,\n\t\t\t<code>\n\t\t\t\t.fail()\n\t\t\t</code>\n\t\t\tor\n\t\t\t<code>\n\t\t\t\t.progress()\n\t\t\t</code>\n\t\t\tto set only one type of callback without filtering status or values.\n\t\t</p>\n\t\t<p>\n\t\t\t<strong>\n\t\t\t\tAs of jQuery 1.8\n\t\t\t</strong>\n\t\t\t, the\n\t\t\t<code>\n\t\t\t\tdeferred.then()\n\t\t\t</code>\n\t\t\tmethod returns a new promise that can filter the status and values of a deferred through a function, replacing the now-deprecated\n\t\t\t<code>\n\t\t\t\tdeferred.pipe()\n\t\t\t</code>\n\t\t\tmethod. The\n\t\t\t<code>\n\t\t\t\tdoneFilter\n\t\t\t</code>\n\t\t\tand\n\t\t\t<code>\n\t\t\t\tfailFilter\n\t\t\t</code>\n\t\t\tfunctions filter the original deferred's resolved / rejected status and values. The\n\t\t\t<code>\n\t\t\t\tprogressFilter\n\t\t\t</code>\n\t\t\tfunction filters any calls to the original deferred's\n\t\t\t<code>\n\t\t\t\tnotify\n\t\t\t</code>\n\t\t\tor\n\t\t\t<code>\n\t\t\t\tnotifyWith\n\t\t\t</code>\n\t\t\tmethods. These filter functions can return a new value to be passed along to the promise's\n\t\t\t<code>\n\t\t\t\t.done()\n\t\t\t</code>\n\t\t\tor\n\t\t\t<code>\n\t\t\t\t.fail()\n\t\t\t</code>\n\t\t\tcallbacks, or they can return another observable object (Deferred, Promise, etc) which will pass its resolved / rejected status and values to the promise's callbacks. If the filter function used is\n\t\t\t<code>\n\t\t\t\tnull\n\t\t\t</code>\n\t\t\t, or not specified, the promise will be resolved or rejected with the same values as the original.\n\t\t</p>\n\t\t<p>\n\t\t\tCallbacks are executed in the order they were added. Since\n\t\t\t<code>\n\t\t\t\tdeferred.then\n\t\t\t</code>\n\t\t\treturns a Promise, other methods of the\n\t\t\tPromise object can be chained to this one, including additional\n\t\t\t<code>\n\t\t\t\t.then()\n\t\t\t</code>\n\t\t\tmethods.\n\t\t</p>",
"examples": [{
"desc": "Since the\n\t\t\t<a href=\"/jQuery.get/\">\n\t\t\t\t<code>\n\t\t\t\t\tjQuery.get\n\t\t\t\t</code>\n\t\t\t</a>\n\t\t\tmethod returns a jqXHR object, which is derived from a Deferred object, we can attach handlers using the\n\t\t\t<code>\n\t\t\t\t.then\n\t\t\t</code>\n\t\t\tmethod.",
"code": "$.get( \"test.php\" ).then(\n\t\t\tfunction() {\n\t\t\talert( \"$.get succeeded\" );\n\t\t\t}, function() {\n\t\t\talert( \"$.get failed!\" );\n\t\t\t}\n\t\t\t);",
"html": "",
"css": ""
},
{
"desc": "Filter the resolve value:",
"code": "var filterResolve = function() {\n\t\t\tvar defer = $.Deferred(),\n\t\t\tfiltered = defer.then(function( value ) {\n\t\t\treturn value * 2;\n\t\t\t});\n\t\t\t\n\t\t\tdefer.resolve( 5 );\n\t\t\tfiltered.done(function( value ) {\n\t\t\t$( \"p\" ).html( \"Value is ( 2*5 = ) 10: \" + value );\n\t\t\t});\n\t\t\t};\n\t\t\t\n\t\t\t$( \"button\" ).on( \"click\", filterResolve );",
"html": "<button>Filter Resolve</button>\n\t\t\t<p></p>",
"css": ""
},
{
"desc": "Filter reject value:",
"code": "var defer = $.Deferred(),\n\t\t\tfiltered = defer.then( null, function( value ) {\n\t\t\treturn value * 3;\n\t\t\t});\n\t\t\t\n\t\t\tdefer.reject( 6 );\n\t\t\tfiltered.fail(function( value ) {\n\t\t\talert( \"Value is ( 3*6 = ) 18: \" + value );\n\t\t\t});",
"html": "",
"css": ""
},
{
"desc": "Chain tasks:",
"code": "var request = $.ajax( url, { dataType: \"json\" } ),\n\t\t\tchained = request.then(function( data ) {\n\t\t\treturn $.ajax( url2, { data: { user: data.userId } } );\n\t\t\t});\n\t\t\t\n\t\t\tchained.done(function( data ) {\n\t\t\t// data retrieved from url2 as provided by the first request\n\t\t\t});",
"html": "",
"css": ""
}
],
"categories": [
"deferred-object",
"version/1.5",
"version/1.7"
]
},
{
"title": ".delay()",
"type": "method",
"name": "delay",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "duration",
"type": "Integer",
"desc": "An integer indicating the number of milliseconds to delay execution of the next item in the queue."
},
{
"name": "queueName",
"optional": "true",
"type": "String",
"desc": "A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue."
}
],
"added": "1.4"
}],
"desc": "Set a timer to delay execution of subsequent items in the queue.",
"longdesc": "<p>Added to jQuery in version 1.4, the <code>.delay()</code> method allows us to delay the execution of functions that follow it in the queue. It can be used with the standard effects queue or with a custom queue. Only subsequent events in a queue are delayed; for example this will <em>not</em> delay the no-arguments forms of <code>.show()</code> or <code>.hide()</code> which do not use the effects queue.</p>\n <p>Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings <code>'fast'</code> and <code>'slow'</code> can be supplied to indicate durations of 200 and 600 milliseconds, respectively.</p>\n <p>Using the standard effects queue, we can, for example, set an 800-millisecond delay between the <code>.slideUp()</code> and <code>.fadeIn()</code> of <code>&lt;div id=\"foo\"&gt;</code>:</p>\n <pre><code>\n$( \"#foo\" ).slideUp( 300 ).delay( 800 ).fadeIn( 400 );\n </code></pre>\n <p>When this statement is executed, the element slides up for 300 milliseconds and then pauses for 800 milliseconds before fading in for 400 milliseconds.</p>\n <div class=\"warning\">\n <p>\n <strong>The <code>.delay()</code> method is best for delaying between queued jQuery effects. Because it is limited—it doesn't, for example, offer a way to cancel the delay—<code>.delay()</code> is not a replacement for JavaScript's native <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers.setTimeout\">setTimeout</a> function, which may be more appropriate for certain use cases.</strong>\n </p>\n </div>",
"examples": [{
"desc": "Animate the hiding and showing of two divs, delaying the first before showing it.",
"code": "$( \"button\" ).click(function() {\n $( \"div.first\" ).slideUp( 300 ).delay( 800 ).fadeIn( 400 );\n $( \"div.second\" ).slideUp( 300 ).fadeIn( 400 );\n});",
"html": "<p><button>Run</button></p>\n<div class=\"first\"></div>\n<div class=\"second\"></div>",
"css": "div {\n position: absolute;\n width: 60px;\n height: 60px;\n float: left;\n }\n .first {\n background-color: #3f3;\n left: 0;\n }\n .second {\n background-color: #33f;\n left: 80px;\n }"
}],
"categories": [
"effects/custom-effects",
"version/1.4"
]
},
{
"title": ".delegate()",
"type": "method",
"name": "delegate",
"return": "jQuery",
"deprecated": "3.0",
"signatures": [{
"arguments": [{
"name": "selector",
"type": "String",
"desc": "A selector to filter the elements that trigger the event."
},
{
"name": "eventType",
"type": "String",
"desc": "A string containing one or more space-separated JavaScript event types, such as \"click\" or \"keydown,\" or custom event names."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute at the time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.2"
},
{
"arguments": [{
"name": "selector",
"type": "String",
"desc": "A selector to filter the elements that trigger the event."
},
{
"name": "eventType",
"type": "String",
"desc": "A string containing one or more space-separated JavaScript event types, such as \"click\" or \"keydown,\" or custom event names."
},
{
"name": "eventData",
"type": "Anything",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute at the time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.2"
},
{
"arguments": [{
"name": "selector",
"type": "String",
"desc": "A selector to filter the elements that trigger the event."
},
{
"name": "events",
"type": "PlainObject",
"desc": "A plain object of one or more event types and functions to execute for them."
}
],
"added": "1.4.3"
}
],
"desc": "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.",
"longdesc": "<p>As of jQuery 3.0, <code>.delegate()</code> has been deprecated. It was superseded by the <a href=\"/on/\"><code>.on()</code></a> method since jQuery 1.7, so its use was already discouraged. For earlier versions, however, it remains the most effective means to use event delegation. More information on event binding and delegation is in the <a href=\"/on/\"><code>.on()</code></a> method. In general, these are the equivalent templates for the two methods:</p>\n <pre><code>\n// jQuery 1.4.3+\n$( elements ).delegate( selector, events, data, handler );\n// jQuery 1.7+\n$( elements ).on( events, selector, data, handler );\n </code></pre>\n <p>For example, the following <code>.delegate()</code> code:</p>\n <pre><code>\n$( \"table\" ).delegate( \"td\", \"click\", function() {\n $( this ).toggleClass( \"chosen\" );\n});\n </code></pre>\n <p>is equivalent to the following code written using <code>.on()</code>:</p>\n <pre><code>\n$( \"table\" ).on( \"click\", \"td\", function() {\n $( this ).toggleClass( \"chosen\" );\n});\n </code></pre>\n <p>To remove events attached with <code>delegate()</code>, see the <a href=\"/undelegate/\">.undelegate()</a> method.</p>\n <p>Passing and handling event data works the same way as it does for <code>.on()</code>.</p>",
"note": [{
"type": "additional",
"text": "Since the <a href=\"/live/\"><code>.live()</code></a> method handles events once they have propagated to the top of the document, it is not possible to stop propagation of live events. Similarly, events handled by <code><a href=\"/delegate/\">.delegate()</a></code> will propagate to the elements to which they are delegated; event handlers bound on any elements below it in the DOM tree will already have been executed by the time the delegated event handler is called. These handlers, therefore, may prevent the delegated handler from triggering by calling <code><a href=\"/event.stopPropagation/\">event.stopPropagation()</a></code> or returning <code>false</code>."
}],
"examples": [{
"desc": "Click a paragraph to add another. Note that .delegate() attaches a click event handler to all paragraphs - even new ones.",
"code": "$( \"body\" ).delegate( \"p\", \"click\", function() {\n $( this ).after( \"<p>Another paragraph!</p>\" );\n});",
"html": "<p>Click me!</p>\n\n<span></span>",
"css": "p {\n background: yellow;\n font-weight: bold;\n cursor: pointer;\n padding: 5px;\n }\n p.over {\n background: #ccc;\n }\n span {\n color: red;\n }"
},
{
"desc": "To display each paragraph's text in an alert box whenever it is clicked:",
"code": "$( \"body\" ).delegate( \"p\", \"click\", function() {\n alert( $( this ).text() );\n});",
"html": "",
"css": ""
},
{
"desc": "To cancel a default action and prevent it from bubbling up, return false:",
"code": "$( \"body\" ).delegate( \"a\", \"click\", function() {\n return false;\n});",
"html": "",
"css": ""
},
{
"desc": "To cancel only the default action by using the preventDefault method.",
"code": "$( \"body\" ).delegate( \"a\", \"click\", function( event ) {\n event.preventDefault();\n});",
"html": "",
"css": ""
},
{
"desc": "Can bind custom events too.",
"code": "$( \"body\" ).delegate( \"p\", \"myCustomEvent\", function( e, myName, myValue ) {\n $( this ).text( \"Hi there!\" );\n $( \"span\" )\n .stop()\n .css( \"opacity\", 1 )\n .text( \"myName = \" + myName )\n .fadeIn( 30 )\n .fadeOut( 1000 );\n});\n$( \"button\" ).click(function() {\n $( \"p\" ).trigger( \"myCustomEvent\" );\n});",
"html": "<p>Has an attached custom event.</p>\n<button>Trigger custom event</button>\n<span style=\"display:none;\"></span>",
"css": "p {\n color: red;\n }\n span {\n color: blue;\n }"
}
],
"categories": [
"events/event-handler-attachment",
"version/1.4.2",
"version/1.4.3",
"deprecated/deprecated-3.0"
]
},
{
"title": ".dequeue()",
"type": "method",
"name": "dequeue",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "queueName",
"optional": "true",
"type": "String",
"desc": "A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue."
}],
"added": "1.2"
}],
"desc": "Execute the next function on the queue for the matched elements.",
"longdesc": "<p>When <code>.dequeue()</code> is called, the next function on the queue is removed from the queue, and then executed. This function should in turn (directly or indirectly) cause <code>.dequeue()</code> to be called, so that the sequence can continue.</p>",
"examples": [{
"desc": "Use dequeue to end a custom queue function which allows the queue to keep going.",
"code": "$( \"button\" ).click(function() {\n $( \"div\" )\n .animate({ left:\"+=200px\" }, 2000 )\n .animate({ top:\"0px\" }, 600 )\n .queue(function() {\n $( this ).toggleClass( \"red\" ).dequeue();\n })\n .animate({ left:\"10px\", top:\"30px\" }, 700 );\n});",
"html": "<button>Start</button>\n<div></div>",
"css": "div {\n margin: 3px;\n width: 50px;\n position: absolute;\n height: 50px;\n left: 10px;\n top: 30px;\n background-color: yellow;\n }\n div.red {\n background-color: red;\n }"
}],
"categories": [
"effects/custom-effects",
"data",
"utilities",
"version/1.2"
]
},
{
"title": "Descendant Selector (\"ancestor descendant\")",
"type": "selector",
"name": "descendant",
"return": "",
"signatures": [{
"arguments": [{
"name": "ancestor",
"type": "Selector",
"desc": "Any valid selector."
},
{
"name": "descendant",
"type": "Selector",
"desc": "A selector to filter the descendant elements."
}
],
"added": "1.0"
}],
"desc": "Selects all elements that are descendants of a given ancestor.",
"longdesc": "<p>A descendant of an element could be a child, grandchild, great-grandchild, and so on, of that element.</p>",
"examples": [{
"desc": "Mark all inputs that are descendants of a form with a dotted blue border. Give a yellow background to inputs that are descendants of a fieldset that is a descendant of a form.",
"code": "$( \"form input\" ).css( \"border\", \"2px dotted blue\" );\n$( \"form fieldset input\" ).css( \"backgroundColor\", \"yellow\" );",
"html": "<form>\n <div>Form is surrounded by the green border.</div>\n\n <label for=\"name\">Child of form:</label>\n <input name=\"name\" id=\"name\">\n\n <fieldset>\n <label for=\"newsletter\">Grandchild of form, child of fieldset:</label>\n <input name=\"newsletter\" id=\"newsletter\">\n </fieldset>\n</form>\nSibling to form: <input name=\"none\">",
"css": "form {\n border: 2px green solid;\n padding: 2px;\n margin: 0;\n background: #efe;\n }\n div {\n color: red;\n }\n fieldset {\n margin: 1px;\n padding: 3px;\n }"
}],
"categories": [
"selectors/hierarchy-selectors",
"version/1.0"
]
},
{
"title": ".detach()",
"type": "method",
"name": "detach",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "selector",
"optional": "true",
"type": "Selector",
"desc": "A selector expression that filters the set of matched elements to be removed."
}],
"added": "1.4"
}],
"desc": "Remove the set of matched elements from the DOM.",
"longdesc": "<p>The <code>.detach()</code> method is the same as <code><a href=\"/remove/\">.remove()</a></code>, except that <code>.detach()</code> keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.</p>",
"examples": [{
"desc": "Detach all paragraphs from the DOM",
"code": "$( \"p\" ).click(function() {\n $( this ).toggleClass( \"off\" );\n});\nvar p;\n$( \"button\" ).click(function() {\n if ( p ) {\n p.appendTo( \"body\" );\n p = null;\n } else {\n p = $( \"p\" ).detach();\n }\n});",
"html": "<p>Hello</p>\nhow are\n<p>you?</p>\n<button>Attach/detach paragraphs</button>",
"css": "p {\n background: yellow;\n margin: 6px 0;\n }\n p.off {\n background: black;\n }"
}],
"categories": [
"manipulation/dom-removal",
"version/1.4"
]
},
{
"title": ".die()",
"type": "method",
"name": "die",
"return": "jQuery",
"deprecated": "1.7",
"removed": "1.9",
"signatures": [{
"arguments": [],
"added": "1.4.1"
},
{
"arguments": [{
"name": "eventType",
"type": "String",
"desc": "A string containing a JavaScript event type, such as <code>click</code> or <code>keydown</code>."
},
{
"name": "handler",
"optional": "true",
"type": "String",
"desc": "The function that is no longer to be executed."
}
],
"added": "1.3"
},
{
"arguments": [{
"name": "events",
"type": "PlainObject",
"desc": "A plain object of one or more event types, such as <code>click</code> or <code>keydown</code> and their corresponding functions that are no longer to be executed."
}],
"added": "1.4.3"
}
],
"desc": "Remove event handlers previously attached using <code>.live()</code> from the elements.",
"longdesc": "<div class=\"warning\">\n <p>Note: This API has been removed in jQuery 1.9; please use <a href=\"/on/\"><code>on()</code></a> instead.</p>\n </div>\n <p>Any handler that has been attached with <code>.live()</code> can be removed with <code>.die()</code>. This method is analogous to calling <code>.off()</code> with no arguments, which is used to remove all handlers attached with <code>.on()</code>.\n See the discussions of <code>.live()</code> and <code>.off()</code> for further details.</p>\n <p>If used without an argument, .die() removes <em>all</em> event handlers previously attached using <code>.live()</code> from the elements.</p>\n <p><strong>As of jQuery 1.7</strong>, use of <code>.die()</code> (and its complementary method, <code>.live()</code>) is not recommended. Instead, use <a href=\"/off/\"><code>.off()</code></a> to remove event handlers bound with <a href=\"/on/\"><code>.on()</code></a></p>\n <p><strong>Note:</strong> In order for .die() to function correctly, the selector used with it must match exactly the selector initially used with .live().</p>",
"examples": [{
"desc": "To unbind all live events from all paragraphs, write:",
"code": "$( \"p\" ).die();",
"html": "",
"css": ""
},
{
"desc": "To unbind all live click events from all paragraphs, write:",
"code": "$( \"p\" ).die( \"click\" );",
"html": "",
"css": ""
},
{
"desc": "To unbind just one previously bound handler, pass the function in as the second argument:",
"code": "var foo = function() {\n // Code to handle some kind of event\n};\n\n// Now foo will be called when paragraphs are clicked\n$( \"p\" ).live( \"click\", foo );\n\n// Now foo will no longer be called\n$( \"p\" ).die( \"click\", foo );",
"html": "",
"css": ""
}
],
"categories": [
"events/event-handler-attachment",
"version/1.3",
"version/1.4.1",
"version/1.4.3",
"deprecated/deprecated-1.7",
"removed"
]
},
{
"title": ":disabled Selector",
"type": "selector",
"name": "disabled",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Selects all elements that are disabled.",
"longdesc": "<p>As with other pseudo-class selectors (those that begin with a \":\"), it is recommended to precede it with a tag name or some other selector; otherwise, the universal selector (\"*\") is implied. In other words, the bare <code>$(':disabled')</code> is equivalent to <code>$('*:disabled')</code>, so <code>$('input:disabled')</code> or similar should be used instead. </p>\n\n <p>Although their resulting selections are usually the same, the <code>:disabled</code> selector is subtly different from the <code>[disabled]</code> attribute selector;<code>:disabled</code> matches elements that are <a href=\"https://html.spec.whatwg.org/multipage/scripting.html#disabled-elements\">actually disabled</a> while <code>[disabled]</code> only checks for the existence of the disabled attribute.</p>\n\n <p>The <code>:disabled</code> selector should only be used for selecting HTML elements that support the <code>disabled</code> attribute (<code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;optgroup&gt;</code>, <code>&lt;option&gt;</code>, <code>&lt;select&gt;</code>, <code>&lt;textarea&gt;</code>, <code>&lt;menuitem&gt;</code>, and <code>&lt;fieldset&gt;</code>).</p>",
"examples": [{
"desc": "Finds all input elements that are disabled.",
"code": "$( \"input:disabled\" ).val( \"this is it\" );",
"html": "<form>\n <input name=\"email\" disabled=\"disabled\">\n <input name=\"id\">\n</form>",
"css": ""
}],
"categories": [
"selectors/form-selectors",
"version/1.0"
]
},
{
"title": ".each()",
"type": "method",
"name": "each",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "A function to execute for each matched element.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "element",
"type": "Element"
}
]
}],
"added": "1.0"
}],
"desc": "Iterate over a jQuery object, executing a function for each matched element.",
"longdesc": "<p>The <code>.each()</code> method is designed to make DOM looping constructs concise and less error-prone. When called it iterates over the DOM elements that are part of the jQuery object. Each time the callback runs, it is passed the current loop iteration, beginning from 0. More importantly, the callback is fired in the context of the current DOM element, so the keyword <code>this</code> refers to the element.</p>\n <p>Suppose you have a simple unordered list on the page:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li&gt;foo&lt;/li&gt;\n &lt;li&gt;bar&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>You can select the list items and iterate across them:</p>\n <pre><code>\n$( \"li\" ).each(function( index ) {\n console.log( index + \": \" + $( this ).text() );\n});\n </code></pre>\n <p>A message is thus logged for each item in the list:</p>\n <p>\n <samp>0: foo</samp>\n <br/>\n <samp>1: bar</samp>\n </p>\n <p>You can stop the loop from within the callback function by returning <code>false</code>.</p>\n <p>Note: most jQuery methods that return a jQuery object also loop through the set of elements in the jQuery collection — a process known as <i>implicit iteration</i>. When this occurs, it is often unnecessary to <i>explicitly</i> iterate with the <code>.each()</code> method:</p>\n <pre><code>\n// The .each() method is unnecessary here:\n$( \"li\" ).each(function() {\n $( this ).addClass( \"foo\" );\n});\n\n// Instead, you should rely on implicit iteration:\n$( \"li\" ).addClass( \"bar\" );\n </code></pre>",
"examples": [{
"desc": "Iterate over three divs and sets their color property.",
"code": "$( document.body ).click(function() {\n $( \"div\" ).each(function( i ) {\n if ( this.style.color !== \"blue\" ) {\n this.style.color = \"blue\";\n } else {\n this.style.color = \"\";\n }\n });\n});",
"html": "<div>Click here</div>\n<div>to iterate through</div>\n<div>these divs.</div>",
"css": "div {\n color: red;\n text-align: center;\n cursor: pointer;\n font-weight: bolder;\n width: 300px;\n }"
},
{
"desc": "To access a jQuery object instead of the regular DOM element, use <code>$( this )</code>. For example:",
"code": "$( \"span\" ).click(function() {\n $( \"li\" ).each(function() {\n $( this ).toggleClass( \"example\" );\n });\n});",
"html": "To do list: <span>(click here to change)</span>\n<ul>\n <li>Eat</li>\n <li>Sleep</li>\n <li>Be merry</li>\n</ul>",
"css": "ul {\n font-size: 18px;\n margin: 0;\n }\n span {\n color: blue;\n text-decoration: underline;\n cursor: pointer;\n }\n .example {\n font-style: italic;\n }"
},
{
"desc": "Use <code>return false</code> to break out of each() loops early.",
"code": "$( \"button\" ).click(function() {\n $( \"div\" ).each(function( index, element ) {\n // element == this\n $( element ).css( \"backgroundColor\", \"yellow\" );\n if ( $( this ).is( \"#stop\" ) ) {\n $( \"span\" ).text( \"Stopped at div index #\" + index );\n return false;\n }\n });\n});",
"html": "<button>Change colors</button>\n<span></span>\n<div></div>\n<div></div>\n<div></div>\n<div></div>\n<div id=\"stop\">Stop here</div>\n<div></div>\n<div></div>\n<div></div>",
"css": "div {\n width: 40px;\n height: 40px;\n margin: 5px;\n float: left;\n border: 2px blue solid;\n text-align: center;\n }\n span {\n color: red;\n }"
}
],
"categories": [
"miscellaneous/collection-manipulation",
"traversing",
"version/1.0"
]
},
{
"title": "Element Selector (\"element\")",
"type": "selector",
"name": "element",
"return": "",
"signatures": [{
"arguments": [{
"name": "element",
"type": "String",
"desc": "An element to search for. Refers to the tagName of DOM nodes."
}],
"added": "1.0"
}],
"desc": "Selects all elements with the given tag name.",
"longdesc": "<p>JavaScript's <code>getElementsByTagName()</code> function is called to return the appropriate elements when this expression is used.</p>",
"examples": [{
"desc": "Finds every DIV element.",
"code": "$( \"div\" ).css( \"border\", \"9px solid red\" );",
"html": "<div>DIV1</div>\n<div>DIV2</div>\n<span>SPAN</span>",
"css": "div, span {\n width: 60px;\n height: 60px;\n float: left;\n padding: 10px;\n margin: 10px;\n background-color: #eee;\n }"
}],
"categories": [
"selectors/basic-css-selectors",
"version/1.0"
]
},
{
"title": ":empty Selector",
"type": "selector",
"name": "empty",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Select all elements that have no children (including text nodes).",
"longdesc": "<p>This is the inverse of <code>:parent</code>. </p>\n <p>One important thing to note with :empty (and :parent) is that child elements include text nodes.</p>\n <p>The W3C recommends that the <code>&lt;p&gt;</code> element have at least one child node, even if that child is merely text (see https://www.w3.org/TR/html401/struct/text.html#edef-P). Some other elements, on the other hand, are empty (i.e. have no children) by definition: &lt;input&gt;, &lt;img&gt;, &lt;br&gt;, and &lt;hr&gt;, for example.</p>",
"examples": [{
"desc": "Finds all elements that are empty - they don't have child elements or text.",
"code": "$( \"td:empty\" )\n .text( \"Was empty!\" )\n .css( \"background\", \"rgb(255,220,200)\" );",
"html": "<table border=\"1\">\n <tr><td>TD #0</td><td></td></tr>\n <tr><td>TD #2</td><td></td></tr>\n <tr><td></td><td>TD#5</td></tr>\n</table>",
"css": "td {\n text-align: center;\n }"
}],
"categories": [
"selectors/content-filter-selector",
"version/1.0"
]
},
{
"title": ".empty()",
"type": "method",
"name": "empty",
"return": "jQuery",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Remove all child nodes of the set of matched elements from the DOM.",
"longdesc": "<p>This method removes not only child (and other descendant) elements, but also any text within the set of matched elements. This is because, according to the DOM specification, any string of text within an element is considered a child node of that element. Consider the following HTML:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;div class=\"hello\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"goodbye\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>We can target any element for removal:</p>\n <pre><code>\n$( \".hello\" ).empty();\n </code></pre>\n <p>This will result in a DOM structure with the <code>Hello</code> text deleted:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;div class=\"hello\"&gt;&lt;/div&gt;\n &lt;div class=\"goodbye\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>If we had any number of nested elements inside <code>&lt;div class=\"hello\"&gt;</code>, they would be removed, too.</p>\n <p>To avoid memory leaks, jQuery removes other constructs such as data and event handlers from the child elements before removing the elements themselves.</p>\n <p>If you want to remove elements without destroying their data or event handlers (so they can be re-added later), use <a href=\"/detach/\"><code>.detach()</code></a> instead.</p>",
"examples": [{
"desc": "Removes all child nodes (including text nodes) from all paragraphs",
"code": "$( \"button\" ).click(function() {\n $( \"p\" ).empty();\n});",
"html": "<p>\n Hello, <span>Person</span> <em>and person</em>.\n</p>\n\n<button>Call empty() on above paragraph</button>",
"css": "p {\n background: yellow;\n }"
}],
"categories": [
"manipulation/dom-removal",
"version/1.0"
]
},
{
"title": ":enabled Selector",
"type": "selector",
"name": "enabled",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Selects all elements that are enabled.",
"longdesc": "<p>As with other pseudo-class selectors (those that begin with a \":\") it is recommended to precede it with a tag name or some other selector; otherwise, the universal selector ( \"*\" ) is implied. In other words, the bare <code>$( \":enabled\" )</code> is equivalent to <code>$( \"*:enabled\" )</code>, so <code>$( \"input:enabled\" )</code> or similar should be used instead. </p>\n\n <p>Although their resulting selections are usually the same, <code>:enabled</code> selector is subtly different from <code>:not([disabled])</code>; <code>:enabled</code> selects elements that have their boolean disabled property strictly equal to false, while <code>:not([disabled])</code> selects elements that do not have a disabled <em>attribute</em> set (regardless of its value).</p>\n\n <p>The <code>:enabled</code> selector should only be used for selecting HTML elements that support the <code>disabled</code> attribute (<code>&lt;button&gt;</code>, <code>&lt;input&gt;</code>, <code>&lt;optgroup&gt;</code>, <code>&lt;option&gt;</code>, <code>&lt;select&gt;</code>, and <code>&lt;textarea&gt;</code>).</p>",
"examples": [{
"desc": "Find all input elements that are enabled.",
"code": "$( \"input:enabled\" ).val( \"this is it\" );",
"html": "<form>\n <input name=\"email\" disabled=\"disabled\">\n <input name=\"id\">\n</form>",
"css": ""
}],
"categories": [
"selectors/form-selectors",
"version/1.0"
]
},
{
"title": ".end()",
"type": "method",
"name": "end",
"return": "jQuery",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "End the most recent filtering operation in the current chain and return the set of matched elements to its previous state.",
"longdesc": "<p>Most of jQuery's <a href=\"/category/traversing/\">DOM traversal</a> methods operate on a jQuery object instance and produce a new one, matching a different set of DOM elements. When this happens, it is as if the new set of elements is pushed onto a stack that is maintained inside the object. Each successive filtering method pushes a new element set onto the stack. If we need an older element set, we can use <code>end()</code> to pop the sets back off of the stack.</p>\n <p>Suppose we have a couple short lists on a page:</p>\n <pre><code>\n&lt;ul class=\"first\"&gt;\n &lt;li class=\"foo\"&gt;list item 1&lt;/li&gt;\n &lt;li&gt;list item 2&lt;/li&gt;\n &lt;li class=\"bar\"&gt;list item 3&lt;/li&gt;\n&lt;/ul&gt;\n&lt;ul class=\"second\"&gt;\n &lt;li class=\"foo\"&gt;list item 1&lt;/li&gt;\n &lt;li&gt;list item 2&lt;/li&gt;\n &lt;li class=\"bar\"&gt;list item 3&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>The <code>end()</code> method is useful primarily when exploiting jQuery's chaining properties. When not using chaining, we can usually just call up a previous object by variable name, so we don't need to manipulate the stack. With <code>end()</code>, though, we can string all the method calls together:</p>\n <pre><code>\n$( \"ul.first\" )\n .find( \".foo\" )\n .css( \"background-color\", \"red\" )\n .end()\n .find( \".bar\" )\n .css( \"background-color\", \"green\" );\n </code></pre>\n <p>This chain searches for items with the class <code>foo</code> within the first list only and turns their backgrounds red. Then <code>end()</code> returns the object to its state before the call to <code>find()</code>, so the second <code>find()</code> looks for '.bar' inside <code>&lt;ul class=\"first\"&gt;</code>, not just inside that list's <code>&lt;li class=\"foo\"&gt;</code>, and turns the matching elements' backgrounds green. The net result is that items 1 and 3 of the first list have a colored background, and none of the items from the second list do.</p>\n <p>A long jQuery chain can be visualized as a structured code block, with filtering methods providing the openings of nested blocks and <code>end()</code> methods closing them:</p>\n <pre><code>\n$( \"ul.first\" )\n .find( \".foo\" )\n .css( \"background-color\", \"red\" )\n .end()\n .find( \".bar\" )\n .css( \"background-color\", \"green\" )\n .end();\n </code></pre>\n <p>The last <code>end()</code> is unnecessary, as we are discarding the jQuery object immediately thereafter. However, when the code is written in this form, the <code>end()</code> provides visual symmetry and a sense of completion —making the program, at least to the eyes of some developers, more readable, at the cost of a slight hit to performance as it is an additional function call.</p>",
"examples": [{
"desc": "Selects all paragraphs, finds span elements inside these, and reverts the selection back to the paragraphs.",
"code": "jQuery.fn.showTags = function( n ) {\n var tags = this.map(function() {\n return this.tagName;\n })\n .get()\n .join( \", \" );\n $( \"b\" ).eq( n ).text( tags );\n return this;\n};\n\n$( \"p\" )\n .showTags( 0 )\n .find( \"span\" )\n .showTags( 1 )\n .css( \"background\", \"yellow\" )\n .end()\n .showTags( 2 )\n .css( \"font-style\", \"italic\" );",
"html": "<p>\n Hi there <span>how</span> are you <span>doing</span>?\n</p>\n\n<p>\n This <span>span</span> is one of\n several <span>spans</span> in this\n <span>sentence</span>.\n</p>\n\n<div>\n Tags in jQuery object initially: <b></b>\n</div>\n\n<div>\n Tags in jQuery object after find: <b></b>\n</div>\n\n<div>\n Tags in jQuery object after end: <b></b>\n</div>",
"css": "p, div {\n margin: 1px;\n padding: 1px;\n font-weight: bold;\n font-size: 16px;\n }\n div {\n color: blue;\n }\n b {\n color: red;\n }"
},
{
"desc": "Selects all paragraphs, finds span elements inside these, and reverts the selection back to the paragraphs.",
"code": "$( \"p\" )\n .find( \"span\" )\n .end()\n .css( \"border\", \"2px red solid\" );",
"html": "<p><span>Hello</span>, how are you?</p>",
"css": "p {\n margin: 10px;\n padding: 10px;\n }"
}
],
"categories": [
"traversing/miscellaneous-traversal",
"version/1.0"
]
},
{
"title": ":eq() Selector",
"type": "selector",
"name": "eq",
"return": "",
"deprecated": "3.4",
"signatures": [{
"arguments": [{
"name": "index",
"type": "Number",
"desc": "Zero-based index of the element to match."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "indexFromEnd",
"type": "Integer",
"desc": "Zero-based index of the element to match, counting backwards from the last element."
}],
"added": "1.8"
}
],
"desc": "Select the element at index <code>n</code> within the matched set.",
"longdesc": "<p><strong>As of jQuery 3.4</strong>, the <code>:eq</code> pseudo-class is deprecated. Remove it from your selectors and filter the results later using <a href=\"/eq/\"><code>.eq()</code></a>.</p>\n <p>The index-related selectors (<code>:eq()</code>, <code>:lt()</code>, <code>:gt()</code>, <code>:even</code>, <code>:odd</code>) filter the set of elements that have matched the expressions that precede them. They narrow the set down based on the order of the elements within this matched set. For example, if elements are first selected with a class selector (<code>.myclass</code>) and four elements are returned, these elements are given indices <code>0</code> through <code>3</code> for the purposes of these selectors.</p>\n <p>Note that since JavaScript arrays use <em>0-based indexing</em>, these selectors reflect that fact. This is why <code>$( \".myclass:eq(1)\" )</code> selects the second element in the document with the class myclass, rather than the first. In contrast, <code>:nth-child(n)</code> uses <em>1-based indexing</em> to conform to the CSS specification.</p>\n <p>Prior to jQuery 1.8, the <code>:eq(index)</code> selector did <em>not</em> accept a negative value for <code>index</code> (though the <a href=\"/eq/\"><code>.eq(index)</code></a> method did).</p>",
"note": [{
"type": "additional",
"text": "Because <code>:eq()</code> is a jQuery extension and not part of the CSS specification, queries using <code>:eq()</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>$(\"your-pure-css-selector\").eq(index)</code> instead."
}],
"examples": [{
"desc": "Find the third td.",
"code": "$( \"td:eq( 2 )\" ).css( \"color\", \"red\" );",
"html": "<table border=\"1\">\n <tr><td>TD #0</td><td>TD #1</td><td>TD #2</td></tr>\n <tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr>\n <tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr>\n</table>",
"css": ""
},
{
"desc": "Apply three different styles to list items to demonstrate that <code>:eq()</code> is designed to select a single element while <code>:nth-child()</code> or <code>:eq()</code> within a looping construct such as <code>.each()</code> can select multiple elements.",
"code": "// Applies yellow background color to a single <li>\n$( \"ul.nav li:eq(1)\" ).css( \"backgroundColor\", \"#ff0\" );\n\n// Applies italics to text of the second <li> within each <ul class=\"nav\">\n$( \"ul.nav\" ).each(function( index ) {\n $( this ).find( \"li:eq(1)\" ).css( \"fontStyle\", \"italic\" );\n});\n\n// Applies red text color to descendants of <ul class=\"nav\">\n// for each <li> that is the second child of its parent\n$( \"ul.nav li:nth-child(2)\" ).css( \"color\", \"red\" );",
"html": "<ul class=\"nav\">\n <li>List 1, item 1</li>\n <li>List 1, item 2</li>\n <li>List 1, item 3</li>\n</ul>\n<ul class=\"nav\">\n <li>List 2, item 1</li>\n <li>List 2, item 2</li>\n <li>List 2, item 3</li>\n</ul>",
"css": ""
},
{
"desc": "Add a class to List 2, item 2 by targeting the second to last &lt;li&gt;",
"code": "$( \"li:eq(-2)\" ).addClass( \"foo\" )",
"html": "<ul class=\"nav\">\n <li>List 1, item 1</li>\n <li>List 1, item 2</li>\n <li>List 1, item 3</li>\n</ul>\n<ul class=\"nav\">\n <li>List 2, item 1</li>\n <li>List 2, item 2</li>\n <li>List 2, item 3</li>\n</ul>",
"css": ".foo {\n color: blue;\n background-color: yellow;\n }"
}
],
"categories": [
"selectors/basic-filter-selectors",
"selectors/jquery-selector-extensions",
"version/1.0",
"version/1.8",
"deprecated/deprecated-3.4"
]
},
{
"title": ".eq()",
"type": "method",
"name": "eq",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "index",
"type": "Integer",
"desc": "An integer indicating the 0-based position of the element."
}],
"added": "1.1.2"
},
{
"arguments": [{
"name": "indexFromEnd",
"type": "Integer",
"desc": "An integer indicating the position of the element, counting backwards from the last element in the set."
}],
"added": "1.4"
}
],
"desc": "Reduce the set of matched elements to the one at the specified index.",
"longdesc": "<p>Given a jQuery object that represents a set of DOM elements, the <code>.eq()</code> method constructs a new jQuery object from one element within that set. The supplied index identifies the position of this element in the set. </p>\n <p>Consider a page with a simple list on it:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li&gt;list item 1&lt;/li&gt;\n &lt;li&gt;list item 2&lt;/li&gt;\n &lt;li&gt;list item 3&lt;/li&gt;\n &lt;li&gt;list item 4&lt;/li&gt;\n &lt;li&gt;list item 5&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>We can apply this method to the set of list items:</p>\n <pre><code>\n$( \"li\" ).eq( 2 ).css( \"background-color\", \"red\" );\n </code></pre>\n <p>The result of this call is a red background for item 3. Note that the supplied index is zero-based, and refers to the position of the element within the jQuery object, not within the DOM tree.</p>\n <p>Providing a negative number indicates a position starting from the end of the set, rather than the beginning. For example:</p>\n <pre><code>\n$( \"li\" ).eq( -2 ).css( \"background-color\", \"red\" );\n </code></pre>\n <p>This time list item 4 is turned red, since it is two from the end of the set.</p>\n <p>If an element cannot be found at the specified zero-based index, the method constructs a new jQuery object with an empty set and a <code>length</code> property of 0. </p>\n <pre><code>\n$( \"li\" ).eq( 5 ).css( \"background-color\", \"red\" );\n </code></pre>\n <p>Here, none of the list items is turned red, since <code>.eq( 5 )</code> indicates the sixth of five list items.</p>",
"examples": [{
"desc": "Turn the div with index 2 blue by adding an appropriate class.",
"code": "$( \"body\" ).find( \"div\" ).eq( 2 ).addClass( \"blue\" );",
"html": "<div></div>\n<div></div>\n<div></div>\n<div></div>\n<div></div>\n<div></div>",
"css": "div {\n width: 60px;\n height: 60px;\n margin: 10px;\n float: left;\n border: 2px solid blue;\n }\n .blue {\n background: blue;\n }"
}],
"categories": [
"traversing/filtering",
"version/1.1.2"
]
},
{
"title": ".error()",
"type": "method",
"name": "error",
"return": "jQuery",
"deprecated": "1.8",
"removed": "3.0",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute when the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
}
],
"desc": "Bind an event handler to the \"error\" JavaScript event.",
"longdesc": "<div class=\"warning\">\n <p>Note: This API has been removed in jQuery 3.0; please use <code>.on( \"error\", handler )</code> instead of <code>.error( handler )</code> and <code>.trigger( \"error\" )</code> instead of <code>.error()</code>.</p>\n </div>\n <p>The <code>error</code> event is sent to elements, such as images, that are referenced by a document and loaded by the browser. It is called if the element was not loaded correctly.</p>\n <p>For example, consider a page with a simple image element:</p>\n <pre><code>\n&lt;img alt=\"Book\" id=\"book\"&gt;\n </code></pre>\n <p>The event handler can be bound to the image:</p>\n <pre><code>\n$( \"#book\" )\n .error(function() {\n alert( \"Handler for .error() called.\" )\n })\n .attr( \"src\", \"missing.png\" );\n </code></pre>\n <p>If the image cannot be loaded (for example, because it is not present at the supplied URL), the alert is displayed:</p>\n <p>\n <samp>Handler for .error() called.</samp>\n </p>\n <div class=\"warning\">\n <p>The event handler <em>must</em> be attached before the browser fires the <code>error</code> event, which is why the example sets the <code>src</code> attribute after attaching the handler. Also, the <code>error</code> event may not be correctly fired when the page is served locally; <code>error</code> relies on HTTP status codes and will generally not be triggered if the URL uses the <code>file:</code> protocol.</p>\n </div>\n <p>Note: A jQuery <code>error</code> event handler should not be attached to the <code>window</code> object. The browser fires the <code>window</code>'s <code>error</code> event when a script error occurs. However, the window <code>error</code> event receives different arguments and has different return value requirements than conventional event handlers. Use <code>window.onerror</code> instead.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.error()</code> method is just a shorthand for <code>.on( \"error\", handler )</code>, detaching is possible using <code>.off( \"error\" )</code>."
}],
"examples": [{
"desc": "To replace all the missing images with another, you can update the <code>src</code> attribute inside the callback passed to <code>.error()</code>. Be sure that the replacement image exists; otherwise the <code>error</code> event will be triggered indefinitely.",
"code": "// If missing.png is missing, it is replaced by replacement.png\n$( \"img\" )\n .error(function() {\n $( this ).attr( \"src\", \"replacement.png\" );\n })\n .attr( \"src\", \"missing.png\" );",
"html": "",
"css": ""
}],
"categories": [
"events/browser-events",
"version/1.0",
"version/1.4.3",
"deprecated/deprecated-1.8",
"removed"
]
},
{
"title": ":even Selector",
"type": "selector",
"name": "even",
"return": "",
"deprecated": "3.4",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Selects even elements, zero-indexed. See also <a href=\"/Selectors/odd/\">odd</a>.",
"longdesc": "<p>In particular, note that the <em>0-based indexing</em> means that, counter-intuitively, <code>:even</code> selects the first element, third element, and so on within the matched set.</p>",
"note": [{
"type": "additional",
"text": "Because <code>:even</code> is a jQuery extension and not part of the CSS specification, queries using <code>:even</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>undefined</code> instead."
},
{
"type": "additional",
"text": "Selected elements are in the order of their appearance in the document."
}
],
"examples": [{
"desc": "Finds even table rows, matching the first, third and so on (index 0, 2, 4 etc.).",
"code": "$( \"tr:even\" ).css( \"background-color\", \"#bbf\" );",
"html": "<table border=\"1\">\n <tr><td>Row with Index #0</td></tr>\n <tr><td>Row with Index #1</td></tr>\n <tr><td>Row with Index #2</td></tr>\n <tr><td>Row with Index #3</td></tr>\n</table>",
"css": "table {\n background: #eee;\n }"
}],
"categories": [
"selectors/basic-filter-selectors",
"selectors/jquery-selector-extensions",
"version/1.0",
"deprecated/deprecated-3.4"
]
},
{
"title": "event.currentTarget",
"type": "property",
"name": "event.currentTarget",
"return": "Element",
"signatures": [{
"arguments": [],
"added": "1.3"
}],
"desc": "The current DOM element within the event bubbling phase.",
"longdesc": "<p>This property will typically be equal to the <code>this</code> of the function.</p>\n <p>\n <em>If you are using <a href=\"/jQuery.proxy/\">jQuery.proxy</a> or another form of scope manipulation, <code>this</code> will be equal to whatever context you have provided, not <code>event.currentTarget</code></em>\n </p>",
"examples": [{
"desc": "Alert that currentTarget matches the `this` keyword.",
"code": "$( \"p\" ).click(function( event ) {\n alert( event.currentTarget === this ); // true\n});",
"html": "",
"css": ""
}],
"categories": [
"events/event-object",
"version/1.3"
]
},
{
"title": "event.data",
"type": "property",
"name": "event.data",
"return": "Object",
"signatures": [{
"arguments": [],
"added": "1.1"
}],
"desc": "An optional object of data passed to an event method when the current executing handler is bound.",
"longdesc": "",
"examples": [{
"desc": "Within a <code>for</code> loop, pass the value of <code>i</code> to the <code>.on()</code> method so that the current iteration's value is preserved.",
"code": "var logDiv = $( \"#log\" );\n\nfor ( var i = 0; i < 5; i++ ) {\n $( \"button\" ).eq( i ).on( \"click\", { value: i }, function( event ) {\n var msgs = [\n \"button = \" + $( this ).index(),\n \"event.data.value = \" + event.data.value,\n \"i = \" + i\n ];\n logDiv.append( msgs.join( \", \" ) + \"<br>\" );\n });\n}",
"html": "<button> 0 </button>\n<button> 1 </button>\n<button> 2 </button>\n<button> 3 </button>\n<button> 4 </button>\n\n<div id=\"log\"></div>",
"css": ""
}],
"categories": [
"events/event-object",
"version/1.1"
]
},
{
"title": "event.delegateTarget",
"type": "property",
"name": "event.delegateTarget",
"return": "Element",
"signatures": [{
"arguments": [],
"added": "1.7"
}],
"desc": "The element where the currently-called jQuery event handler was attached.",
"longdesc": "<p>This property is most often useful in delegated events attached by <a href=\"/delegate/\"><code>.delegate()</code></a> or <a href=\"/on/\"><code>.on()</code></a>, where the event handler is attached at an ancestor of the element being processed. It can be used, for example, to identify and remove event handlers at the delegation point.</p>\n <p>For non-delegated event handlers attached directly to an element, <code>event.delegateTarget</code> will always be equal to <code>event.currentTarget</code>.</p>",
"examples": [{
"desc": "When a button in any box class is clicked, change the box's background color to red.",
"code": "$( \".box\" ).on( \"click\", \"button\", function( event ) {\n $( event.delegateTarget ).css( \"background-color\", \"red\" );\n});",
"html": "",
"css": ""
}],
"categories": [
"events/event-object",
"events",
"version/1.7"
]
},
{
"title": "event.isDefaultPrevented()",
"type": "method",
"name": "event.isDefaultPrevented",
"return": "Boolean",
"signatures": [{
"arguments": [],
"added": "1.3"
}],
"desc": "Returns whether <a href=\"/event.preventDefault/\">event.preventDefault()</a> was ever called on this event object.",
"longdesc": "",
"examples": [{
"desc": "Checks whether event.preventDefault() was called.",
"code": "$( \"a\" ).click(function( event ) {\n alert( event.isDefaultPrevented() ); // false\n event.preventDefault();\n alert( event.isDefaultPrevented() ); // true\n});",
"html": "",
"css": ""
}],
"categories": [
"events/event-object",
"version/1.3"
]
},
{
"title": "event.isImmediatePropagationStopped()",
"type": "method",
"name": "event.isImmediatePropagationStopped",
"return": "Boolean",
"signatures": [{
"arguments": [],
"added": "1.3"
}],
"desc": "Returns whether event.stopImmediatePropagation() was ever called on this event object.",
"longdesc": "<p>This property was introduced in <a href=\"https://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html#Events-Event-isImmediatePropagationStopped\">DOM level 3</a>.</p>",
"examples": [{
"desc": "Checks whether event.stopImmediatePropagation() was called.",
"code": "function immediatePropStopped( event ) {\n var msg = \"\";\n if ( event.isImmediatePropagationStopped() ) {\n msg = \"called\";\n } else {\n msg = \"not called\";\n }\n $( \"#stop-log\" ).append( \"<div>\" + msg + \"</div>\" );\n}\n\n$( \"button\" ).click(function( event ) {\n immediatePropStopped( event );\n event.stopImmediatePropagation();\n immediatePropStopped( event );\n});",
"html": "<button>click me</button>\n<div id=\"stop-log\"></div>",
"css": ""
}],
"categories": [
"events/event-object",
"version/1.3"
]
},
{
"title": "event.isPropagationStopped()",
"type": "method",
"name": "event.isPropagationStopped",
"return": "Boolean",
"signatures": [{
"arguments": [],
"added": "1.3"
}],
"desc": "Returns whether <a href=\"/event.stopPropagation/\">event.stopPropagation()</a> was ever called on this event object.",
"longdesc": "<p>This event method is described in the <a href=\"https://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/events.html#Events-Event-isPropagationStopped\">W3C DOM Level 3 specification</a>.</p>",
"examples": [{
"desc": "Checks whether event.stopPropagation() was called",
"code": "function propStopped( event ) {\n var msg = \"\";\n if ( event.isPropagationStopped() ) {\n msg = \"called\";\n } else {\n msg = \"not called\";\n }\n $( \"#stop-log\" ).append( \"<div>\" + msg + \"</div>\" );\n}\n\n$( \"button\" ).click(function(event) {\n propStopped( event );\n event.stopPropagation();\n propStopped( event );\n});",
"html": "<button>click me</button>\n<div id=\"stop-log\"></div>",
"css": ""
}],
"categories": [
"events/event-object",
"version/1.3"
]
},
{
"title": "event.metaKey",
"type": "property",
"name": "event.metaKey",
"return": "Boolean",
"signatures": [{
"arguments": [],
"added": "1.0.4"
}],
"desc": "Indicates whether the META key was pressed when the event fired.",
"longdesc": "<p>Returns a boolean value (<code>true</code> or <code>false</code>) that indicates whether or not the <kbd>META</kbd> key was pressed at the time the event fired.\n This key might map to an alternative key name on some platforms.</p>\n <p>On Macintosh keyboards, the <kbd>META</kbd> key maps to the <a href=\"https://en.wikipedia.org/wiki/Command_key\">Command key (⌘)</a>.</p>\n <p>On Windows keyboards, the <kbd>META</kbd> key maps to the <a href=\"https://en.wikipedia.org/wiki/Windows_key\">Windows key</a>.</p>",
"examples": [{
"desc": "Determine whether the META key was pressed when the event fired.",
"code": "$( \"#checkMetaKey\" ).click(function( event ) {\n $( \"#display\" ).text( event.metaKey );\n});",
"html": "<button value=\"Test\" name=\"Test\" id=\"checkMetaKey\">Click me!</button>\n<div id=\"display\"></div>",
"css": "body {\n background-color: #eef;\n }\n div {\n padding: 20px;\n }"
}],
"categories": [
"events/event-object",
"version/1.0.4"
]
},
{
"title": "event.namespace",
"type": "property",
"name": "event.namespace",
"return": "String",
"signatures": [{
"arguments": [],
"added": "1.4.3"
}],
"desc": "The namespace specified when the event was triggered.",
"longdesc": "<p>This will likely be used primarily by plugin authors who wish to handle tasks differently depending on the event namespace used.</p>",
"examples": [{
"desc": "Determine the event namespace used.",
"code": "$( \"p\" ).on( \"test.something\", function( event ) {\n alert( event.namespace );\n});\n$( \"button\" ).click(function( event ) {\n $( \"p\" ).trigger( \"test.something\" );\n});",
"html": "<button>display event.namespace</button>\n<p></p>",
"css": ""
}],
"categories": [
"events/event-object",
"version/1.4.3"
]
},
{
"title": "event.pageX",
"type": "property",
"name": "event.pageX",
"return": "Number",
"signatures": [{
"arguments": [],
"added": "1.0.4"
}],
"desc": "The mouse position relative to the left edge of the document.",
"longdesc": "",
"examples": [{
"desc": "Show the mouse position relative to the left and top edges of the document (within this iframe).",
"code": "$( document ).on( \"mousemove\", function( event ) {\n $( \"#log\" ).text( \"pageX: \" + event.pageX + \", pageY: \" + event.pageY );\n});",
"html": "<div id=\"log\"></div>",
"css": "body {\n background-color: #eef;\n }\n div {\n padding: 20px;\n }"
}],
"categories": [
"events/event-object",
"version/1.0.4"
]
},
{
"title": "event.pageY",
"type": "property",
"name": "event.pageY",
"return": "Number",
"signatures": [{
"arguments": [],
"added": "1.0.4"
}],
"desc": "The mouse position relative to the top edge of the document.",
"longdesc": "",
"examples": [{
"desc": "Show the mouse position relative to the left and top edges of the document (within this iframe).",
"code": "$( document ).on( \"mousemove\", function( event ) {\n $( \"#log\" ).text( \"pageX: \" + event.pageX + \", pageY: \" + event.pageY );\n});",
"html": "<div id=\"log\"></div>",
"css": "body {\n background-color: #eef;\n }\n div {\n padding: 20px;\n }"
}],
"categories": [
"events/event-object",
"version/1.0.4"
]
},
{
"title": "event.preventDefault()",
"name": "event.preventDefault",
"type": "method",
"return": "undefined",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "If this method is called, the default action of the event will not be triggered.",
"longdesc": "<p>For example, clicked anchors will not take the browser to a new URL. We can use <a href=\"/event.isDefaultPrevented/\"><code>event.isDefaultPrevented()</code></a> to determine if this method has been called by an event handler that was triggered by this event.</p>",
"examples": [{
"desc": "Cancel the default action (navigation) of the click.",
"code": "$( \"a\" ).click(function( event ) {\n event.preventDefault();\n $( \"<div>\" )\n .append( \"default \" + event.type + \" prevented\" )\n .appendTo( \"#log\" );\n});",
"html": "<a href=\"https://jquery.com\">default click action is prevented</a>\n<div id=\"log\"></div>",
"css": ""
}],
"categories": [
"events/event-object",
"version/1.0"
]
},
{
"title": "event.relatedTarget",
"type": "property",
"name": "event.relatedTarget",
"return": "Element",
"signatures": [{
"arguments": [],
"added": "1.1.4"
}],
"desc": "The other DOM element involved in the event, if any.",
"longdesc": "<p>For <code>mouseout</code>, indicates the element being entered; for <code>mouseover</code>, indicates the element being exited. </p>",
"examples": [{
"desc": "On mouseout of anchors, alert the element type being entered.",
"code": "$( \"a\" ).mouseout(function( event ) {\n alert( event.relatedTarget.nodeName ); // \"DIV\"\n});",
"html": "",
"css": ""
}],
"categories": [
"events/event-object",
"version/1.1.4"
]
},
{
"title": "event.result",
"type": "property",
"name": "event.result",
"return": "Object",
"signatures": [{
"arguments": [],
"added": "1.3"
}],
"desc": "The last value returned by an event handler that was triggered by this event, unless the value was <code>undefined</code>.",
"longdesc": "<p>This property can be useful for getting previous return values of custom events. </p>",
"examples": [{
"desc": "Display previous handler's return value",
"code": "$( \"button\" ).click(function( event ) {\n return \"hey\";\n});\n$( \"button\" ).click(function( event ) {\n $( \"p\" ).html( event.result );\n});",
"html": "<button>display event.result</button>\n<p></p>",
"css": ""
}],
"categories": [
"events/event-object",
"version/1.3"
]
},
{
"title": "event.stopImmediatePropagation()",
"type": "method",
"name": "event.stopImmediatePropagation",
"return": "undefined",
"signatures": [{
"arguments": [],
"added": "1.3"
}],
"desc": "Keeps the rest of the handlers from being executed and prevents the event from bubbling up the DOM tree.",
"longdesc": "<p>In addition to keeping any additional handlers on an element from being executed, this method also stops the bubbling by implicitly calling <code>event.stopPropagation()</code>. To simply prevent the event from bubbling to ancestor elements but allow other event handlers to execute on the same element, we can use <code><a href=\"/event.stopPropagation/\">event.stopPropagation()</a></code> instead.</p>\n <p>Use <code><a href=\"/event.isImmediatePropagationStopped/\">event.isImmediatePropagationStopped()</a></code> to know whether this method was ever called (on that event object).</p>",
"note": [{
"type": "additional",
"text": "Since the <a href=\"/live/\"><code>.live()</code></a> method handles events once they have propagated to the top of the document, it is not possible to stop propagation of live events. Similarly, events handled by <code><a href=\"/delegate/\">.delegate()</a></code> will propagate to the elements to which they are delegated; event handlers bound on any elements below it in the DOM tree will already have been executed by the time the delegated event handler is called. These handlers, therefore, may prevent the delegated handler from triggering by calling <code><a href=\"/event.stopPropagation/\">event.stopPropagation()</a></code> or returning <code>false</code>."
}],
"examples": [{
"desc": "Prevents other event handlers from being called.",
"code": "$( \"p\" ).click(function( event ) {\n event.stopImmediatePropagation();\n});\n$( \"p\" ).click(function( event ) {\n // This function won't be executed\n $( this ).css( \"background-color\", \"#f00\" );\n});\n$( \"div\" ).click(function( event ) {\n // This function will be executed\n $( this ).css( \"background-color\", \"#f00\" );\n});",
"html": "<p>paragraph</p>\n<div>division</div>",
"css": "p {\n height: 30px;\n width: 150px;\n background-color: #ccf;\n }\n div {\n height: 30px;\n width: 150px;\n background-color: #cfc;\n }"
}],
"categories": [
"events/event-object",
"version/1.3"
]
},
{
"title": "event.stopPropagation()",
"type": "method",
"name": "event.stopPropagation",
"return": "undefined",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.",
"longdesc": "<p>We can use <code><a href=\"/event.isPropagationStopped/\">event.isPropagationStopped()</a></code> to determine if this method was ever called (on that event object). </p>\n <p>This method works for custom events triggered with <a href=\"/trigger/\">trigger()</a> as well.</p>\n <p>Note that this will not prevent other handlers <em>on the same element</em> from running. </p>",
"note": [{
"type": "additional",
"text": "Since the <a href=\"/live/\"><code>.live()</code></a> method handles events once they have propagated to the top of the document, it is not possible to stop propagation of live events. Similarly, events handled by <code><a href=\"/delegate/\">.delegate()</a></code> will propagate to the elements to which they are delegated; event handlers bound on any elements below it in the DOM tree will already have been executed by the time the delegated event handler is called. These handlers, therefore, may prevent the delegated handler from triggering by calling <code><a href=\"/event.stopPropagation/\">event.stopPropagation()</a></code> or returning <code>false</code>."
}],
"examples": [{
"desc": "Kill the bubbling on the click event.",
"code": "$( \"p\" ).click(function( event ) {\n event.stopPropagation();\n // Do something\n});",
"html": "",
"css": ""
}],
"categories": [
"events/event-object",
"version/1.0"
]
},
{
"title": "event.target",
"type": "property",
"name": "event.target",
"return": "Element",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "The DOM element that initiated the event.",
"longdesc": "<p>The <code>target</code> property can be the element that registered for the event or a descendant of it. It is often useful to compare <code>event.target</code> to <code>this</code> in order to determine if the event is being handled due to event bubbling. This property is very useful in event delegation, when events bubble.</p>",
"examples": [{
"desc": "Display the tag's name on click",
"code": "$( \"body\" ).click(function( event ) {\n $( \"#log\" ).html( \"clicked: \" + event.target.nodeName );\n});",
"html": "<div id=\"log\"></div>\n<div>\n <p>\n <strong><span>click</span></strong>\n </p>\n</div>",
"css": "span, strong, p {\n padding: 8px;\n display: block;\n border: 1px solid #999;\n }"
},
{
"desc": "Implements a simple event delegation: The click handler is added to an unordered list, and the children of its li children are hidden. Clicking one of the li children toggles (see toggle()) their children.",
"code": "function handler( event ) {\n var target = $( event.target );\n if ( target.is( \"li\" ) ) {\n target.children().toggle();\n }\n}\n$( \"ul\" ).click( handler ).find( \"ul\" ).hide();",
"html": "<ul>\n <li>item 1\n <ul>\n <li>sub item 1-a</li>\n <li>sub item 1-b</li>\n </ul>\n </li>\n <li>item 2\n <ul>\n <li>sub item 2-a</li>\n <li>sub item 2-b</li>\n </ul>\n </li>\n</ul>",
"css": ""
}
],
"categories": [
"events/event-object",
"version/1.0"
]
},
{
"title": "event.timeStamp",
"type": "property",
"name": "event.timeStamp",
"return": "Number",
"signatures": [{
"arguments": [],
"added": "1.2.6"
}],
"desc": "The difference in milliseconds between the time the browser created the event and January 1, 1970.",
"longdesc": "<p>This property can be useful for profiling event performance by getting the <code>event.timeStamp</code> value at two points in the code and noting the difference. To simply determine the current time inside an event handler, use <code>(new Date).getTime()</code> instead.</p>\n <p>Note: Due to a <a href=\"https://bugzilla.mozilla.org/show_bug.cgi?id=238041\">bug open since 2004</a>, this value is not populated correctly in Firefox and it is not possible to know the time the event was created in that browser.</p>",
"examples": [{
"desc": "Display the time since the click handler last executed.",
"code": "var last, diff;\n$( \"div\" ).click(function( event ) {\n if ( last ) {\n diff = event.timeStamp - last;\n $( \"div\" ).append( \"time since last event: \" + diff + \"<br>\" );\n } else {\n $( \"div\" ).append( \"Click again.<br>\" );\n }\n last = event.timeStamp;\n});",
"html": "<div>Click.</div>",
"css": "div {\n height: 100px;\n width: 300px;\n margin: 10px;\n background-color: #ffd;\n overflow: auto;\n }"
}],
"categories": [
"events/event-object",
"version/1.2.6"
]
},
{
"title": "event.type",
"type": "property",
"name": "event.type",
"return": "String",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Describes the nature of the event.",
"longdesc": "",
"examples": [{
"desc": "On all anchor clicks, alert the event type.",
"code": "$( \"a\" ).click(function( event ) {\n alert( event.type ); // \"click\"\n});",
"html": "",
"css": ""
}],
"categories": [
"events/event-object",
"version/1.0"
]
},
{
"title": "event.which",
"type": "property",
"name": "event.which",
"return": "Number",
"signatures": [{
"arguments": [],
"added": "1.1.3"
}],
"desc": "For key or mouse events, this property indicates the specific key or button that was pressed.",
"longdesc": "<p>The <code>event.which</code> property normalizes <code>event.keyCode</code> and <code>event.charCode</code>. It is recommended to watch <code>event.which</code> for keyboard key input. For more detail, read about <a href=\"https://developer.mozilla.org/en/DOM/event.charCode#Notes\">event.charCode on the MDN</a>. </p>\n <p><code>event.which</code> also normalizes button presses (<code>mousedown</code> and <code>mouseup</code>events), reporting <code>1</code> for left button, <code>2</code> for middle, and <code>3</code> for right. Use <code>event.which</code> instead of <code>event.button</code>. </p>",
"examples": [{
"desc": "Log which key was depressed.",
"code": "$( \"#whichkey\" ).on( \"keydown\", function( event ) {\n $( \"#log\" ).html( event.type + \": \" + event.which );\n});",
"html": "<input id=\"whichkey\" value=\"type something\">\n<div id=\"log\"></div>",
"css": ""
},
{
"desc": "Log which mouse button was depressed.",
"code": "$( \"#whichkey\" ).on( \"mousedown\", function( event ) {\n $( \"#log\" ).html( event.type + \": \" + event.which );\n});",
"html": "<input id=\"whichkey\" value=\"click here\">\n<div id=\"log\"></div>",
"css": ""
}
],
"categories": [
"events/event-object",
"version/1.1.3"
]
},
{
"title": ".fadeIn()",
"type": "method",
"name": "fadeIn",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "duration",
"default": "400",
"optional": "true",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run."
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete, called once per matched element."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "options",
"type": "PlainObject",
"desc": "A map of additional options to pass to the method.",
"properties": [{
"name": "duration",
"default": "400",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run.",
"arguments": []
},
{
"name": "easing",
"type": "String",
"default": "swing",
"desc": "A string indicating which easing function to use for the transition.",
"arguments": []
},
{
"name": "queue",
"default": "true",
"type": [
"Boolean",
"String"
],
"desc": "A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. <strong>As of jQuery 1.7</strong>, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call <code>.dequeue(\"queuename\")</code> to start it.",
"arguments": []
},
{
"name": "specialEasing",
"type": "PlainObject",
"added": "1.4",
"desc": "An object containing one or more of the CSS properties defined by the properties argument and their corresponding easing functions.",
"arguments": []
},
{
"name": "step",
"type": "Function",
"desc": "A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.",
"arguments": [{
"name": "now",
"type": "Number",
"desc": "The numeric value of the property being animated at each step"
},
{
"name": "tween",
"type": "Tween",
"desc": "An object of properties related to the animation and the element being animated. For information about the tween object and its properties, see <a href=\"/jQuery.Tween/\">jQuery.Tween</a>"
}
]
},
{
"name": "progress",
"type": "Function",
"added": "1.8",
"desc": "A function to be called after each step of the animation, only once per animated element regardless of the number of animated properties.",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "progress",
"type": "Number",
"desc": "A number from 0 to 1 indicating the progress of the animation"
},
{
"name": "remainingMs",
"type": "Number",
"desc": "A number indicating the remaining number of milliseconds until the scheduled end of the animation"
}
]
},
{
"name": "complete",
"type": "Function",
"desc": "A function that is called once the animation on an element is complete.",
"arguments": []
},
{
"name": "start",
"type": "Function",
"added": "1.8",
"desc": "A function to call when the animation on an element begins.",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
}]
},
{
"name": "done",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element completes (its Promise object is resolved).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
},
{
"name": "fail",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element fails to complete (its Promise object is rejected).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
},
{
"name": "always",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element completes or stops without completing (its Promise object is either resolved or rejected).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
}
]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "duration",
"default": "400",
"optional": "true",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run."
},
{
"name": "easing",
"type": "String",
"default": "swing",
"optional": "true",
"desc": "A string indicating which easing function to use for the transition."
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete, called once per matched element."
}
],
"added": "1.4.3"
}
],
"desc": "Display the matched elements by fading them to opaque.",
"longdesc": "<p>The <code>.fadeIn()</code> method animates the opacity of the matched elements. It is similar to the <code><a href=\"/fadeTo/\">.fadeTo()</a></code> method but that method does not unhide the element and can specify the final opacity level.</p>\n <p>Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings <code>'fast'</code> and <code>'slow'</code> can be supplied to indicate durations of <code>200</code> and <code>600</code> milliseconds, respectively. If any other string is supplied, or if the <code>duration</code> parameter is omitted, the default duration of <code>400</code> milliseconds is used.</p>\n <p>We can animate any element, such as a simple image:</p>\n <pre><code>\n&lt;div id=\"clickme\"&gt;\n Click here\n&lt;/div&gt;\n&lt;img id=\"book\" src=\"book.png\" alt=\"\" width=\"100\" height=\"123\"&gt;\n\n// With the element initially hidden, we can show it slowly:\n$( \"#clickme\" ).click(function() {\n $( \"#book\" ).fadeIn( \"slow\", function() {\n // Animation complete\n });\n});\n </code></pre>\n <figure>\n <img class=\"column three\" src=\"/resources/0042_06_33.png\" alt=\"\"/>\n <img class=\"column three\" src=\"/resources/0042_06_34.png\" alt=\"\"/>\n <img class=\"column three\" src=\"/resources/0042_06_35.png\" alt=\"\"/>\n <img class=\"column three\" src=\"/resources/0042_06_36.png\" alt=\"\"/>\n <figcaption>Figure 1 - Illustration of the <code>fadeIn()</code> effect</figcaption>\n </figure>\n <h4 id=\"easing\">Easing</h4>\n <p><strong>As of jQuery 1.4.3</strong>, an optional string naming an easing function may be used. Easing functions specify the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called <code>swing</code>, and one that progresses at a constant pace, called <code>linear</code>. More easing functions are available with the use of plug-ins, most notably the <a href=\"https://jqueryui.com\">jQuery UI suite</a>.</p>\n <h4 id=\"callback-function\">Callback Function</h4>\n <p>If supplied, the callback is fired once the animation is complete. This can be useful for stringing different animations together in sequence. The callback is not sent any arguments, but <code>this</code> is set to the DOM element being animated. If multiple elements are animated, it is important to note that the callback is executed once per matched element, not once for the animation as a whole. </p>\n <p><strong>As of jQuery 1.6</strong>, the <code><a href=\"/promise/\">.promise()</a></code> method can be used in conjunction with the <code><a href=\"/deferred.done/\">deferred.done()</a></code> method to execute a single callback for the animation as a whole when <em>all</em> matching elements have completed their animations ( See the <a href=\"/promise/#example-1\">example for .promise()</a> ). </p>",
"note": [{
"type": "additional",
"text": "All jQuery effects, including <code>.fadeIn()</code>, can be turned off globally by setting <code>jQuery.fx.off = true</code>, which effectively sets the duration to 0. For more information, see <a href=\"/jquery.fx.off/\">jQuery.fx.off</a>."
}],
"examples": [{
"desc": "Animates hidden divs to fade in one by one, completing each animation within 600 milliseconds.",
"code": "$( document.body ).click(function() {\n $( \"div:hidden\" ).first().fadeIn( \"slow\" );\n});",
"html": "<span>Click here...</span>\n<div id=\"one\"></div>\n<div id=\"two\"></div>\n<div id=\"three\"></div>",
"css": "span {\n color: red;\n cursor: pointer;\n }\n div {\n margin: 3px;\n width: 80px;\n display: none;\n height: 80px;\n float: left;\n }\n #one {\n background: #f00;\n }\n #two {\n background: #0f0;\n }\n #three {\n background: #00f;\n }"
},
{
"desc": "Fades a red block in over the text. Once the animation is done, it quickly fades in more text on top.",
"code": "$( \"a\" ).click(function() {\n $( \"div\" ).fadeIn( 3000, function() {\n $( \"span\" ).fadeIn( 100 );\n });\n return false;\n});",
"html": "<p>\n Let it be known that the party of the first part\n and the party of the second part are henceforth\n and hereto directed to assess the allegations\n for factual correctness... (<a href=\"#\">click!</a>)\n <div><span>CENSORED!</span></div>\n</p>",
"css": "p {\n position: relative;\n width: 400px;\n height: 90px;\n }\n div {\n position: absolute;\n width: 400px;\n height: 65px;\n font-size: 36px;\n text-align: center;\n color: yellow;\n background: red;\n padding-top: 25px;\n top: 0;\n left: 0;\n display: none;\n }\n span {\n display: none;\n }"
}
],
"categories": [
"effects/fading",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ".fadeOut()",
"type": "method",
"name": "fadeOut",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "duration",
"default": "400",
"optional": "true",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run."
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete, called once per matched element."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "options",
"type": "PlainObject",
"desc": "A map of additional options to pass to the method.",
"properties": [{
"name": "duration",
"default": "400",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run.",
"arguments": []
},
{
"name": "easing",
"type": "String",
"default": "swing",
"desc": "A string indicating which easing function to use for the transition.",
"arguments": []
},
{
"name": "queue",
"default": "true",
"type": [
"Boolean",
"String"
],
"desc": "A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. <strong>As of jQuery 1.7</strong>, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call <code>.dequeue(\"queuename\")</code> to start it.",
"arguments": []
},
{
"name": "specialEasing",
"type": "PlainObject",
"added": "1.4",
"desc": "An object containing one or more of the CSS properties defined by the properties argument and their corresponding easing functions.",
"arguments": []
},
{
"name": "step",
"type": "Function",
"desc": "A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.",
"arguments": [{
"name": "now",
"type": "Number",
"desc": "The numeric value of the property being animated at each step"
},
{
"name": "tween",
"type": "Tween",
"desc": "An object of properties related to the animation and the element being animated. For information about the tween object and its properties, see <a href=\"/jQuery.Tween/\">jQuery.Tween</a>"
}
]
},
{
"name": "progress",
"type": "Function",
"added": "1.8",
"desc": "A function to be called after each step of the animation, only once per animated element regardless of the number of animated properties.",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "progress",
"type": "Number",
"desc": "A number from 0 to 1 indicating the progress of the animation"
},
{
"name": "remainingMs",
"type": "Number",
"desc": "A number indicating the remaining number of milliseconds until the scheduled end of the animation"
}
]
},
{
"name": "complete",
"type": "Function",
"desc": "A function that is called once the animation on an element is complete.",
"arguments": []
},
{
"name": "start",
"type": "Function",
"added": "1.8",
"desc": "A function to call when the animation on an element begins.",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
}]
},
{
"name": "done",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element completes (its Promise object is resolved).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
},
{
"name": "fail",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element fails to complete (its Promise object is rejected).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
},
{
"name": "always",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element completes or stops without completing (its Promise object is either resolved or rejected).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
}
]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "duration",
"default": "400",
"optional": "true",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run."
},
{
"name": "easing",
"type": "String",
"default": "swing",
"optional": "true",
"desc": "A string indicating which easing function to use for the transition."
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete, called once per matched element."
}
],
"added": "1.4.3"
}
],
"desc": "Hide the matched elements by fading them to transparent.",
"longdesc": "<p>The <code>.fadeOut()</code> method animates the opacity of the matched elements. Once the opacity reaches 0, the <code>display</code> style property is set to <code>none</code>, so the element no longer affects the layout of the page.</p>\n <p>Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings <code>'fast'</code> and <code>'slow'</code> can be supplied to indicate durations of <code>200</code> and <code>600</code> milliseconds, respectively. If any other string is supplied, or if the <code>duration</code> parameter is omitted, the default duration of <code>400</code> milliseconds is used.</p>\n <p>We can animate any element, such as a simple image:</p>\n <pre><code>\n&lt;div id=\"clickme\"&gt;\n Click here\n&lt;/div&gt;\n&lt;img id=\"book\" src=\"book.png\" alt=\"\" width=\"100\" height=\"123\"&gt;\n </code></pre>\n <p>With the element initially shown, we can hide it slowly:</p>\n <pre><code>\n$( \"#clickme\" ).click(function() {\n $( \"#book\" ).fadeOut( \"slow\", function() {\n // Animation complete.\n });\n});\n </code></pre>\n <figure>\n <img class=\"column three\" src=\"/resources/0042_06_37.png\" alt=\"\"/>\n <img class=\"column three\" src=\"/resources/0042_06_38.png\" alt=\"\"/>\n <img class=\"column three\" src=\"/resources/0042_06_39.png\" alt=\"\"/>\n <img class=\"column three\" src=\"/resources/0042_06_40.png\" alt=\"\"/>\n <figcaption>Figure 1 - Illustration of the <code>fadeOut()</code> effect</figcaption>\n </figure>\n <div class=\"warning\">\n <p><strong>Note: </strong>To avoid unnecessary DOM manipulation, <code>.fadeOut()</code> will not hide an element that is already considered hidden. For information on which elements jQuery considers hidden, see <a href=\"/hidden-selector/\"> :hidden Selector</a>.</p>\n </div>\n <h4 id=\"easing\">Easing</h4>\n <p><strong>As of jQuery 1.4.3</strong>, an optional string naming an easing function may be used. Easing functions specify the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called <code>swing</code>, and one that progresses at a constant pace, called <code>linear</code>. More easing functions are available with the use of plug-ins, most notably the <a href=\"https://jqueryui.com\">jQuery UI suite</a>.</p>\n <h4 id=\"callback-function\">Callback Function</h4>\n <p>If supplied, the callback is fired once the animation is complete. This can be useful for stringing different animations together in sequence. The callback is not sent any arguments, but <code>this</code> is set to the DOM element being animated. If multiple elements are animated, it is important to note that the callback is executed once per matched element, not once for the animation as a whole.</p>\n <p><strong>As of jQuery 1.6</strong>, the <code><a href=\"/promise/\">.promise()</a></code> method can be used in conjunction with the <code><a href=\"/deferred.done/\">deferred.done()</a></code> method to execute a single callback for the animation as a whole when <em>all</em> matching elements have completed their animations ( See the <a href=\"/promise/#example-1\">example for .promise()</a> ). </p>",
"note": [{
"type": "additional",
"text": "All jQuery effects, including <code>.fadeOut()</code>, can be turned off globally by setting <code>jQuery.fx.off = true</code>, which effectively sets the duration to 0. For more information, see <a href=\"/jquery.fx.off/\">jQuery.fx.off</a>."
}],
"examples": [{
"desc": "Animates all paragraphs to fade out, completing the animation within 600 milliseconds.",
"code": "$( \"p\" ).click(function() {\n $( \"p\" ).fadeOut( \"slow\" );\n});",
"html": "<p>\n If you click on this paragraph\n you'll see it just fade away.\n</p>",
"css": "p {\n font-size: 150%;\n cursor: pointer;\n }"
},
{
"desc": "Fades out spans in one section that you click on.",
"code": "$( \"span\" ).click(function() {\n $( this ).fadeOut( 1000, function() {\n $( \"div\" ).text( \"'\" + $( this ).text() + \"' has faded!\" );\n $( this ).remove();\n });\n});\n$( \"span\" ).hover(function() {\n $( this ).addClass( \"hilite\" );\n}, function() {\n $( this ).removeClass( \"hilite\" );\n});",
"html": "<h3>Find the modifiers - <div></div></h3>\n<p>\n If you <span>really</span> want to go outside\n <span>in the cold</span> then make sure to wear\n your <span>warm</span> jacket given to you by\n your <span>favorite</span> teacher.\n</p>",
"css": "span {\n cursor: pointer;\n }\n span.hilite {\n background: yellow;\n }\n div {\n display: inline;\n color: red;\n }"
},
{
"desc": "Fades out two divs, one with a \"linear\" easing and one with the default, \"swing,\" easing.",
"code": "$( \"#btn1\" ).click(function() {\n function complete() {\n $( \"<div>\" ).text( this.id ).appendTo( \"#log\" );\n }\n $( \"#box1\" ).fadeOut( 1600, \"linear\", complete );\n $( \"#box2\" ).fadeOut( 1600, complete );\n});\n\n$( \"#btn2\" ).click(function() {\n $( \"div\" ).show();\n $( \"#log\" ).empty();\n});",
"html": "<button id=\"btn1\">fade out</button>\n<button id=\"btn2\">show</button>\n\n<div id=\"log\"></div>\n\n<div id=\"box1\" class=\"box\">linear</div>\n<div id=\"box2\" class=\"box\">swing</div>",
"css": ".box,\n button {\n float: left;\n margin: 5px 10px 5px 0;\n }\n .box {\n height: 80px;\n width: 80px;\n background: #090;\n }\n #log {\n clear: left;\n }"
}
],
"categories": [
"effects/fading",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ".fadeTo()",
"type": "method",
"name": "fadeTo",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "duration",
"type": [
"String",
"Number"
],
"desc": "A string or number determining how long the animation will run."
},
{
"name": "opacity",
"type": "Number",
"desc": "A number between 0 and 1 denoting the target opacity."
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "duration",
"type": [
"String",
"Number"
],
"desc": "A string or number determining how long the animation will run."
},
{
"name": "opacity",
"type": "Number",
"desc": "A number between 0 and 1 denoting the target opacity."
},
{
"name": "easing",
"type": "String",
"optional": "true",
"desc": "A string indicating which easing function to use for the transition."
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete."
}
],
"added": "1.4.3"
}
],
"desc": "Adjust the opacity of the matched elements.",
"longdesc": "<p>The <code>.fadeTo()</code> method animates the opacity of the matched elements. It is similar to the <code><a href=\"/fadeIn/\">.fadeIn()</a></code> method but that method unhides the element and always fades to 100% opacity.</p>\n <p>Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings <code>'fast'</code> and <code>'slow'</code> can be supplied to indicate durations of <code>200</code> and <code>600</code> milliseconds, respectively. If any other string is supplied, the default duration of <code>400</code> milliseconds is used. Unlike the other effect methods, <code>.fadeTo()</code> requires that <code>duration</code> be explicitly specified.</p>\n <p>If supplied, the callback is fired once the animation is complete. This can be useful for stringing different animations together in sequence. The callback is not sent any arguments, but <code>this</code> is set to the DOM element being animated. If multiple elements are animated, it is important to note that the callback is executed once per matched element, not once for the animation as a whole.</p>\n <p>We can animate any element, such as a simple image:</p>\n <pre><code>\n&lt;div id=\"clickme\"&gt;\n Click here\n&lt;/div&gt;\n&lt;img id=\"book\" src=\"book.png\" alt=\"\" width=\"100\" height=\"123\"&gt;\n// With the element initially shown, we can dim it slowly:\n$( \"#clickme\" ).click(function() {\n $( \"#book\" ).fadeTo( \"slow\" , 0.5, function() {\n // Animation complete.\n });\n});\n </code></pre>\n <figure>\n <img class=\"column three\" src=\"/resources/0042_06_41.png\" alt=\"\"/>\n <img class=\"column three\" src=\"/resources/0042_06_42.png\" alt=\"\"/>\n <img class=\"column three\" src=\"/resources/0042_06_43.png\" alt=\"\"/>\n <img class=\"column three\" src=\"/resources/0042_06_44.png\" alt=\"\"/>\n <figcaption>Figure 1 - Illustration of the <code>fadeTo()</code> effect</figcaption>\n </figure>\n <p>With <code>duration</code> set to <code>0</code>, this method just changes the <code>opacity</code> CSS property, so <code>.fadeTo( 0, opacity )</code> is the same as <code>.css( \"opacity\", opacity )</code>.</p>",
"note": [{
"type": "additional",
"text": "All jQuery effects, including <code>.fadeTo()</code>, can be turned off globally by setting <code>jQuery.fx.off = true</code>, which effectively sets the duration to 0. For more information, see <a href=\"/jquery.fx.off/\">jQuery.fx.off</a>."
}],
"examples": [{
"desc": "Animates first paragraph to fade to an opacity of 0.33 (33%, about one third visible), completing the animation within 600 milliseconds.",
"code": "$( \"p\" ).first().click(function() {\n $( this ).fadeTo( \"slow\", 0.33 );\n});",
"html": "<p>\nClick this paragraph to see it fade.\n</p>\n\n<p>\nCompare to this one that won't fade.\n</p>",
"css": ""
},
{
"desc": "Fade div to a random opacity on each click, completing the animation within 200 milliseconds.",
"code": "$( \"div\" ).click(function() {\n $( this ).fadeTo( \"fast\", Math.random() );\n});",
"html": "<p>And this is the library that John built...</p>\n\n<div id=\"one\"></div>\n<div id=\"two\"></div>\n<div id=\"three\"></div>",
"css": "p {\n width: 80px;\n margin: 0;\n padding: 5px;\n }\n div {\n width: 40px;\n height: 40px;\n position: absolute;\n }\n #one {\n top: 0;\n left: 0;\n background: #f00;\n }\n #two {\n top: 20px;\n left: 20px;\n background: #0f0;\n }\n #three {\n top: 40px;\n left:40px;\n background:#00f;\n }"
},
{
"desc": "Find the right answer! The fade will take 250 milliseconds and change various styles when it completes.",
"code": "var getPos = function( n ) {\n return (Math.floor( n ) * 90) + \"px\";\n};\n$( \"p\" ).each(function( n ) {\n var r = Math.floor( Math.random() * 3 );\n var tmp = $( this ).text();\n $( this ).text( $( \"p\" ).eq( r ).text() );\n $( \"p\" ).eq( r ).text( tmp );\n $( this ).css( \"left\", getPos( n ) );\n});\n$( \"div\" )\n .each(function( n ) {\n $( this ).css( \"left\", getPos( n ) );\n })\n .css( \"cursor\", \"pointer\" )\n .click( function() {\n $( this ).fadeTo( 250, 0.25, function() {\n $( this )\n .css( \"cursor\", \"\" )\n .prev()\n .css({\n \"font-weight\": \"bolder\",\n \"font-style\": \"italic\"\n });\n });\n });",
"html": "<p>Wrong</p>\n<div></div>\n<p>Wrong</p>\n<div></div>\n<p>Right!</p>\n<div></div>",
"css": "div, p {\n width: 80px;\n height: 40px;\n top: 0;\n margin: 0;\n position: absolute;\n padding-top: 8px;\n }\n p {\n background: #fcc;\n text-align: center;\n }\n div {\n background: blue;\n }"
}
],
"categories": [
"effects/fading",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ".fadeToggle()",
"type": "method",
"name": "fadeToggle",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "duration",
"default": "400",
"optional": "true",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run."
},
{
"name": "easing",
"type": "String",
"default": "swing",
"optional": "true",
"desc": "A string indicating which easing function to use for the transition."
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete, called once per matched element."
}
],
"added": "1.4.4"
},
{
"arguments": [{
"name": "options",
"type": "PlainObject",
"desc": "A map of additional options to pass to the method.",
"properties": [{
"name": "duration",
"default": "400",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run.",
"arguments": []
},
{
"name": "easing",
"type": "String",
"default": "swing",
"desc": "A string indicating which easing function to use for the transition.",
"arguments": []
},
{
"name": "queue",
"default": "true",
"type": [
"Boolean",
"String"
],
"desc": "A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. <strong>As of jQuery 1.7</strong>, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call <code>.dequeue(\"queuename\")</code> to start it.",
"arguments": []
},
{
"name": "specialEasing",
"type": "PlainObject",
"added": "1.4",
"desc": "An object containing one or more of the CSS properties defined by the properties argument and their corresponding easing functions.",
"arguments": []
},
{
"name": "step",
"type": "Function",
"desc": "A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.",
"arguments": [{
"name": "now",
"type": "Number",
"desc": "The numeric value of the property being animated at each step"
},
{
"name": "tween",
"type": "Tween",
"desc": "An object of properties related to the animation and the element being animated. For information about the tween object and its properties, see <a href=\"/jQuery.Tween/\">jQuery.Tween</a>"
}
]
},
{
"name": "progress",
"type": "Function",
"added": "1.8",
"desc": "A function to be called after each step of the animation, only once per animated element regardless of the number of animated properties.",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "progress",
"type": "Number",
"desc": "A number from 0 to 1 indicating the progress of the animation"
},
{
"name": "remainingMs",
"type": "Number",
"desc": "A number indicating the remaining number of milliseconds until the scheduled end of the animation"
}
]
},
{
"name": "complete",
"type": "Function",
"desc": "A function that is called once the animation on an element is complete.",
"arguments": []
},
{
"name": "start",
"type": "Function",
"added": "1.8",
"desc": "A function to call when the animation on an element begins.",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
}]
},
{
"name": "done",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element completes (its Promise object is resolved).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
},
{
"name": "fail",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element fails to complete (its Promise object is rejected).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
},
{
"name": "always",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element completes or stops without completing (its Promise object is either resolved or rejected).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
}
]
}],
"added": "1.4.4"
}
],
"desc": "Display or hide the matched elements by animating their opacity.",
"longdesc": "<p>The <code>.fadeToggle()</code> method animates the opacity of the matched elements. When called on a visible element, the element's <code>display</code> style property is set to <code>none</code> once the opacity reaches 0, so the element no longer affects the layout of the page.</p>\n <p>Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings <code>'fast'</code> and <code>'slow'</code> can be supplied to indicate durations of <code>200</code> and <code>600</code> milliseconds, respectively.</p>\n <h4 id=\"easing\">Easing</h4>\n <p>The string representing an easing function specifies the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called <code>swing</code>, and one that progresses at a constant pace, called <code>linear</code>. More easing functions are available with the use of plug-ins, most notably the <a href=\"https://jqueryui.com\">jQuery UI suite</a>.</p>\n <h4 id=\"callback-function\">Callback Function</h4>\n <p>If supplied, the callback is fired once the animation is complete. This can be useful for stringing different animations together in sequence. The callback is not sent any arguments, but <code>this</code> is set to the DOM element being animated. If multiple elements are animated, it is important to note that the callback is executed once per matched element, not once for the animation as a whole.</p>\n <p><strong>As of jQuery 1.6</strong>, the <code><a href=\"/promise/\">.promise()</a></code> method can be used in conjunction with the <code><a href=\"/deferred.done/\">deferred.done()</a></code> method to execute a single callback for the animation as a whole when <em>all</em> matching elements have completed their animations ( See the <a href=\"/promise/#example-1\">example for .promise()</a> ). </p>",
"note": [{
"type": "additional",
"text": "All jQuery effects, including <code>.fadeToggle()</code>, can be turned off globally by setting <code>jQuery.fx.off = true</code>, which effectively sets the duration to 0. For more information, see <a href=\"/jquery.fx.off/\">jQuery.fx.off</a>."
}],
"examples": [{
"desc": "Fades first paragraph in or out, completing the animation within 600 milliseconds and using a linear easing. Fades last paragraph in or out for 200 milliseconds, inserting a \"finished\" message upon completion.",
"code": "$( \"button\" ).first().click(function() {\n $( \"p\" ).first().fadeToggle( \"slow\", \"linear\" );\n});\n$( \"button\" ).last().click(function() {\n $( \"p\" ).last().fadeToggle( \"fast\", function() {\n $( \"#log\" ).append( \"<div>finished</div>\" );\n });\n});",
"html": "<button>fadeToggle p1</button>\n<button>fadeToggle p2</button>\n<p>This paragraph has a slow, linear fade.</p>\n<p>This paragraph has a fast animation.</p>\n<div id=\"log\"></div>",
"css": ""
}],
"categories": [
"effects",
"effects/fading",
"version/1.4.4"
]
},
{
"title": ":file Selector",
"type": "selector",
"name": "file",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Selects all elements of type file.",
"longdesc": "<p><code>:file</code> is equivalent to <code>[type=\"file\"]</code>. As with other pseudo-class selectors (those that begin with a \":\") it is recommended to precede it with a tag name or some other selector; otherwise, the universal selector (\"*\") is implied. In other words, the bare <code>$( \":file\" )</code> is equivalent to <code>$(\"*:file\" )</code>, so <code>$( \"input:file\" )</code> should be used instead. </p>",
"note": [{
"type": "additional",
"text": "Because <code>:file</code> is a jQuery extension and not part of the CSS specification, queries using <code>:file</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>[type=\"file\"]</code> instead."
}],
"examples": [{
"desc": "Finds all file inputs.",
"code": "var input = $( \"input:file\" ).css({\n background: \"yellow\",\n border: \"3px red solid\"\n});\n$( \"div\" )\n .text( \"For this type jQuery found \" + input.length + \".\" )\n .css( \"color\", \"red\" );\n$( \"form\" ).submit(function( event ) {\n event.preventDefault();\n});",
"html": "<form>\n <input type=\"button\" value=\"Input Button\">\n <input type=\"checkbox\">\n <input type=\"file\">\n <input type=\"hidden\">\n <input type=\"image\">\n <input type=\"password\">\n <input type=\"radio\">\n <input type=\"reset\">\n <input type=\"submit\">\n <input type=\"text\">\n <select><option>Option</option></select>\n <textarea></textarea>\n <button>Button</button>\n</form>\n<div></div>",
"css": "textarea {\n height: 45px;\n }"
}],
"categories": [
"selectors/form-selectors",
"selectors/jquery-selector-extensions",
"version/1.0"
]
},
{
"title": ".filter()",
"type": "method",
"name": "filter",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "selector",
"type": "Selector",
"desc": "A string containing a selector expression to match the current set of elements against."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "A function used as a test for each element in the set. <code>this</code> is the current DOM element.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "element",
"type": "Element"
}
]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "elements",
"type": "Element",
"desc": "One or more DOM elements to match the current set of elements against."
}],
"added": "1.4"
},
{
"arguments": [{
"name": "selection",
"type": "jQuery",
"desc": "An existing jQuery object to match the current set of elements against."
}],
"added": "1.4"
}
],
"desc": "Reduce the set of matched elements to those that match the selector or pass the function's test.",
"longdesc": "<p>Given a jQuery object that represents a set of DOM elements, the <code>.filter()</code> method constructs a new jQuery object from a subset of the matching elements. The supplied selector is tested against each element; all elements matching the selector will be included in the result.</p><p>Consider a page with a simple list on it:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li&gt;list item 1&lt;/li&gt;\n &lt;li&gt;list item 2&lt;/li&gt;\n &lt;li&gt;list item 3&lt;/li&gt;\n &lt;li&gt;list item 4&lt;/li&gt;\n &lt;li&gt;list item 5&lt;/li&gt;\n &lt;li&gt;list item 6&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>We can apply this method to the set of list items:</p>\n <pre><code>\n$( \"li\" ).filter( \":even\" ).css( \"background-color\", \"red\" );\n </code></pre>\n <p>The result of this call is a red background for items 1, 3, and 5, as they match the selector (recall that <code>:even</code> and <code>:odd</code> use 0-based indexing).</p>\n <h4 id=\"using-filter-function\">Using a Filter Function</h4>\n <p>The second form of this method allows us to filter elements against a function rather than a selector. For each element, if the function returns <code>true</code> (or a \"truthy\" value), the element will be included in the filtered set; otherwise, it will be excluded. Suppose we have a somewhat more involved HTML snippet:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li&gt;&lt;strong&gt;list&lt;/strong&gt; item 1 - one strong tag&lt;/li&gt;\n &lt;li&gt;&lt;strong&gt;list&lt;/strong&gt; item &lt;strong&gt;2&lt;/strong&gt; -\n two &lt;span&gt;strong tags&lt;/span&gt;&lt;/li&gt;\n &lt;li&gt;list item 3&lt;/li&gt;\n &lt;li&gt;list item 4&lt;/li&gt;\n &lt;li&gt;list item 5&lt;/li&gt;\n &lt;li&gt;list item 6&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>We can select the list items, then filter them based on their contents:</p>\n <pre><code>\n$( \"li\" )\n .filter(function( index ) {\n return $( \"strong\", this ).length === 1;\n })\n .css( \"background-color\", \"red\" );\n </code></pre>\n <p>This code will alter the first list item only, as it contains exactly one <code>&lt;strong&gt;</code> tag. Within the filter function, <code>this</code> refers to each DOM element in turn. The parameter passed to the function tells us the index of that DOM element within the set matched by the jQuery object.</p>\n <p>We can also take advantage of the <code>index</code> passed through the function, which indicates the 0-based position of the element within the unfiltered set of matched elements:</p>\n <pre><code>\n$( \"li\" )\n .filter(function( index ) {\n return index % 3 === 2;\n })\n .css( \"background-color\", \"red\" );\n </code></pre>\n <p>This alteration to the code will cause the third and sixth list items to be highlighted, as it uses the modulus operator (<code>%</code>) to select every item with an <code>index</code> value that, when divided by 3, has a remainder of <code>2</code>.</p>\n <p><strong>Note:</strong> When a CSS selector string is passed to <code>.filter()</code>, text and comment nodes will always be removed from the resulting jQuery object during the filtering process. When a specific node or array of nodes are provided, a text or comment node will be included in the resulting jQuery object only if it matches one of the nodes in the filtering array.</p>\n <note id=\"svg-support\" type=\"additional\"/>",
"examples": [{
"desc": "Change the color of all divs; then add a border to those with a \"middle\" class.",
"code": "$( \"div\" )\n .css( \"background\", \"#c8ebcc\" )\n .filter( \".middle\" )\n .css( \"border-color\", \"red\" );",
"html": "<div></div>\n<div class=\"middle\"></div>\n<div class=\"middle\"></div>\n<div class=\"middle\"></div>\n<div class=\"middle\"></div>\n<div></div>",
"css": "div {\n width: 60px;\n height: 60px;\n margin: 5px;\n float: left;\n border: 2px white solid;\n }"
},
{
"desc": "Change the color of all divs; then add a border to the second one (index == 1) and the div with an id of \"fourth.\"",
"code": "$( \"div\" )\n .css( \"background\", \"#b4b0da\" )\n .filter(function( index ) {\n return index === 1 || $( this ).attr( \"id\" ) === \"fourth\";\n })\n .css( \"border\", \"3px double red\" );",
"html": "<div id=\"first\"></div>\n<div id=\"second\"></div>\n<div id=\"third\"></div>\n<div id=\"fourth\"></div>\n<div id=\"fifth\"></div>\n<div id=\"sixth\"></div>",
"css": "div {\n width: 60px;\n height: 60px;\n margin: 5px;\n float: left;\n border: 3px white solid;\n }"
},
{
"desc": "Select all divs and filter the selection with a DOM element, keeping only the one with an id of \"unique\".",
"code": "$( \"div\" ).filter( document.getElementById( \"unique\" ) );",
"html": "",
"css": ""
},
{
"desc": "Select all divs and filter the selection with a jQuery object, keeping only the one with an id of \"unique\".",
"code": "$( \"div\" ).filter( $( \"#unique\" ) );",
"html": "",
"css": ""
}
],
"categories": [
"traversing/filtering",
"version/1.0",
"version/1.4"
]
},
{
"title": ".find()",
"type": "method",
"name": "find",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "selector",
"type": "Selector",
"desc": "A string containing a selector expression to match elements against."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "element",
"type": [
"Element",
"jQuery"
],
"desc": "An element or a jQuery object to match elements against."
}],
"added": "1.6"
}
],
"desc": "Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.",
"longdesc": "<p>Given a jQuery object that represents a set of DOM elements, the <code>.find()</code> method allows us to search through the descendants of these elements in the DOM tree and construct a new jQuery object from the matching elements. The <code>.find()</code> and <code>.children()</code> methods are similar, except that the latter only travels a single level down the DOM tree.</p>\n <p>The first signature for the <code>.find()</code>method accepts a selector expression of the same type that we can pass to the <code>$()</code> function. The elements will be filtered by testing whether they match this selector; all parts of the selector must lie inside of an element on which .find() is called. The expressions allowed include selectors like <code>&gt; p</code> which will find all the paragraphs that are children of the elements in the jQuery object.</p>\n <p>Consider a page with a basic nested list on it:</p>\n <pre><code>\n&lt;ul class=\"level-1\"&gt;\n &lt;li class=\"item-i\"&gt;I&lt;/li&gt;\n &lt;li class=\"item-ii\"&gt;II\n &lt;ul class=\"level-2\"&gt;\n &lt;li class=\"item-a\"&gt;A&lt;/li&gt;\n &lt;li class=\"item-b\"&gt;B\n &lt;ul class=\"level-3\"&gt;\n &lt;li class=\"item-1\"&gt;1&lt;/li&gt;\n &lt;li class=\"item-2\"&gt;2&lt;/li&gt;\n &lt;li class=\"item-3\"&gt;3&lt;/li&gt;\n &lt;/ul&gt;\n &lt;/li&gt;\n &lt;li class=\"item-c\"&gt;C&lt;/li&gt;\n &lt;/ul&gt;\n &lt;/li&gt;\n &lt;li class=\"item-iii\"&gt;III&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>If we begin at item II, we can find list items within it:</p>\n <pre><code>\n$( \"li.item-ii\" ).find( \"li\" ).css( \"background-color\", \"red\" );\n </code></pre>\n <p>The result of this call is a red background on items A, B, 1, 2, 3, and C. Even though item II matches the selector expression, it is not included in the results; only descendants are considered candidates for the match.</p>\n <div class=\"warning\">\n <p>Unlike most of the tree traversal methods, the selector expression is required in a call to <code>.find()</code>. If we need to retrieve all of the descendant elements, we can pass in the universal selector <code>'*'</code> to accomplish this.</p>\n </div>\n <p><a href=\"/jquery/#selector-context\">Selector context</a> is implemented with the <code>.find()</code> <code>method;</code> therefore, <code>$( \"li.item-ii\" ).find( \"li\" )</code> is equivalent to <code>$( \"li\", \"li.item-ii\" )</code>.</p>\n <p><strong>As of jQuery 1.6</strong>, we can also filter the selection with a given jQuery collection or element. With the same nested list as above, if we start with:</p>\n <pre><code>\nvar allListElements = $( \"li\" );\n </code></pre>\n <p>And then pass this jQuery object to find:</p>\n <pre><code>\n$( \"li.item-ii\" ).find( allListElements );\n </code></pre>\n <p>This will return a jQuery collection which contains only the list elements that are descendants of item II.</p>\n <p>Similarly, an element may also be passed to find:</p>\n <pre><code>\nvar item1 = $( \"li.item-1\" )[ 0 ];\n$( \"li.item-ii\" ).find( item1 ).css( \"background-color\", \"red\" );\n </code></pre>\n <p>The result of this call would be a red background on item 1.</p>\n <note id=\"svg-support\" type=\"additional\"/>",
"examples": [{
"desc": "Starts with all paragraphs and searches for descendant span elements, same as <code>$( \"p span\" )</code>",
"code": "$( \"p\" ).find( \"span\" ).css( \"color\", \"red\" );",
"html": "<p><span>Hello</span>, how are you?</p>\n<p>Me? I'm <span>good</span>.</p>",
"css": ""
},
{
"desc": "A selection using a jQuery collection of all span tags. Only spans within p tags are changed to red while others are left blue.",
"code": "var spans = $( \"span\" );\n$( \"p\" ).find( spans ).css( \"color\", \"red\" );",
"html": "<p><span>Hello</span>, how are you?</p>\n<p>Me? I'm <span>good</span>.</p>\n<div>Did you <span>eat</span> yet?</div>",
"css": "span {\n color: blue;\n }"
},
{
"desc": "Add spans around each word then add a hover and italicize words with the letter <strong>t</strong>.",
"code": "var newText = $( \"p\" ).text().split( \" \" ).join( \"</span> <span>\" );\nnewText = \"<span>\" + newText + \"</span>\";\n\n$( \"p\" )\n .html( newText )\n .find( \"span\" )\n .hover(function() {\n $( this ).addClass( \"hilite\" );\n }, function() {\n $( this ).removeClass( \"hilite\" );\n })\n .end()\n .find( \":contains('t')\" )\n .css({\n \"font-style\": \"italic\",\n \"font-weight\": \"bolder\"\n });",
"html": "<p>\n When the day is short\n find that which matters to you\n or stop believing\n</p>",
"css": "p {\n font-size: 20px;\n width: 200px;\n color: blue;\n font-weight: bold;\n margin: 0 10px;\n }\n .hilite {\n background: yellow;\n }"
}
],
"categories": [
"traversing/tree-traversal",
"version/1.0",
"version/1.6"
]
},
{
"title": ".finish()",
"type": "method",
"name": "finish",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "queue",
"type": "String",
"optional": "true",
"default": "'fx'",
"desc": "The name of the queue in which to stop animations."
}],
"added": "1.9"
}],
"desc": "Stop the currently-running animation, remove all queued animations, and complete all animations for the matched elements.",
"longdesc": "<p>When <code>.finish()</code> is called on an element, the currently-running animation and all queued animations (if any) immediately stop and their CSS properties set to their target values. All queued animations are removed.</p>\n <p>If the first argument is provided, only the animations in the queue represented by that string will be stopped.</p>\n <p>The <code>.finish()</code> method is similar to <code>.stop(true, true)</code> in that it clears the queue and the current animation jumps to its end value. It differs, however, in that <code>.finish()</code> also causes the CSS property of all <em>queued</em> animations to jump to their end values, as well.</p>\n <div class=\"warning\">\n <p>Animations may be stopped globally by setting the property <code>$.fx.off</code> to <code>true</code>. When this is done, all animation methods will immediately set elements to their final state when called, rather than displaying an effect.</p>\n </div>",
"examples": [{
"desc": "Click the Go button once to start the animation, and then click the other buttons to see how they affect the current and queued animations.",
"code": "var horiz = $( \"#path\" ).width() - 20,\n vert = $( \"#path\" ).height() - 20;\n\nvar btns = {\n bstt: function() {\n $( \"div.box\" ).stop( true, true );\n },\n bs: function() {\n $( \"div.box\" ).stop();\n },\n bsft: function() {\n $( \"div.box\" ).stop( false, true );\n },\n bf: function() {\n $( \"div.box\" ).finish();\n },\n bcf: function() {\n $( \"div.box\" ).clearQueue().finish();\n },\n bsff: function() {\n $( \"div.box\" ).stop( false, false );\n },\n bstf: function() {\n $( \"div.box\" ).stop( true, false );\n },\n bcs: function() {\n $( \"div.box\" ).clearQueue().stop();\n }\n};\n\n$( \"button.b\" ).on( \"click\", function() {\n btns[ this.id ]();\n});\n\n$( \"#go\" ).on( \"click\", function() {\n $( \".box\" )\n .clearQueue()\n .stop()\n .css({\n left: 10,\n top: 10\n })\n .animate({\n top: vert\n }, 3000 )\n .animate({\n left: horiz\n }, 3000 )\n .animate({\n top: 10\n }, 3000 );\n});",
"html": "<div class=\"box\"></div>\n<div id=\"path\">\n <button id=\"go\">Go</button>\n <br>\n <button id=\"bstt\" class=\"b\">.stop( true,true )</button>\n <button id=\"bcf\" class=\"b\">.clearQueue().finish()</button>\n <br>\n <button id=\"bstf\" class=\"b\">.stop( true, false )</button>\n <button id=\"bcs\" class=\"b\">.clearQueue().stop()</button>\n <br>\n <button id=\"bsff\" class=\"b\">.stop( false, false )</button>\n <button id=\"bs\" class=\"b\">.stop()</button>\n <br>\n <button id=\"bsft\" class=\"b\">.stop( false, true )</button>\n <br>\n <button id=\"bf\" class=\"b\">.finish()</button>\n</div>",
"css": ".box {\n position: absolute;\n top: 10px;\n left: 10px;\n width: 15px;\n height: 15px;\n background: black;\n }\n #path {\n height: 244px;\n font-size: 70%;\n border-left: 2px dashed red;\n border-bottom: 2px dashed green;\n border-right: 2px dashed blue;\n }\n button {\n width: 12em;\n display: block;\n text-align: left;\n margin: 0 auto;\n }"
}],
"categories": [
"effects/custom-effects",
"version/1.9"
]
},
{
"title": ":first-child Selector",
"type": "selector",
"name": "first-child",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.1.4"
}],
"desc": "Selects all elements that are the first child of their parent.",
"longdesc": "<p>While <a href=\"/first/\">.first()</a> matches only a single element, the <code>:first-child</code> selector can match more than one: one for each parent. This is equivalent to <code>:nth-child(1)</code>.</p>",
"examples": [{
"desc": "Finds the first span in each matched div to underline and add a hover state.",
"code": "$( \"div span:first-child\" )\n .css( \"text-decoration\", \"underline\" )\n .hover(function() {\n $( this ).addClass( \"sogreen\" );\n }, function() {\n $( this ).removeClass( \"sogreen\" );\n });",
"html": "<div>\n <span>John,</span>\n <span>Karl,</span>\n <span>Brandon</span>\n</div>\n<div>\n <span>Glen,</span>\n <span>Tane,</span>\n <span>Ralph</span>\n</div>",
"css": "span {\n color: #008;\n }\n span.sogreen {\n color: green;\n font-weight: bolder;\n }"
}],
"categories": [
"selectors/child-filter-selectors",
"version/1.1.4"
]
},
{
"title": ":first-of-type Selector",
"type": "selector",
"name": "first-of-type",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.9"
}],
"desc": "Selects all elements that are the first among siblings of the same element name.",
"longdesc": "<p>The <code>:first-of-type</code> selector matches elements that have no other element with both the same parent and the same element name coming before it in the document tree.</p>",
"examples": [{
"desc": "Find the first span in each matched div and add a class to it.",
"code": "$( \"span:first-of-type\" ).addClass( \"fot\" );",
"html": "<div>\n <span>Corey,</span>\n <span>Yehuda,</span>\n <span>Adam,</span>\n <span>Todd</span>\n</div>\n<div>\n <b>Nobody,</b>\n <span>Jörn,</span>\n <span>Scott,</span>\n <span>Timo</span>\n</div>",
"css": "span.fot {\n color: red;\n font-size: 120%;\n font-style: italic;\n }"
}],
"categories": [
"selectors/child-filter-selectors",
"version/1.9"
]
},
{
"title": ":first Selector",
"type": "selector",
"name": "first",
"return": "",
"deprecated": "3.4",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Selects the first matched DOM element.",
"longdesc": "<p><strong>As of jQuery 3.4</strong>, the <code>:first</code> pseudo-class is deprecated. Remove it from your selectors and filter the results later using <a href=\"/first/\"><code>.first()</code></a>.</p>\n <p>The <code>:first</code> pseudo-class is equivalent to <code>:eq( 0 )</code>. It could also be written as <code>:lt( 1 )</code>. While this matches only a single element, <a href=\"/first-child-selector/\">:first-child</a> can match more than one: One for each parent.</p>",
"note": [{
"type": "additional",
"text": "Because <code>:first</code> is a jQuery extension and not part of the CSS specification, queries using <code>:first</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>undefined</code> instead."
},
{
"type": "additional",
"text": "Selected elements are in the order of their appearance in the document."
}
],
"examples": [{
"desc": "Finds the first table row.",
"code": "$( \"tr:first\" ).css( \"font-style\", \"italic\" );",
"html": "<table>\n <tr><td>Row 1</td></tr>\n <tr><td>Row 2</td></tr>\n <tr><td>Row 3</td></tr>\n</table>",
"css": "td {\n color: blue;\n font-weight: bold;\n }"
}],
"categories": [
"selectors/basic-filter-selectors",
"selectors/jquery-selector-extensions",
"version/1.0",
"deprecated/deprecated-3.4"
]
},
{
"title": ".first()",
"type": "method",
"name": "first",
"return": "jQuery",
"signatures": [{
"arguments": [],
"added": "1.4"
}],
"desc": "Reduce the set of matched elements to the first in the set.",
"longdesc": "<p>Given a jQuery object that represents a set of DOM elements, the <code>.first()</code> method constructs a new jQuery object from the first element in that set.</p>\n <p>Consider a page with a simple list on it:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li&gt;list item 1&lt;/li&gt;\n &lt;li&gt;list item 2&lt;/li&gt;\n &lt;li&gt;list item 3&lt;/li&gt;\n &lt;li&gt;list item 4&lt;/li&gt;\n &lt;li&gt;list item 5&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>We can apply this method to the set of list items:</p>\n <pre><code>\n$( \"li\" ).first().css( \"background-color\", \"red\" );\n </code></pre>\n <p>The result of this call is a red background for the first item.</p>",
"examples": [{
"desc": "Highlight the first span in a paragraph.",
"code": "$( \"p span\" ).first().addClass( \"highlight\" );",
"html": "<p>\n <span>Look:</span>\n <span>This is some text in a paragraph.</span>\n <span>This is a note about it.</span>\n</p>",
"css": ".highlight{\n background-color: yellow\n }"
}],
"categories": [
"traversing/filtering",
"version/1.4"
]
},
{
"title": ":focus Selector",
"type": "selector",
"name": "focus",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.6"
}],
"desc": "Selects element if it is currently focused.",
"longdesc": "<p>As with other pseudo-class selectors (those that begin with a \":\"), it is recommended to precede <code>:focus</code> with a tag name or some other selector; otherwise, the universal selector ( \"*\" ) is implied. In other words, the bare <code>$( \":focus\" )</code> is equivalent to <code>$( \"*:focus\" )</code>. If you are looking for the currently focused element, <code>$( document.activeElement )</code> will retrieve it without having to search the whole DOM tree.</p>",
"examples": [{
"desc": "Adds the focused class to whatever element has focus",
"code": "$( \"#content\" ).delegate( \"*\", \"focus blur\", function() {\n var elem = $( this );\n setTimeout(function() {\n elem.toggleClass( \"focused\", elem.is( \":focus\" ) );\n }, 0 );\n});",
"html": "<div id=\"content\">\n <input tabIndex=\"1\">\n <input tabIndex=\"2\">\n <select tabIndex=\"3\">\n <option>select menu</option>\n </select>\n <div tabIndex=\"4\">\n a div\n </div>\n</div>",
"css": ".focused {\n background: #abcdef;\n }"
}],
"categories": [
"selectors/basic-filter-selectors",
"selectors/form-selectors",
"version/1.6"
]
},
{
"title": ".focus()",
"type": "method",
"name": "focus",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"focus\" JavaScript event, or trigger that event on an element.",
"longdesc": "<ul>\n <li>This method is a shortcut for <code>.on( \"focus\", handler )</code> in the first and second variations, and <code>.trigger( \"focus\" )</code> in the third.</li>\n <li>The <code>focus</code> event is sent to an element when it gains focus. This event is implicitly applicable to a limited set of elements, such as form elements (<code>&lt;input&gt;</code>, <code>&lt;select&gt;</code>, etc.) and links (<code>&lt;a href&gt;</code>). In recent browser versions, the event can be extended to include all element types by explicitly setting the element's <code>tabindex</code> property. An element can gain focus via keyboard commands, such as the Tab key, or by mouse clicks on the element.</li>\n <li>Elements with focus are usually highlighted in some way by the browser, for example with a dotted line surrounding the element. The focus is used to determine which element is the first to receive keyboard-related events.</li>\n </ul>\n <div class=\"warning\">\n <p>Attempting to set focus to a hidden element causes an error in Internet Explorer. Take care to only use <code>.focus()</code> on elements that are visible. To run an element's focus event handlers without setting focus to the element, use <code>.triggerHandler( \"focus\" )</code> instead of <code>.focus()</code>.</p>\n </div>\n <p>For example, consider the HTML:</p>\n <pre><code>\n&lt;form&gt;\n &lt;input id=\"target\" type=\"text\" value=\"Field 1\"&gt;\n &lt;input type=\"text\" value=\"Field 2\"&gt;\n&lt;/form&gt;\n&lt;div id=\"other\"&gt;\n Trigger the handler\n&lt;/div&gt;\n </code></pre>\n <p>The event handler can be bound to the first input field:</p>\n <pre><code>\n$( \"#target\" ).focus(function() {\n alert( \"Handler for .focus() called.\" );\n});\n </code></pre>\n <p>Now clicking on the first field, or tabbing to it from another field, displays the alert:</p>\n <p>\n <samp>Handler for .focus() called.</samp>\n </p>\n <p>We can trigger the event when another element is clicked:</p>\n <pre><code>\n$( \"#other\" ).click(function() {\n $( \"#target\" ).focus();\n});\n </code></pre>\n <p>After this code executes, clicks on <samp>Trigger the handler</samp> will also alert the message.</p>\n <p>The <code>focus</code> event does not bubble in Internet Explorer. Therefore, scripts that rely on event delegation with the <code>focus</code> event will not work consistently across browsers. As of version 1.4.2, however, jQuery works around this limitation by mapping <code>focus</code> to the <code>focusin</code> event in its event delegation methods, <a href=\"/live/\"><code>.live()</code></a> and <a href=\"/delegate/\"><code>.delegate()</code></a>.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.focus()</code> method is just a shorthand for <code>.on( \"focus\", handler )</code>, detaching is possible using <code>.off( \"focus\" )</code>."
}],
"examples": [{
"desc": "Fire focus.",
"code": "$( \"input\" ).focus(function() {\n $( this ).next( \"span\" ).css( \"display\", \"inline\" ).fadeOut( 1000 );\n});",
"html": "<p><input type=\"text\"> <span>focus fire</span></p>\n<p><input type=\"password\"> <span>focus fire</span></p>",
"css": "span {\n display: none;\n }"
},
{
"desc": "To stop people from writing in text input boxes, try:",
"code": "$( \"input[type=text]\" ).focus(function() {\n $( this ).blur();\n});",
"html": "",
"css": ""
},
{
"desc": "To focus on a login input box with id 'login' on page startup, try:",
"code": "$( document ).ready(function() {\n $( \"#login\" ).focus();\n});",
"html": "",
"css": ""
}
],
"categories": [
"events/form-events",
"forms",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ".focusin()",
"type": "method",
"name": "focusin",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.4"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"focusin\" event.",
"longdesc": "<p>This method is a shortcut for <code>.on( \"focusin\", handler )</code> in the first two variations, and <code>.trigger( \"focusin\" )</code> in the third.</p>\n <p>The <code>focusin</code> event is sent to an element when it, or any element inside of it, gains focus. This is distinct from the <a href=\"/focus/\">focus</a> event in that it supports detecting the focus event on parent elements (in other words, it supports event bubbling).</p>\n <p>This event will likely be used together with the <a href=\"/focusout/\">focusout</a> event.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.focusin()</code> method is just a shorthand for <code>.on( \"focusin\", handler )</code>, detaching is possible using <code>.off( \"focusin\" )</code>."
}],
"examples": [{
"desc": "Watch for a focus to occur within the paragraphs on the page.",
"code": "$( \"p\" ).focusin(function() {\n $( this ).find( \"span\" ).css( \"display\", \"inline\" ).fadeOut( 1000 );\n});",
"html": "<p><input type=\"text\"> <span>focusin fire</span></p>\n<p><input type=\"password\"> <span>focusin fire</span></p>",
"css": "span {\n display: none;\n }"
}],
"categories": [
"events/form-events",
"forms",
"version/1.4",
"version/1.4.3"
]
},
{
"title": ".focusout()",
"type": "method",
"name": "focusout",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.4"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"focusout\" JavaScript event.",
"longdesc": "<p>This method is a shortcut for <code>.on( \"focusout\", handler )</code> when passed arguments, and <code>.trigger( \"focusout\" )</code> when no arguments are passed.</p>\n <p>The <code>focusout</code> event is sent to an element when it, or any element inside of it, loses focus. This is distinct from the <a href=\"/blur/\">blur</a> event in that it supports detecting the loss of focus on descendant elements (in other words, it supports event bubbling).</p>\n <p>This event will likely be used together with the <a href=\"/focusin/\">focusin</a> event.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.focusout()</code> method is just a shorthand for <code>.on( \"focusout\", handler )</code>, detaching is possible using <code>.off( \"focusout\" )</code>."
}],
"examples": [{
"desc": "Watch for a loss of focus to occur inside paragraphs and note the difference between the <code>focusout</code> count and the <code>blur</code> count. (The <code>blur</code> count does not change because those events do not bubble.)",
"code": "var focus = 0,\n blur = 0;\n$( \"p\" )\n .focusout(function() {\n focus++;\n $( \"#focus-count\" ).text( \"focusout fired: \" + focus + \"x\" );\n })\n .blur(function() {\n blur++;\n $( \"#blur-count\" ).text( \"blur fired: \" + blur + \"x\" );\n });",
"html": "<div class=\"inputs\">\n <p>\n <input type=\"text\"><br>\n <input type=\"text\">\n </p>\n <p>\n <input type=\"password\">\n </p>\n</div>\n<div id=\"focus-count\">focusout fire</div>\n<div id=\"blur-count\">blur fire</div>",
"css": ".inputs {\n float: left;\n margin-right: 1em;\n }\n .inputs p {\n margin-top: 0;\n }"
}],
"categories": [
"events/form-events",
"forms",
"version/1.4",
"version/1.4.3"
]
},
{
"entries": [{
"title": ".get()",
"type": "method",
"name": "get",
"return": "Element",
"signatures": [{
"arguments": [{
"name": "index",
"type": "Integer",
"desc": "A zero-based integer indicating which element to retrieve."
}],
"added": "1.0"
}],
"desc": "Retrieve one of the elements matched by the jQuery object.",
"longdesc": "<p>The <code>.get()</code> method grants access to the DOM nodes underlying each jQuery object. If the value of <code>index</code> is out of bounds — less than the negative number of elements or equal to or greater than the number of elements — it returns <code>undefined</code>. Consider a simple unordered list:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li id=\"foo\"&gt;foo&lt;/li&gt;\n &lt;li id=\"bar\"&gt;bar&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>With an index specified, <code>.get( index )</code> retrieves a single element:</p>\n <pre><code>\nconsole.log( $( \"li\" ).get( 0 ) );\n </code></pre>\n <p>Since the index is zero-based, the first list item is returned:</p>\n <p>\n <samp>&lt;li id=\"foo\"&gt;</samp>\n </p>\n\n <p>Each jQuery object also masquerades as an array, so we can use the array dereferencing operator to get at the list item instead:</p>\n <pre><code>\nconsole.log( $( \"li\" )[ 0 ] );\n </code></pre>\n <p>However, this syntax lacks some of the additional capabilities of .get(), such as specifying a negative index:</p>\n <pre><code>\nconsole.log( $( \"li\" ).get( -1 ) );\n </code></pre>\n <p>A negative index is counted from the end of the matched set, so this example returns the last item in the list:</p>\n <p>\n <samp>&lt;li id=\"bar\"&gt;</samp>\n </p>",
"examples": [{
"desc": "Display the tag name of the click element.",
"code": "$( \"*\", document.body ).click(function( event ) {\n event.stopPropagation();\n var domElement = $( this ).get( 0 );\n $( \"span\" ).first().text( \"Clicked on - \" + domElement.nodeName );\n});",
"html": "<span>&nbsp;</span>\n<p>In this paragraph is an <span>important</span> section</p>\n<div><input type=\"text\"></div>",
"css": "span {\n color: red;\n }\n div {\n background: yellow;\n }"
}],
"categories": [
"miscellaneous/dom-element-methods",
"version/1.0"
]
},
{
"title": ".get()",
"type": "method",
"name": "get",
"return": "Array",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Retrieve the elements matched by the jQuery object.",
"longdesc": "<p>Consider a simple unordered list:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li id=\"foo\"&gt;foo&lt;/li&gt;\n &lt;li id=\"bar\"&gt;bar&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>Without a parameter, <code>.get()</code> returns an array of all of the elements:</p>\n <pre><code>\nconsole.log( $( \"li\" ).get() );\n </code></pre>\n <p>All of the matched DOM nodes are returned by this call, contained in a standard array:</p>\n <p>\n <span class=\"result\">[&lt;li id=\"foo\"&gt;, &lt;li id=\"bar\"&gt;]</span>\n </p>",
"examples": [{
"desc": "Select all divs in the document and return the DOM Elements as an Array; then use the built-in reverse() method to reverse that array.",
"code": "function display( divs ) {\n var a = [];\n for ( var i = 0; i < divs.length; i++ ) {\n a.push( divs[ i ].innerHTML );\n }\n $( \"span\" ).text( a.join(\" \") );\n}\ndisplay( $( \"div\" ).get().reverse() );",
"html": "Reversed - <span></span>\n\n<div>One</div>\n<div>Two</div>\n<div>Three</div>",
"css": "span {\n color: red;\n }"
}],
"categories": [
"miscellaneous/dom-element-methods",
"version/1.0"
]
}
]
},
{
"title": ":gt() Selector",
"type": "selector",
"name": "gt",
"return": "",
"deprecated": "3.4",
"signatures": [{
"arguments": [{
"name": "index",
"type": "Number",
"desc": "Zero-based index."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "indexFromEnd",
"type": "Integer",
"desc": "Zero-based index, counting backwards from the last element."
}],
"added": "1.8"
}
],
"desc": "Select all elements at an index greater than <code>index</code> within the matched set.",
"longdesc": "<p><strong>As of jQuery 3.4</strong>, the <code>:gt</code> pseudo-class is deprecated. Remove it from your selectors and filter the results later using <a href=\"/slice/\"><code>.slice()</code></a>. For example, <code>:gt(3)</code> can be replaced with a call to <code>.slice( 4 )</code> (the provided index needs to be increased by one).</p>\n <p>\n <strong>index-related selectors</strong>\n </p>\n <p>The index-related selector expressions (including this \"greater than\" selector) filter the set of elements that have matched the expressions that precede them. They narrow the set down based on the order of the elements within this matched set. For example, if elements are first selected with a class selector (<code>.myclass</code>) and four elements are returned, these elements are given indices 0 through 3 for the purposes of these selectors.</p>\n <p>Note that since JavaScript arrays use <em>0-based indexing</em>, these selectors reflect that fact. This is why <code>$( \".myclass:gt(1)\" )</code> selects elements after the second element in the document with the class <code>myclass</code>, rather than after the first. In contrast, <code>:nth-child(n)</code> uses <em>1-based indexing</em> to conform to the CSS specification.</p>\n <p>Prior to jQuery 1.8, the <code>:gt(index)</code> selector did <em>not</em> accept a negative value for <code>index</code></p>",
"note": [{
"type": "additional",
"text": "Because <code>:gt()</code> is a jQuery extension and not part of the CSS specification, queries using <code>:gt()</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>$(\"your-pure-css-selector\").slice(index)</code> instead."
}],
"examples": [{
"desc": "Give TD #5 and higher a yellow background and TD #8 a red text color.",
"code": "$( \"td:gt(4)\" ).css( \"backgroundColor\", \"yellow\" );\n$( \"td:gt(-2)\" ).css( \"color\", \"red\" );",
"html": "<table border=\"1\">\n <tr><td>TD #0</td><td>TD #1</td><td>TD #2</td></tr>\n <tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr>\n <tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr>\n</table>",
"css": ""
}],
"categories": [
"selectors/basic-filter-selectors",
"selectors/jquery-selector-extensions",
"version/1.0",
"deprecated/deprecated-3.4"
]
},
{
"title": "Has Attribute Selector [name]",
"type": "selector",
"name": "attributeHas",
"return": "",
"signatures": [{
"arguments": [{
"name": "attribute",
"type": "String",
"desc": "An attribute name."
}],
"added": "1.0"
}],
"desc": "Selects elements that have the specified attribute, with any value.",
"longdesc": "",
"examples": [{
"desc": "Bind a single click to divs with an id that adds the id to the div's text.",
"code": "// Using .one() so the handler is executed at most once\n// per element per event type\n$( \"div[id]\" ).one( \"click\", function() {\n var idString = $( this ).text() + \" = \" + $( this ).attr( \"id\" );\n $( this ).text( idString );\n});",
"html": "<div>no id</div>\n<div id=\"hey\">with id</div>\n<div id=\"there\">has an id</div>\n<div>nope</div>",
"css": ""
}],
"categories": [
"selectors/attribute-selectors",
"version/1.0"
]
},
{
"title": ":has() Selector",
"type": "selector",
"name": "has",
"return": "",
"signatures": [{
"arguments": [{
"name": "selector",
"type": "Selector",
"desc": "Any selector."
}],
"added": "1.1.4"
}],
"desc": "Selects elements which contain at least one element that matches the specified selector.",
"longdesc": "<p>The expression <code>$( \"div:has(p)\" )</code> matches a <code>&lt;div&gt;</code> if a <code>&lt;p&gt;</code> exists anywhere among its descendants, not just as a direct child.</p>",
"note": [{
"type": "additional",
"text": "Because <code>:has()</code> is a jQuery extension and not part of the CSS specification, queries using <code>:has()</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>$( \"your-pure-css-selector\" ).has( selector/DOMElement )</code> instead."
}],
"examples": [{
"desc": "Adds the class \"test\" to all divs that have a paragraph inside of them.",
"code": "$( \"div:has(p)\" ).addClass( \"test\" );",
"html": "<div><p>Hello in a paragraph</p></div>\n<div>Hello again! (with no paragraph)</div>",
"css": ".test {\n border: 3px inset red;\n }"
}],
"categories": [
"selectors/content-filter-selector",
"selectors/jquery-selector-extensions",
"version/1.1.4"
]
},
{
"title": ".has()",
"type": "method",
"name": "has",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "selector",
"type": "String",
"desc": "A string containing a selector expression to match elements against."
}],
"added": "1.4"
},
{
"arguments": [{
"name": "contained",
"type": "Element",
"desc": "A DOM element to match elements against."
}],
"added": "1.4"
}
],
"desc": "Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.",
"longdesc": "<p>Given a jQuery object that represents a set of DOM elements, the <code>.has()</code> method constructs a new jQuery object from a subset of the matching elements. The supplied selector is tested against the descendants of the matching elements; the element will be included in the result if any of its descendant elements matches the selector.</p>\n <p>Consider a page with a nested list as follows:</p>\n <pre><code>\n &lt;ul&gt;\n &lt;li&gt;list item 1&lt;/li&gt;\n &lt;li&gt;list item 2\n &lt;ul&gt;\n &lt;li&gt;list item 2-a&lt;/li&gt;\n &lt;li&gt;list item 2-b&lt;/li&gt;\n &lt;/ul&gt;\n &lt;/li&gt;\n &lt;li&gt;list item 3&lt;/li&gt;\n &lt;li&gt;list item 4&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>We can apply this method to the set of list items as follows:</p>\n <pre><code>\n$( \"li\" ).has( \"ul\" ).css( \"background-color\", \"red\" );\n </code></pre>\n <p>The result of this call is a red background for item 2, as it is the only <code>&lt;li&gt;</code> that has a <code>&lt;ul&gt;</code> among its descendants.</p>",
"examples": [{
"desc": "Check if an element is inside another.",
"code": "$( \"ul\" ).append( \"<li>\" +\n ( $( \"ul\" ).has( \"li\" ).length ? \"Yes\" : \"No\" ) +\n \"</li>\" );\n$( \"ul\" ).has( \"li\" ).addClass( \"full\" );",
"html": "<ul><li>Does the UL contain an LI?</li></ul>",
"css": ".full {\n border: 1px solid red;\n }"
}],
"categories": [
"traversing/filtering",
"version/1.4"
]
},
{
"title": ".hasClass()",
"type": "method",
"name": "hasClass",
"return": "Boolean",
"signatures": [{
"arguments": [{
"name": "className",
"type": "String",
"desc": "The class name to search for."
}],
"added": "1.2"
}],
"desc": "Determine whether any of the matched elements are assigned the given class.",
"longdesc": "<p>Elements may have more than one class assigned to them. In HTML, this is represented by separating the class names with a space:</p>\n <pre><code>\n&lt;div id=\"mydiv\" class=\"foo bar\"&gt;&lt;/div&gt;\n </code></pre>\n <p>The <code>.hasClass()</code> method will return <code>true</code> if the class is assigned to an element, even if other classes also are. For example, given the HTML above, the following will return <code>true</code>:</p>\n <pre><code>\n$( \"#mydiv\" ).hasClass( \"foo\" )\n </code></pre>\n <p>As would:</p>\n <pre><code>\n$( \"#mydiv\" ).hasClass( \"bar\" )\n </code></pre>\n <p>While this would return <code>false</code>:</p>\n <pre><code>\n$( \"#mydiv\" ).hasClass( \"quux\" )\n </code></pre>\n <p>As of jQuery 1.12/2.2, this method supports XML documents, including SVG.</p>",
"examples": [{
"desc": "Looks for the paragraph that contains 'selected' as a class.",
"code": "$( \"#result1\" ).append( $( \"p\" ).first().hasClass( \"selected\" ).toString() );\n$( \"#result2\" ).append( $( \"p\" ).last().hasClass( \"selected\" ).toString() );\n$( \"#result3\" ).append( $( \"p\" ).hasClass( \"selected\" ).toString() ) ;",
"html": "<p>This paragraph is black and is the first paragraph.</p>\n<p class=\"selected\">This paragraph is red and is the second paragraph.</p>\n<div id=\"result1\">First paragraph has selected class: </div>\n<div id=\"result2\">Second paragraph has selected class: </div>\n<div id=\"result3\">At least one paragraph has selected class: </div>",
"css": "p {\n margin: 8px;\n font-size: 16px;\n }\n .selected {\n color: red;\n }"
}],
"categories": [
"attributes",
"manipulation/class-attribute",
"css",
"version/1.2"
]
},
{
"title": ":header Selector",
"type": "selector",
"name": "header",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.2"
}],
"desc": "Selects all elements that are headers, like h1, h2, h3 and so on.",
"longdesc": "",
"note": [{
"type": "additional",
"text": "Because <code>:header</code> is a jQuery extension and not part of the CSS specification, queries using <code>:header</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>undefined</code> instead."
}],
"examples": [{
"desc": "Adds a background and text color to all the headers on the page.",
"code": "$( \":header\" ).css({ background: \"#ccc\", color: \"blue\" });",
"html": "<h1>Header 1</h1>\n<p>Contents 1</p>\n<h2>Header 2</h2>\n<p>Contents 2</p>",
"css": ""
}],
"categories": [
"selectors/basic-filter-selectors",
"selectors/jquery-selector-extensions",
"version/1.2"
]
},
{
"entries": [{
"title": ".height()",
"type": "method",
"name": "height",
"return": "Number",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Get the current computed height for the first element in the set of matched elements.",
"longdesc": "<p>The difference between <code>.css( \"height\" )</code> and <code>.height()</code> is that the latter returns a unit-less pixel value (for example, <code>400</code>) while the former returns a value with units intact (for example, <code>400px</code>). The <code>.height()</code> method is recommended when an element's height needs to be used in a mathematical calculation.</p>\n <figure>\n <img src=\"/resources/0042_04_01.png\"/>\n <figcaption>Figure 1 - Illustration of the measured height</figcaption>\n </figure>\n <p>This method is also able to find the height of the window and document.</p>\n <pre><code>\n// Returns height of browser viewport\n$( window ).height();\n\n// Returns height of HTML document\n$( document ).height();\n </code></pre>\n <p>Note that <code>.height()</code> will always return the content height, regardless of the value of the CSS <code>box-sizing</code> property. As of jQuery 1.8, this may require retrieving the CSS height plus <code>box-sizing</code> property and then subtracting any potential border and padding on each element when the element has <code>box-sizing: border-box</code>. To avoid this penalty, use <code>.css( \"height\" )</code> rather than <code>.height()</code>.</p>\n <div class=\"warning\">\n <p><strong>Note:</strong> Although <code>style</code> and <code>script</code> tags will report a value for <code>.width()</code> or <code>height()</code> when absolutely positioned and given <code>display:block</code>, it is strongly discouraged to call those methods on these tags. In addition to being a bad practice, the results may also prove unreliable.</p>\n </div>",
"note": [{
"type": "additional",
"text": "The number returned by dimensions-related APIs, including <code>.height()</code>, may be fractional in some cases. Code should not assume it is an integer. Also, dimensions may be incorrect when the page is zoomed by the user; browsers do not expose an API to detect this condition."
},
{
"type": "additional",
"text": "The value reported by <code>.height()</code> is not guaranteed to be accurate when the element or its parent is hidden. To get an accurate value, ensure the element is visible before using <code>.height()</code>. jQuery will attempt to temporarily show and then re-hide an element in order to measure its dimensions, but this is unreliable and (even when accurate) can significantly impact page performance. This show-and-rehide measurement feature may be removed in a future version of jQuery."
}
],
"examples": [{
"desc": "Show various heights. Note the values are from the iframe so might be smaller than you expected. The yellow highlight shows the iframe body.",
"code": "function showHeight( element, height ) {\n $( \"div\" ).text( \"The height for the \" + element + \" is \" + height + \"px.\" );\n}\n$( \"#getp\" ).click(function() {\n showHeight( \"paragraph\", $( \"p\" ).height() );\n});\n$( \"#getd\" ).click(function() {\n showHeight( \"document\", $( document ).height() );\n});\n$( \"#getw\" ).click(function() {\n showHeight( \"window\", $( window ).height() );\n});",
"html": "<button id=\"getp\">Get Paragraph Height</button>\n<button id=\"getd\">Get Document Height</button>\n<button id=\"getw\">Get Window Height</button>\n\n<div>&nbsp;</div>\n<p>\n Sample paragraph to test height\n</p>",
"css": "body {\n background: yellow;\n }\n button {\n font-size: 12px;\n margin: 2px;\n }\n p {\n width: 150px;\n border: 1px red solid;\n }\n div {\n color: red;\n font-weight: bold;\n }"
}],
"categories": [
"css",
"dimensions",
"manipulation/style-properties",
"version/1.0",
"version/1.4.1"
]
},
{
"title": "",
"type": "method",
"name": "height",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "value",
"type": [
"String",
"Number"
],
"desc": "An integer representing the number of pixels, or an integer with an optional unit of measure appended (as a string)."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "A function returning the height to set. Receives the index position of the element in the set and the old height as arguments. Within the function, <code>this</code> refers to the current element in the set.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "height",
"type": "Integer"
}
]
}],
"added": "1.4.1"
}
],
"desc": "Set the CSS height of every matched element.",
"longdesc": "<p>When calling <code>.height(value)</code>, the value can be either a string (number and unit) or a number. If only a number is provided for the value, jQuery assumes a pixel unit. If a string is provided, however, a valid CSS measurement must be provided for the height (such as <code>100px</code>, <code>50%</code>, or <code>auto</code>). Note that in modern browsers, the CSS height property does not include padding, border, or margin.</p>\n <p>If no explicit unit was specified (like 'em' or '%') then \"px\" is concatenated to the value.</p>\n <p>Note that <code>.height(value)</code> sets the content height of the box regardless of the value of the CSS <code>box-sizing</code> property.</p>",
"examples": [{
"desc": "To set the height of each div on click to 30px plus a color change.",
"code": "$( \"div\" ).one( \"click\", function() {\n $( this ).height( 30 ).css({\n cursor: \"auto\",\n backgroundColor: \"green\"\n });\n});",
"html": "<div></div>\n<div></div>\n<div></div>\n<div></div>\n<div></div>",
"css": "div {\n width: 50px;\n height: 70px;\n float: left;\n margin: 5px;\n background: rgb(255,140,0);\n cursor: pointer;\n }"
}],
"categories": [
"css",
"dimensions",
"manipulation/style-properties",
"version/1.0",
"version/1.4.1"
]
}
]
},
{
"title": ":hidden Selector",
"type": "selector",
"name": "hidden",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Selects all elements that are hidden.",
"longdesc": "<p>Elements can be considered hidden for several reasons:</p>\n <ul>\n <li>They have a CSS <code>display</code> value of <code>none</code>.</li>\n <li>They are form elements with <code>type=\"hidden\"</code>.</li>\n <li>Their width and height are explicitly set to 0.</li>\n <li>An ancestor element is hidden, so the element is not shown on the page.</li>\n </ul>\n <p>Elements with <code>visibility: hidden</code> or <code>opacity: 0</code> are considered to be visible, since they still consume space in the layout. During animations that hide an element, the element is considered to be visible until the end of the animation.</p>\n <p>Elements that are not in a document are not considered to be visible; jQuery does not have a way to know if they will be visible when appended to a document since it depends on the applicable styles.</p>\n <p>This selector is the opposite of the <a href=\"/visible-selector/\"><code>:visible</code></a> selector. So, every element selected by <code>:hidden</code> isn't selected by <code>:visible</code> and vice versa.</p>\n <p>During animations to show an element, the element is considered to be visible at the start of the animation.</p>\n <p>How <code>:hidden</code> is determined was changed in jQuery 1.3.2. An element is assumed to be hidden if it or any of its parents consumes no space in the document. CSS visibility isn't taken into account (therefore <code>$( elem ).css( \"visibility\", \"hidden\" ).is( \":hidden\" ) == false</code>). The <a href=\"https://blog.jquery.com/2009/02/20/jquery-1-3-2-released/\">release notes</a> outline the changes in more detail.</p>\n <p>jQuery 3 slightly modifies the meaning of <code>:hidden</code> (and therefore of <a href=\"/visible-selector/\"><code>:visible</code></a>). Starting with this version, elements will be considered <code>:hidden</code> if they don't have any layout boxes. For example, <code>br</code> elements and inline elements with no content will not be selected by the <code>:hidden</code> selector.</p>",
"note": [{
"type": "additional",
"text": "Because <code>:hidden</code> is a jQuery extension and not part of the CSS specification, queries using <code>:hidden</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>undefined</code> instead."
},
{
"type": "additional",
"text": "Using this selector heavily can have performance implications, as it may force the browser to re-render the page before it can determine visibility. Tracking the visibility of elements via other methods, using a class for example, can provide better performance."
}
],
"examples": [{
"desc": "Shows all hidden divs and counts hidden inputs.",
"code": "// In some browsers :hidden includes head, title, script, etc...\nvar hiddenElements = $( \"body\" ).find( \":hidden\" ).not( \"script\" );\n\n$( \"span\" ).first().text( \"Found \" + hiddenElements.length + \" hidden elements total.\" );\n$( \"div:hidden\" ).show( 3000 );\n$( \"span\" ).last().text( \"Found \" + $( \"input:hidden\" ).length + \" hidden inputs.\" );",
"html": "<span></span>\n<div></div>\n<div style=\"display:none;\">Hider!</div>\n<div></div>\n\n<div class=\"starthidden\">Hider!</div>\n<div></div>\n\n<form>\n <input type=\"hidden\">\n <input type=\"hidden\">\n <input type=\"hidden\">\n</form>\n\n<span></span>",
"css": "div {\n width: 70px;\n height: 40px;\n background: #e7f;\n margin: 5px;\n float: left;\n }\n span {\n display: block;\n clear: left;\n color: red;\n }\n .starthidden {\n display: none;\n }"
}],
"categories": [
"selectors/jquery-selector-extensions",
"version/1.0",
"selectors/visibility-filter-selectors"
]
},
{
"title": ".hide()",
"type": "method",
"name": "hide",
"return": "jQuery",
"signatures": [{
"arguments": [],
"added": "1.0"
},
{
"arguments": [{
"name": "duration",
"default": "400",
"optional": "true",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run."
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete, called once per matched element."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "options",
"type": "PlainObject",
"desc": "A map of additional options to pass to the method.",
"properties": [{
"name": "duration",
"default": "400",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run.",
"arguments": []
},
{
"name": "easing",
"type": "String",
"default": "swing",
"desc": "A string indicating which easing function to use for the transition.",
"arguments": []
},
{
"name": "queue",
"default": "true",
"type": [
"Boolean",
"String"
],
"desc": "A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. <strong>As of jQuery 1.7</strong>, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call <code>.dequeue(\"queuename\")</code> to start it.",
"arguments": []
},
{
"name": "specialEasing",
"type": "PlainObject",
"added": "1.4",
"desc": "An object containing one or more of the CSS properties defined by the properties argument and their corresponding easing functions.",
"arguments": []
},
{
"name": "step",
"type": "Function",
"desc": "A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.",
"arguments": [{
"name": "now",
"type": "Number",
"desc": "The numeric value of the property being animated at each step"
},
{
"name": "tween",
"type": "Tween",
"desc": "An object of properties related to the animation and the element being animated. For information about the tween object and its properties, see <a href=\"/jQuery.Tween/\">jQuery.Tween</a>"
}
]
},
{
"name": "progress",
"type": "Function",
"added": "1.8",
"desc": "A function to be called after each step of the animation, only once per animated element regardless of the number of animated properties.",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "progress",
"type": "Number",
"desc": "A number from 0 to 1 indicating the progress of the animation"
},
{
"name": "remainingMs",
"type": "Number",
"desc": "A number indicating the remaining number of milliseconds until the scheduled end of the animation"
}
]
},
{
"name": "complete",
"type": "Function",
"desc": "A function that is called once the animation on an element is complete.",
"arguments": []
},
{
"name": "start",
"type": "Function",
"added": "1.8",
"desc": "A function to call when the animation on an element begins.",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
}]
},
{
"name": "done",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element completes (its Promise object is resolved).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
},
{
"name": "fail",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element fails to complete (its Promise object is rejected).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
},
{
"name": "always",
"type": "Function",
"added": "1.8",
"desc": "A function to be called when the animation on an element completes or stops without completing (its Promise object is either resolved or rejected).",
"arguments": [{
"name": "animation",
"type": "Promise",
"desc": "An enhanced Promise object with additional properties for the animation"
},
{
"name": "jumpedToEnd",
"type": "Boolean",
"desc": "Indicates whether the animation jumped to the end"
}
]
}
]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "duration",
"default": "400",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run."
},
{
"name": "easing",
"type": "String",
"default": "swing",
"optional": "true",
"desc": "A string indicating which easing function to use for the transition."
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete, called once per matched element."
}
],
"added": "1.4.3"
}
],
"desc": "Hide the matched elements.",
"longdesc": "<p>With no parameters, the <code>.hide()</code> method is the simplest way to hide an element:</p>\n <pre><code>\n$( \".target\" ).hide();\n </code></pre>\n <p>The matched elements will be hidden immediately, with no animation. This is roughly equivalent to calling <code>.css( \"display\", \"none\" )</code>, except that the value of the <code>display</code> property is saved in jQuery's data cache so that <code>display</code> can later be restored to its initial value. If an element has a <code>display</code> value of <code>inline</code> and is hidden then shown, it will once again be displayed <code>inline</code>.</p>\n <p>When a duration, a plain object, or a \"complete\" function is provided, <code>.hide()</code> becomes an animation method. The <code>.hide()</code> method animates the width, height, and opacity of the matched elements simultaneously. When these properties reach 0, the <code>display</code> style property is set to <code>none</code> to ensure that the element no longer affects the layout of the page.</p>\n <p>Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings <code>'fast'</code> and <code>'slow'</code> can be supplied to indicate durations of <code>200</code> and <code>600</code> milliseconds, respectively.</p>\n <p>Note that <code>.hide()</code> is fired immediately and will override the animation queue if no duration or a duration of 0 is specified.</p>\n <p>As of jQuery <strong>1.4.3</strong>, an optional string naming an easing function may be used. Easing functions specify the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called <code>swing</code>, and one that progresses at a constant pace, called <code>linear</code>. More easing functions are available with the use of plug-ins, most notably the <a href=\"https://jqueryui.com\">jQuery UI suite</a>.</p>\n <p>If supplied, the callback is fired once the animation is complete. This can be useful for stringing different animations together in sequence. The callback is not sent any arguments, but <code>this</code> is set to the DOM element being animated. If multiple elements are animated, it is important to note that the callback is executed once per matched element, not once for the animation as a whole.</p>\n <div class=\"warning\">\n <p><strong>Note:</strong> This method may cause performance issues, especially when used on many elements. If you're encountering such issues, use performance testing tools to determine whether this method is causing them. Moreover, this method can cause problems with responsive layouts if the display value differs at different viewport sizes.</p>\n </div>\n <p>We can animate any element, such as a simple image:</p>\n <pre><code>\n&lt;div id=\"clickme\"&gt;\n Click here\n&lt;/div&gt;\n&lt;img id=\"book\" src=\"book.png\" alt=\"\" width=\"100\" height=\"123\"&gt;\n </code></pre>\n <pre><code>\n// With the element initially shown, we can hide it slowly:\n$( \"#clickme\" ).click(function() {\n $( \"#book\" ).hide( \"slow\", function() {\n alert( \"Animation complete.\" );\n });\n});\n </code></pre>\n <figure>\n <img class=\"column three\" src=\"/resources/0042_06_05.png\" alt=\"\"/>\n <img class=\"column three\" src=\"/resources/0042_06_06.png\" alt=\"\"/>\n <img class=\"column three\" src=\"/resources/0042_06_07.png\" alt=\"\"/>\n <img class=\"column three\" src=\"/resources/0042_06_08.png\" alt=\"\"/>\n <figcaption>Figure 1 - Illustration of the <code>hide()</code> effect</figcaption>\n </figure>",
"note": [{
"type": "additional",
"text": "All jQuery effects, including <code>.hide()</code>, can be turned off globally by setting <code>jQuery.fx.off = true</code>, which effectively sets the duration to 0. For more information, see <a href=\"/jquery.fx.off/\">jQuery.fx.off</a>."
}],
"examples": [{
"desc": "Hides all paragraphs then the link on click.",
"code": "$( \"p\" ).hide();\n$( \"a\" ).click(function( event ) {\n event.preventDefault();\n $( this ).hide();\n});",
"html": "<p>Hello</p>\n<a href=\"#\">Click to hide me too</a>\n<p>Here is another paragraph</p>",
"css": ""
},
{
"desc": "Animates all shown paragraphs to hide slowly, completing the animation within 600 milliseconds.",
"code": "$( \"button\" ).click(function() {\n $( \"p\" ).hide( \"slow\" );\n});",
"html": "<button>Hide 'em</button>\n<p>Hiya</p>\n<p>Such interesting text, eh?</p>",
"css": "p {\n background: #dad;\n font-weight: bold;\n }"
},
{
"desc": "Animates all spans (words in this case) to hide fastly, completing each animation within 200 milliseconds. Once each animation is done, it starts the next one.",
"code": "$( \"#hider\" ).click(function() {\n $( \"span:last-child\" ).hide( \"fast\", function() {\n // Use arguments.callee so we don't need a named function\n $( this ).prev().hide( \"fast\", arguments.callee );\n });\n});\n$( \"#shower\" ).click(function() {\n $( \"span\" ).show( 2000 );\n});",
"html": "<button id=\"hider\">Hide</button>\n<button id=\"shower\">Show</button>\n<div>\n <span>Once</span> <span>upon</span> <span>a</span>\n <span>time</span> <span>there</span> <span>were</span>\n <span>three</span> <span>programmers...</span>\n</div>",
"css": "span {\n background: #def3ca;\n padding: 3px;\n float: left;\n }"
},
{
"desc": "Hides the divs when clicked over 2 seconds, then removes the div element when its hidden. Try clicking on more than one box at a time.",
"code": "for ( var i = 0; i < 5; i++ ) {\n $( \"<div>\" ).appendTo( document.body );\n}\n$( \"div\" ).click(function() {\n $( this ).hide( 2000, function() {\n $( this ).remove();\n });\n});",
"html": "<div></div>",
"css": "div {\n background: #ece023;\n width: 30px;\n height: 40px;\n margin: 2px;\n float: left;\n }"
}
],
"categories": [
"effects/basics",
"version/1.0",
"version/1.4.3"
]
},
{
"entries": [{
"title": ".hover()",
"type": "method",
"name": "hover",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handlerIn",
"type": "Function",
"desc": "A function to execute when the mouse pointer enters the element.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
},
{
"name": "handlerOut",
"type": "Function",
"desc": "A function to execute when the mouse pointer leaves the element.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.0"
}],
"desc": "Bind two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements.",
"longdesc": "<p>The <code>.hover()</code> method binds handlers for both <code>mouseenter</code> and <code>mouseleave</code> events. You can use it to simply apply behavior to an element during the time the mouse is within the element.</p>\n <p>Calling <code>$( selector ).hover( handlerIn, handlerOut )</code> is shorthand for:</p>\n <pre><code>\n$( selector ).mouseenter( handlerIn ).mouseleave( handlerOut );\n </code></pre>\n <p>See the discussions for <code><a href=\"/mouseenter/\">.mouseenter()</a></code> and <code><a href=\"/mouseleave/\">.mouseleave()</a></code> for more details.</p>",
"examples": [{
"desc": "To add a special style to list items that are being hovered over, try:",
"code": "$( \"li\" ).hover(\n function() {\n $( this ).append( $( \"<span> ***</span>\" ) );\n }, function() {\n $( this ).find( \"span\" ).last().remove();\n }\n);\n\n$( \"li.fade\" ).hover(function() {\n $( this ).fadeOut( 100 );\n $( this ).fadeIn( 500 );\n});",
"html": "<ul>\n <li>Milk</li>\n <li>Bread</li>\n <li class=\"fade\">Chips</li>\n <li class=\"fade\">Socks</li>\n</ul>",
"css": "ul {\n margin-left: 20px;\n color: blue;\n }\n li {\n cursor: default;\n }\n span {\n color: red;\n }"
},
{
"desc": "To add a special style to table cells that are being hovered over, try:",
"code": "$( \"td\" ).hover(\n function() {\n $( this ).addClass( \"hover\" );\n }, function() {\n $( this ).removeClass( \"hover\" );\n }\n);",
"html": "",
"css": ""
},
{
"desc": "To unbind the above example use:",
"code": "$( \"td\" ).off( \"mouseenter mouseleave\" );",
"html": "",
"css": ""
}
],
"categories": [
"events/mouse-events",
"version/1.0"
]
},
{
"title": "",
"type": "method",
"name": "hover",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handlerInOut",
"type": "Function",
"desc": "A function to execute when the mouse pointer enters or leaves the element.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.4"
}],
"desc": "Bind a single handler to the matched elements, to be executed when the mouse pointer enters or leaves the elements.",
"longdesc": "<p>The <code>.hover()</code> method, when passed a single function, will execute that handler for both <code>mouseenter</code> and <code>mouseleave</code> events. This allows the user to use jQuery's various toggle methods within the handler or to respond differently within the handler depending on the <code>event.type</code>.</p>\n <p>Calling <code>$(selector).hover(handlerInOut)</code> is shorthand for:</p>\n <pre><code>\n$( selector ).on( \"mouseenter mouseleave\", handlerInOut );\n </code></pre>\n <p>See the discussions for <code><a href=\"/mouseenter/\">.mouseenter()</a></code> and <code><a href=\"/mouseleave/\">.mouseleave()</a></code> for more details.</p>",
"examples": [{
"desc": "Slide the next sibling LI up or down on hover, and toggle a class.",
"code": "$( \"li\" )\n .filter( \":odd\" )\n .hide()\n .end()\n .filter( \":even\" )\n .hover(function() {\n $( this )\n .toggleClass( \"active\" )\n .next()\n .stop( true, true )\n .slideToggle();\n });",
"html": "<ul>\n <li>Milk</li>\n <li>White</li>\n <li>Carrots</li>\n <li>Orange</li>\n <li>Broccoli</li>\n <li>Green</li>\n</ul>",
"css": "ul {\n margin-left: 20px;\n color: blue;\n }\n li {\n cursor: default;\n }\n li.active {\n background: black;\n color: white;\n }\n span {\n color:red;\n }"
}],
"categories": [
"events/mouse-events",
"version/1.0"
]
}
]
},
{
"entries": [{
"title": ".html()",
"type": "method",
"name": "html",
"return": "String",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Get the HTML contents of the first element in the set of matched elements.",
"longdesc": "<p>This method is not available on XML documents.</p>\n <p>In an HTML document, <code>.html()</code> can be used to get the contents of any element. If the selector expression matches more than one element, only the first match will have its HTML content returned. Consider this code:</p>\n <pre><code>\n$( \"div.demo-container\" ).html();\n </code></pre>\n <p>In order for the following <code>&lt;div&gt;</code>'s content to be retrieved, it would have to be the first one with <code>class=\"demo-container\"</code> in the document:</p>\n <pre><code>\n&lt;div class=\"demo-container\"&gt;\n &lt;div class=\"demo-box\"&gt;Demonstration Box&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>The result would look like this:</p>\n <pre><code>\n&lt;div class=\"demo-box\"&gt;Demonstration Box&lt;/div&gt;\n </code></pre>\n <p>This method uses the browser's <code>innerHTML</code> property. Some browsers may not return HTML that exactly replicates the HTML source in an original document. For example, Internet Explorer sometimes leaves off the quotes around attribute values if they contain only alphanumeric characters.</p>",
"note": [{
"type": "additional",
"text": "By design, any jQuery constructor or method that accepts an HTML string — <a href=\"/jQuery/\">jQuery()</a>, <a href=\"/append/\">.append()</a>, <a href=\"/after/\">.after()</a>, etc. — can potentially execute code. This can occur by injection of script tags or use of HTML attributes that execute code (for example, <code>&lt;img onload=\"\"&gt;</code>). Do not use these methods to insert strings obtained from untrusted sources such as URL query parameters, cookies, or form inputs. Doing so can introduce cross-site-scripting (XSS) vulnerabilities. Remove or escape any user input before adding content to the document."
}],
"examples": [{
"desc": "Click a paragraph to convert it from html to text.",
"code": "$( \"p\" ).click(function() {\n var htmlString = $( this ).html();\n $( this ).text( htmlString );\n});",
"html": "<p>\n <b>Click</b> to change the <span id=\"tag\">html</span>\n</p>\n<p>\n to a <span id=\"text\">text</span> node.\n</p>\n<p>\n This <button name=\"nada\">button</button> does nothing.\n</p>",
"css": "p {\n margin: 8px;\n font-size: 20px;\n color: blue;\n cursor: pointer;\n }\n b {\n text-decoration: underline;\n }\n button {\n cursor: pointer;\n }"
}],
"categories": [
"attributes",
"manipulation/dom-insertion-inside",
"version/1.0",
"version/1.4"
]
},
{
"title": "",
"type": "method",
"name": "html",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "htmlString",
"type": "htmlString",
"desc": "A string of HTML to set as the content of each matched element."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "A function returning the HTML content to set. Receives the\n index position of the element in the set and the old HTML value as arguments.\n jQuery empties the element before calling the function;\n use the oldhtml argument to reference the previous content.\n Within the function, <code>this</code> refers to the current element in the set.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "oldhtml",
"type": "htmlString"
}
]
}],
"added": "1.4"
}
],
"desc": "Set the HTML contents of each element in the set of matched elements.",
"longdesc": "<p>The <code>.html()</code> method is not available in XML documents. </p>\n <p>When <code>.html()</code> is used to set an element's content,\n any content that was in that element is completely replaced by the new content.\n Additionally, jQuery removes other constructs such as data and event\n handlers from child elements before replacing those elements with the new content.</p>\n\n <p>Consider the following HTML:</p>\n <pre><code>\n&lt;div class=\"demo-container\"&gt;\n &lt;div class=\"demo-box\"&gt;Demonstration Box&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>The content of <code>&lt;div class=\"demo-container\"&gt;</code> can be set like this:</p>\n <pre><code>\n$( \"div.demo-container\" )\n .html( \"&lt;p&gt;All new content. &lt;em&gt;You bet!&lt;/em&gt;&lt;/p&gt;\" );\n </code></pre>\n <p>That line of code will replace everything inside <code>&lt;div class=\"demo-container\"&gt;</code>:</p>\n <pre><code>\n&lt;div class=\"demo-container\"&gt;\n &lt;p&gt;All new content. &lt;em&gt;You bet!&lt;/em&gt;&lt;/p&gt;\n&lt;/div&gt;\n </code></pre>\n <p>As of jQuery 1.4, the <code>.html()</code> method allows the HTML content to be set by passing in a function.</p>\n <pre><code>\n$( \"div.demo-container\" ).html(function() {\n var emphasis = \"&lt;em&gt;\" + $( \"p\" ).length + \" paragraphs!&lt;/em&gt;\";\n return \"&lt;p&gt;All new content for \" + emphasis + \"&lt;/p&gt;\";\n});\n </code></pre>\n <p>Given a document with six paragraphs, this example will set the HTML of <code>&lt;div class=\"demo-container\"&gt;</code> to <code>&lt;p&gt;All new content for &lt;em&gt;6 paragraphs!&lt;/em&gt;&lt;/p&gt;</code>.</p>\n <p>This method uses the browser's <code>innerHTML</code> property. Some browsers may not generate a DOM that exactly replicates the HTML source provided. For example, Internet Explorer prior to version 8 will convert all <code>href</code> properties on links to absolute URLs, and Internet Explorer prior to version 9 will not correctly handle HTML5 elements without the addition of a separate <a href=\"https://code.google.com/p/html5shiv/\">compatibility layer</a>.</p>\n <p>To set the content of a <code>&lt;script&gt;</code> element, which does not contain HTML, use the <a href=\"/text/\"><code>.text()</code></a> method and not <code>.html()</code>.</p>\n <p><strong>Note:</strong> In Internet Explorer up to and including version 9, setting the text content of an HTML element may corrupt the text nodes of its children that are being removed from the document as a result of the operation. If you are keeping references to these DOM elements and need them to be unchanged, use <code>.empty().html( string )</code> instead of <code>.html(string)</code> so that the elements are removed from the document before the new string is assigned to the element.</p>",
"examples": [{
"desc": "Add some html to each div.",
"code": "$( \"div\" ).html( \"<span class='red'>Hello <b>Again</b></span>\" );",
"html": "<span>Hello</span>\n<div></div>\n<div></div>\n<div></div>",
"css": ".red {\n color: red;\n }"
},
{
"desc": "Add some html to each div then immediately do further manipulations to the inserted html.",
"code": "$( \"div\" ).html( \"<b>Wow!</b> Such excitement...\" );\n$( \"div b\" )\n .append( document.createTextNode( \"!!!\" ) )\n .css( \"color\", \"red\" );",
"html": "<div></div>\n<div></div>\n<div></div>",
"css": "div {\n color: blue;\n font-size: 18px;\n }"
}
],
"categories": [
"attributes",
"manipulation/dom-insertion-inside",
"version/1.0",
"version/1.4"
]
}
]
},
{
"title": "ID Selector (\"#id\")",
"type": "selector",
"name": "id",
"return": "",
"signatures": [{
"arguments": [{
"name": "id",
"type": "String",
"desc": "An ID to search for, specified via the id attribute of an element."
}],
"added": "1.0"
}],
"desc": "Selects a single element with the given id attribute.",
"longdesc": "<p>For id selectors, jQuery uses the JavaScript function <code>document.getElementById()</code>, which is extremely efficient. When another selector is attached to the id selector, such as <code>h2#pageTitle</code>, jQuery performs an additional check before identifying the element as a match.</p>\n <p>Calling <code>jQuery()</code> (or <code>$()</code>) with an id selector as its argument will return a jQuery object containing a collection of either zero or one DOM element.</p>\n <p>Each <code>id</code> value must be used only once within a document. If more than one element has been assigned the same ID, queries that use that ID will only select the first matched element in the DOM. This behavior should not be relied on, however; a document with more than one element using the same ID is invalid.</p>\n <p>If the id contains characters like periods or colons you have to <a href=\"https://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation/\">escape those characters with backslashes</a>.</p>",
"examples": [{
"desc": "Select the element with the id \"myDiv\" and give it a red border.",
"code": "$( \"#myDiv\" ).css( \"border\", \"3px solid red\" );",
"html": "<div id=\"notMe\"><p>id=\"notMe\"</p></div>\n<div id=\"myDiv\">id=\"myDiv\"</div>",
"css": "div {\n width: 90px;\n height: 90px;\n float: left;\n padding: 5px;\n margin: 5px;\n background-color: #eee;\n }"
},
{
"desc": "Select the element with the id \"myID.entry[1]\" and give it a red border. Note how certain characters must be escaped with backslashes.",
"code": "$( \"#myID\\\\.entry\\\\[1\\\\]\" ).css( \"border\", \"3px solid red\" );",
"html": "<div id=\"myID.entry[0]\">id=\"myID.entry[0]\"</div>\n<div id=\"myID.entry[1]\">id=\"myID.entry[1]\"</div>\n<div id=\"myID.entry[2]\">id=\"myID.entry[2]\"</div>",
"css": "div {\n width: 300px;\n float: left;\n padding: 2px;\n margin: 3px;\n background-color: #eee;\n }"
}
],
"categories": [
"selectors/basic-css-selectors",
"version/1.0"
]
},
{
"title": ":image Selector",
"type": "selector",
"name": "image",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Selects all elements of type image.",
"longdesc": "<p><code>:image</code> is equivalent to <code>[type=\"image\"]</code></p>",
"note": [{
"type": "additional",
"text": "Because <code>:image</code> is a jQuery extension and not part of the CSS specification, queries using <code>:image</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>[type=\"image\"]</code> instead."
}],
"examples": [{
"desc": "Finds all image inputs.",
"code": "var input = $( \"input:image\" ).css({\n background:\"yellow\",\n border:\"3px red solid\"\n});\n$( \"div\" )\n .text( \"For this type jQuery found \" + input.length + \".\" )\n .css( \"color\", \"red\" );\n$( \"form\" ).submit(function( event ) {\n event.preventDefault();\n});",
"html": "<form>\n <input type=\"button\" value=\"Input Button\">\n <input type=\"checkbox\">\n <input type=\"file\">\n <input type=\"hidden\">\n <input type=\"image\">\n <input type=\"password\">\n <input type=\"radio\">\n <input type=\"reset\">\n <input type=\"submit\">\n <input type=\"text\">\n <select>\n <option>Option</option>\n </select>\n <textarea></textarea>\n <button>Button</button>\n</form>\n<div></div>",
"css": "textarea {\n height: 45px;\n }"
}],
"categories": [
"selectors/form-selectors",
"selectors/jquery-selector-extensions",
"version/1.0"
]
},
{
"title": ".index()",
"type": "method",
"name": "index",
"return": "Integer",
"signatures": [{
"arguments": [],
"added": "1.4"
},
{
"arguments": [{
"name": "selector",
"type": "Selector",
"desc": "A selector representing a jQuery collection in which to look for an element."
}],
"added": "1.4"
},
{
"arguments": [{
"name": "element",
"type": [
"Element",
"jQuery"
],
"desc": "The DOM element or first element within the jQuery object to look for."
}],
"added": "1.0"
}
],
"desc": "Search for a given element from among the matched elements.",
"longdesc": "<h4>Return Values</h4>\n <p>If no argument is passed to the <code>.index()</code> method, the return value is an integer indicating the position of the first element within the jQuery object relative to its sibling elements.</p>\n <p>If <code>.index()</code> is called on a collection of elements and a DOM element or jQuery object is passed in, <code>.index()</code> returns an integer indicating the position of the passed element relative to the original collection.</p>\n <p>If a selector string is passed as an argument, <code>.index()</code> returns an integer indicating the position of the first element within the jQuery object relative to the elements matched by the selector. If the element is not found, <code>.index()</code> will return -1.</p>\n <h4>Detail</h4>\n <p>The complementary operation to <code>.get()</code>, which accepts an index and returns a DOM node, <code>.index()</code> can take a DOM node and returns an index. Suppose we have a simple unordered list on the page:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li id=\"foo\"&gt;foo&lt;/li&gt;\n &lt;li id=\"bar\"&gt;bar&lt;/li&gt;\n &lt;li id=\"baz\"&gt;baz&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>If we retrieve one of the three list items (for example, through a DOM function or as the context to an event handler), <code>.index()</code> can search for this list item within the set of matched elements:</p>\n <pre><code>\nvar listItem = document.getElementById( \"bar\" );\nalert( \"Index: \" + $( \"li\" ).index( listItem ) );\n </code></pre>\n <p>We get back the zero-based position of the list item:</p>\n <p>\n <samp>Index: 1</samp>\n </p>\n <p>Similarly, if we retrieve a jQuery object consisting of one of the three list items, <code>.index()</code> will search for that list item:</p>\n <pre><code>\nvar listItem = $( \"#bar\" );\nalert( \"Index: \" + $( \"li\" ).index( listItem ) );\n </code></pre>\n <p>We get back the zero-based position of the list item:</p>\n <p>\n <samp>Index: 1</samp>\n </p>\n <p>Note that if the jQuery collection used as the <code>.index()</code> method's argument contains more than one element, the first element within the matched set of elements will be used.</p>\n <pre><code>\nvar listItems = $( \"li\" ).slice( 1 );\nalert( \"Index: \" + $( \"li\" ).index( listItems ) );\n </code></pre>\n <p>We get back the zero-based position of the first list item within the matched set:</p>\n <p>\n <samp>Index: 1</samp>\n </p>\n <p>If we use a string as the <code>.index()</code> method's argument, it is interpreted as a jQuery selector string. The first element among the object's matched elements which also matches this selector is located.</p>\n <pre><code>\nvar listItem = $( \"#bar\" );\nalert( \"Index: \" + listItem.index( \"li\" ) );\n </code></pre>\n <p>We get back the zero-based position of the list item:</p>\n <p>\n <samp>Index: 1</samp>\n </p>\n <p>If we omit the argument, <code>.index()</code> will return the position of the first element within the set of matched elements in relation to its siblings:</p>\n <pre><code>\nalert( \"Index: \" + $( \"#bar\" ).index() );\n </code></pre>\n <p>Again, we get back the zero-based position of the list item:</p>\n <p>\n <samp>Index: 1</samp>\n </p>",
"examples": [{
"desc": "On click, returns the index (zero-based) of that div in the page.",
"code": "$( \"div\" ).click(function() {\n // `this` is the DOM element that was clicked\n var index = $( \"div\" ).index( this );\n $( \"span\" ).text( \"That was div index #\" + index );\n});",
"html": "<span>Click a div!</span>\n<div>First div</div>\n<div>Second div</div>\n<div>Third div</div>",
"css": "div {\n background: yellow;\n margin: 5px;\n }\n span {\n color: red;\n }"
},
{
"desc": "Returns the index for the element with ID bar.",
"code": "var listItem = $( \"#bar\" );\n$( \"div\" ).html( \"Index: \" + $( \"li\" ).index( listItem ) );",
"html": "<ul>\n <li id=\"foo\">foo</li>\n <li id=\"bar\">bar</li>\n <li id=\"baz\">baz</li>\n</ul>\n<div></div>",
"css": "div {\n font-weight: bold;\n color: #090;\n }"
},
{
"desc": "Returns the index for the first item in the jQuery collection.",
"code": "var listItems = $( \"li\" ).slice( 1 );\n$( \"div\" ).html( \"Index: \" + $( \"li\" ).index( listItems ) );",
"html": "<ul>\n <li id=\"foo\">foo</li>\n <li id=\"bar\">bar</li>\n <li id=\"baz\">baz</li>\n</ul>\n<div></div>",
"css": "div {\n font-weight: bold;\n color: #090;\n }"
},
{
"desc": "Returns the index for the element with ID bar in relation to all &lt;li&gt; elements.",
"code": "$( \"div\" ).html( \"Index: \" + $( \"#bar\" ).index( \"li\" ) );",
"html": "<ul>\n <li id=\"foo\">foo</li>\n <li id=\"bar\">bar</li>\n <li id=\"baz\">baz</li>\n</ul>\n<div></div>",
"css": "div {\n font-weight: bold;\n color: #090;\n }"
},
{
"desc": "Returns the index for the element with ID bar in relation to its siblings.",
"code": "var barIndex = $( \"#bar\" ).index();\n$( \"div\" ).html( \"Index: \" + barIndex );",
"html": "<ul>\n <li id=\"foo\">foo</li>\n <li id=\"bar\">bar</li>\n <li id=\"baz\">baz</li>\n</ul>\n<div></div>",
"css": "div {\n font-weight: bold;\n color: #090;\n }"
},
{
"desc": "Returns -1, as there is no element with ID foobar.",
"code": "var foobar = $( \"li\" ).index( $( \"#foobar\" ) );\n$( \"div\" ).html( \"Index: \" + foobar );",
"html": "<ul>\n <li id=\"foo\">foo</li>\n <li id=\"bar\">bar</li>\n <li id=\"baz\">baz</li>\n</ul>\n<div></div>",
"css": "div {\n font-weight: bold;\n color: #090;\n }"
}
],
"categories": [
"miscellaneous/dom-element-methods",
"version/1.0",
"version/1.4"
]
},
{
"entries": [{
"title": ".innerHeight()",
"type": "method",
"name": "innerHeight",
"return": "Number",
"signatures": [{
"arguments": [],
"added": "1.2.6"
}],
"desc": "Get the current computed height for the first element in the set of matched elements, including padding but not border.",
"longdesc": "<p>This method returns the height of the element, including top and bottom padding, in pixels. If called on an empty set of elements, returns <code>undefined</code> (<code>null</code> before jQuery 3.0).</p>\n <p>This method is not applicable to <code>window</code> and <code>document</code> objects; for these, use <code><a href=\"/height/\">.height()</a></code> instead.</p>\n <figure>\n <img src=\"/resources/0042_04_02.png\"/>\n <figcaption>Figure 1 - Illustration of the measured height</figcaption>\n </figure>",
"note": [{
"type": "additional",
"text": "The number returned by dimensions-related APIs, including <code>.innerHeight()</code>, may be fractional in some cases. Code should not assume it is an integer. Also, dimensions may be incorrect when the page is zoomed by the user; browsers do not expose an API to detect this condition."
},
{
"type": "additional",
"text": "The value reported by <code>.innerHeight()</code> is not guaranteed to be accurate when the element or its parent is hidden. To get an accurate value, ensure the element is visible before using <code>.innerHeight()</code>. jQuery will attempt to temporarily show and then re-hide an element in order to measure its dimensions, but this is unreliable and (even when accurate) can significantly impact page performance. This show-and-rehide measurement feature may be removed in a future version of jQuery."
}
],
"examples": [{
"desc": "Get the innerHeight of a paragraph.",
"code": "var p = $( \"p\" ).first();\n$( \"p\" ).last().text( \"innerHeight:\" + p.innerHeight() );",
"html": "<p>Hello</p>\n<p></p>",
"css": "p {\n margin: 10px;\n padding: 5px;\n border: 2px solid #666;\n }"
}],
"categories": [
"css",
"dimensions",
"manipulation/style-properties",
"version/1.2.6"
]
},
{
"title": "",
"type": "method",
"name": "innerHeight",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "value",
"type": [
"String",
"Number"
],
"desc": "A number representing the number of pixels, or a number along with an optional unit of measure appended (as a string)."
}],
"added": "1.8.0"
},
{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "A function returning the inner height (including padding but not border) to set. Receives the index position of the element in the set and the old inner height as arguments. Within the function, <code>this</code> refers to the current element in the set.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "height",
"type": "Number"
}
]
}],
"added": "1.8.0"
}
],
"desc": "Set the CSS inner height of each element in the set of matched elements.",
"longdesc": "<p>When calling <code>.innerHeight(\"value\")</code>, the value can be either a string (number and unit) or a number. If only a number is provided for the value, jQuery assumes a pixel unit. If a string is provided, however, any valid CSS measurement may be used for the height (such as <code>100px</code>, <code>50%</code>, or <code>auto</code>). Note that in modern browsers, the CSS height property does not include padding, border, or margin, unless the <code>box-sizing</code> CSS property is used.</p>\n <p>If no explicit unit is specified (like \"em\" or \"%\") then \"px\" is assumed.</p>",
"examples": [{
"desc": "Change the inner height of each div the first time it is clicked (and change its color).",
"code": "var modHeight = 70;\n$( \"div\" ).one( \"click\", function() {\n $( this ).innerHeight( modHeight ).addClass( \"mod\" );\n modHeight -= 8;\n});",
"html": "<div>d</div>\n<div>d</div>\n<div>d</div>\n<div>d</div>\n<div>d</div>",
"css": "div {\n width: 60px;\n padding: 10px;\n height: 70px;\n float: left;\n margin: 5px;\n background: red;\n cursor: pointer;\n}\n.mod {\n background: blue;\n cursor: default;\n}"
}],
"categories": [
"css",
"dimensions",
"manipulation/style-properties",
"version/1.8"
]
}
]
},
{
"entries": [{
"title": ".innerWidth()",
"type": "method",
"name": "innerWidth",
"return": "Number",
"signatures": [{
"arguments": [],
"added": "1.2.6"
}],
"desc": "Get the current computed inner width for the first element in the set of matched elements, including padding but not border.",
"longdesc": "<p>This method returns the width of the element, including left and right padding, in pixels. If called on an empty set of elements, returns <code>undefined</code> (<code>null</code> before jQuery 3.0).</p>\n <p>This method is not applicable to <code>window</code> and <code>document</code> objects; for these, use <code><a href=\"/width/\">.width()</a></code> instead.</p>\n <figure>\n <img src=\"/resources/0042_04_05.png\"/>\n <figcaption>Figure 1 - Illustration of the measured width</figcaption>\n </figure>",
"note": [{
"type": "additional",
"text": "The number returned by dimensions-related APIs, including <code>.innerWidth()</code>, may be fractional in some cases. Code should not assume it is an integer. Also, dimensions may be incorrect when the page is zoomed by the user; browsers do not expose an API to detect this condition."
},
{
"type": "additional",
"text": "The value reported by <code>.innerWidth()</code> is not guaranteed to be accurate when the element or its parent is hidden. To get an accurate value, ensure the element is visible before using <code>.innerWidth()</code>. jQuery will attempt to temporarily show and then re-hide an element in order to measure its dimensions, but this is unreliable and (even when accurate) can significantly impact page performance. This show-and-rehide measurement feature may be removed in a future version of jQuery."
}
],
"examples": [{
"desc": "Get the innerWidth of a paragraph.",
"code": "var p = $( \"p\" ).first();\n$( \"p\" ).last().text( \"innerWidth:\" + p.innerWidth() );",
"html": "<p>Hello</p>\n<p></p>",
"css": "p {\n margin: 10px;\n padding: 5px;\n border: 2px solid #666;\n }"
}],
"categories": [
"css",
"dimensions",
"manipulation/style-properties",
"version/1.2.6"
]
},
{
"title": "",
"type": "method",
"name": "innerWidth",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "value",
"type": [
"String",
"Number"
],
"desc": "A number representing the number of pixels, or a number along with an optional unit of measure appended (as a string)."
}],
"added": "1.8.0"
},
{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "A function returning the inner width (including padding but not border) to set. Receives the index position of the element in the set and the old inner width as arguments. Within the function, <code>this</code> refers to the current element in the set.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "width",
"type": "Number"
}
]
}],
"added": "1.8.0"
}
],
"desc": "Set the CSS inner width of each element in the set of matched elements.",
"longdesc": "<p>When calling <code>.innerWidth(\"value\")</code>, the value can be either a string (number and unit) or a number. If only a number is provided for the value, jQuery assumes a pixel unit. If a string is provided, however, any valid CSS measurement may be used for the width (such as <code>100px</code>, <code>50%</code>, or <code>auto</code>). Note that in modern browsers, the CSS width property does not include padding, border, or margin, unless the <code>box-sizing</code> CSS property is used.</p>\n <p>If no explicit unit is specified (like \"em\" or \"%\") then \"px\" is assumed.</p>",
"examples": [{
"desc": "Change the inner width of each div the first time it is clicked (and change its color).",
"code": "var modWidth = 60;\n$( \"div\" ).one( \"click\", function() {\n$( this ).innerWidth( modWidth ).addClass( \"mod\" );\nmodWidth -= 8;\n});",
"html": "<div>d</div>\n<div>d</div>\n<div>d</div>\n<div>d</div>\n<div>d</div>",
"css": "div {\nwidth: 60px;\npadding: 10px;\nheight: 50px;\nfloat: left;\nmargin: 5px;\nbackground: red;\ncursor: pointer;\n}\n.mod {\nbackground: blue;\ncursor: default;\n}"
}],
"categories": [
"css",
"dimensions",
"manipulation/style-properties",
"version/1.8"
]
}
]
},
{
"title": ":input Selector",
"type": "selector",
"name": "input",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Selects all input, textarea, select and button elements.",
"longdesc": "<p>The <code>:input</code> selector basically selects all form controls.</p>",
"note": [{
"type": "additional",
"text": "Because <code>:input</code> is a jQuery extension and not part of the CSS specification, queries using <code>:input</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>undefined</code> instead."
}],
"examples": [{
"desc": "Finds all input elements.",
"code": "var allInputs = $( \":input\" );\nvar formChildren = $( \"form > *\" );\n$( \"#messages\" ).text( \"Found \" + allInputs.length + \" inputs and the form has \" +\n formChildren.length + \" children.\" );\n\n$( \"form\" ).submit(function( event ) {\n event.preventDefault();\n});",
"html": "<form>\n <input type=\"button\" value=\"Input Button\">\n <input type=\"checkbox\">\n <input type=\"file\">\n <input type=\"hidden\">\n <input type=\"image\">\n <input type=\"password\">\n <input type=\"radio\">\n <input type=\"reset\">\n <input type=\"submit\">\n <input type=\"text\">\n <select>\n <option>Option</option>\n </select>\n <textarea></textarea>\n <button>Button</button>\n</form>\n<div id=\"messages\"></div>",
"css": "textarea {\n height: 25px;\n }"
}],
"categories": [
"selectors/form-selectors",
"selectors/jquery-selector-extensions",
"version/1.0"
]
},
{
"title": ".insertAfter()",
"type": "method",
"name": "insertAfter",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "target",
"type": [
"Selector",
"htmlString",
"Element",
"Array",
"jQuery"
],
"desc": "A selector, element, array of elements, HTML string, or jQuery object; the matched set of elements will be inserted after the element(s) specified by this parameter."
}],
"added": "1.0"
}],
"desc": "Insert every element in the set of matched elements after the target.",
"longdesc": "<p>The <code><a href=\"/after/\">.after()</a></code> and <code>.insertAfter()</code> methods perform the same task. The major difference is in the syntax—specifically, in the placement of the content and target. With <code>.after()</code>, the selector expression preceding the method is the container after which the content is inserted. With <code>.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 <p>Consider the following HTML:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;h2&gt;Greetings&lt;/h2&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>We can create content and insert it after several elements at once:</p>\n <pre><code>\n$( \"&lt;p&gt;Test&lt;/p&gt;\" ).insertAfter( \".inner\" );\n </code></pre>\n <p>Each inner <code>&lt;div&gt;</code> element gets this new content:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;h2&gt;Greetings&lt;/h2&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;p&gt;Test&lt;/p&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n &lt;p&gt;Test&lt;/p&gt;\n&lt;/div&gt;\n </code></pre>\n <p>We can also select an element on the page and insert it after another:</p>\n <pre><code>\n$( \"h2\" ).insertAfter( $( \".container\" ) );\n </code></pre>\n <p>If an element selected this way is inserted into a single location elsewhere in the DOM, it will be moved after the target (not cloned) and a new set consisting of the inserted element is returned:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n&lt;h2&gt;Greetings&lt;/h2&gt;\n </code></pre>\n <p>If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first, and that new set (the original element plus clones) is returned.</p>\n <p><strong>Before jQuery 1.9,</strong> the append-to-single-element case did not create a new set, but instead returned the original set which made it difficult to use the <code>.end()</code> method reliably when being used with an unknown number of elements.</p>",
"note": [{
"type": "additional",
"text": "By design, any jQuery constructor or method that accepts an HTML string — <a href=\"/jQuery/\">jQuery()</a>, <a href=\"/append/\">.append()</a>, <a href=\"/after/\">.after()</a>, etc. — can potentially execute code. This can occur by injection of script tags or use of HTML attributes that execute code (for example, <code>&lt;img onload=\"\"&gt;</code>). Do not use these methods to insert strings obtained from untrusted sources such as URL query parameters, cookies, or form inputs. Doing so can introduce cross-site-scripting (XSS) vulnerabilities. Remove or escape any user input before adding content to the document."
},
{
"type": "additional",
"text": "jQuery doesn't officially support SVG. Using jQuery methods on SVG documents, unless explicitly documented for that method, might cause unexpected behaviors. Examples of methods that support SVG as of jQuery 3.0 are <code>addClass</code> and <code>removeClass</code>."
}
],
"examples": [{
"desc": "Insert all paragraphs after an element with id of \"foo\". Same as $( \"#foo\" ).after( \"p\" )",
"code": "$( \"p\" ).insertAfter( \"#foo\" );",
"html": "<p> is what I said... </p>\n<div id=\"foo\">FOO!</div>",
"css": "#foo {\n background: yellow;\n }"
}],
"categories": [
"manipulation/dom-insertion-outside",
"version/1.0"
]
},
{
"title": ".insertBefore()",
"type": "method",
"name": "insertBefore",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "target",
"type": [
"Selector",
"htmlString",
"Element",
"Array",
"jQuery"
],
"desc": "A selector, element, array of elements, HTML string, or jQuery object; the matched set of elements will be inserted before the element(s) specified by this parameter."
}],
"added": "1.0"
}],
"desc": "Insert every element in the set of matched elements before the target.",
"longdesc": "<p>The <code><a href=\"/before/\">.before()</a></code> and <code>.insertBefore()</code> methods perform the same task. The major difference is in the syntax-specifically, in the placement of the content and target. With <code>.before()</code>, the selector expression preceding the method is the container before which the content is inserted. With <code>.insertBefore()</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 before the target container.</p>\n <p>Consider the following HTML:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;h2&gt;Greetings&lt;/h2&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>We can create content and insert it before several elements at once:</p>\n <pre><code>\n$( \"&lt;p&gt;Test&lt;/p&gt;\" ).insertBefore( \".inner\" );\n </code></pre>\n <p>Each inner <code>&lt;div&gt;</code> element gets this new content:</p>\n <pre><code>\n&lt;div class=\"container\"&gt;\n &lt;h2&gt;Greetings&lt;/h2&gt;\n &lt;p&gt;Test&lt;/p&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;p&gt;Test&lt;/p&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>We can also select an element on the page and insert it before another:</p>\n <pre><code>\n$( \"h2\" ).insertBefore( $( \".container\" ) );\n </code></pre>\n <p>If an element selected this way is inserted into a single location elsewhere in the DOM, it will be moved before the target (not cloned) and a new set consisting of the inserted element is returned:</p>\n <pre><code>\n&lt;h2&gt;Greetings&lt;/h2&gt;\n&lt;div class=\"container\"&gt;\n &lt;div class=\"inner\"&gt;Hello&lt;/div&gt;\n &lt;div class=\"inner\"&gt;Goodbye&lt;/div&gt;\n&lt;/div&gt;\n </code></pre>\n <p>If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first, and that new set (the original element plus clones) is returned.</p>\n <p><strong>Before jQuery 1.9,</strong> the append-to-single-element case did not create a new set, but instead returned the original set which made it difficult to use the <code>.end()</code> method reliably when being used with an unknown number of elements.</p>",
"note": [{
"type": "additional",
"text": "By design, any jQuery constructor or method that accepts an HTML string — <a href=\"/jQuery/\">jQuery()</a>, <a href=\"/append/\">.append()</a>, <a href=\"/after/\">.after()</a>, etc. — can potentially execute code. This can occur by injection of script tags or use of HTML attributes that execute code (for example, <code>&lt;img onload=\"\"&gt;</code>). Do not use these methods to insert strings obtained from untrusted sources such as URL query parameters, cookies, or form inputs. Doing so can introduce cross-site-scripting (XSS) vulnerabilities. Remove or escape any user input before adding content to the document."
},
{
"type": "additional",
"text": "jQuery doesn't officially support SVG. Using jQuery methods on SVG documents, unless explicitly documented for that method, might cause unexpected behaviors. Examples of methods that support SVG as of jQuery 3.0 are <code>addClass</code> and <code>removeClass</code>."
}
],
"examples": [{
"desc": "Insert all paragraphs before an element with id of \"foo\". Same as $( \"#foo\" ).before( \"p\" )",
"code": "$( \"p\" ).insertBefore( \"#foo\" );",
"html": "<div id=\"foo\">FOO!</div>\n<p>I would like to say: </p>",
"css": "#foo {\n background: yellow;\n }"
}],
"categories": [
"manipulation/dom-insertion-outside",
"version/1.0"
]
},
{
"title": ".is()",
"type": "method",
"name": "is",
"return": "Boolean",
"signatures": [{
"arguments": [{
"name": "selector",
"type": "Selector",
"desc": "A string containing a selector expression to match elements against."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "A function used as a test for every element in the set. It accepts two arguments, <code>index</code>, which is the element's index in the jQuery collection, and <code>element</code>, which is the DOM element. Within the function, <code>this</code> refers to the current DOM element.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "element",
"type": "Element"
}
]
}],
"added": "1.6"
},
{
"arguments": [{
"name": "selection",
"type": "jQuery",
"desc": "An existing jQuery object to match the current set of elements against."
}],
"added": "1.6"
},
{
"arguments": [{
"name": "elements",
"type": "Element",
"desc": "One or more elements to match the current set of elements against."
}],
"added": "1.6"
}
],
"desc": "Check the current matched set of elements against a selector, element, or jQuery object and return <code>true</code> if at least one of these elements matches the given arguments.",
"longdesc": "<p>Unlike other filtering methods, <code>.is()</code> does not create a new jQuery object. Instead, it allows you to test the contents of a jQuery object without modification. This is often useful inside callbacks, such as event handlers.</p>\n <p>Suppose you have a list, with two of its items containing a child element:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li&gt;list &lt;strong&gt;item 1&lt;/strong&gt;&lt;/li&gt;\n &lt;li&gt;&lt;span&gt;list item 2&lt;/span&gt;&lt;/li&gt;\n &lt;li&gt;list item 3&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>You can attach a click handler to the &lt;ul&gt; element, and then limit the code to be triggered only when a list item itself, not one of its children, is clicked:</p>\n <pre><code>\n$( \"ul\" ).click(function( event ) {\n var target = $( event.target );\n if ( target.is( \"li\" ) ) {\n target.css( \"background-color\", \"red\" );\n }\n});\n </code></pre>\n <p>Now, when the user clicks on the word \"list\" in the first item or anywhere in the third item, the clicked list item will be given a red background. However, when the user clicks on item 1 in the first item or anywhere in the second item, nothing will occur, because in those cases the target of the event would be <code>&lt;strong&gt;</code> or <code>&lt;span&gt;</code>, respectively.</p>\n <h4>Using a Function</h4>\n <p>The second form of this method evaluates expressions related to elements based on a function rather than a selector. For each element, if the function returns <code>true</code>, <code>.is()</code> returns <code>true</code> as well. For example, given a somewhat more involved HTML snippet:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li&gt;&lt;strong&gt;list&lt;/strong&gt; item 1 - one strong tag&lt;/li&gt;\n &lt;li&gt;&lt;strong&gt;list&lt;/strong&gt; item &lt;strong&gt;2&lt;/strong&gt; -\n two &lt;span&gt;strong tags&lt;/span&gt;&lt;/li&gt;\n &lt;li&gt;list item 3&lt;/li&gt;\n &lt;li&gt;list item 4&lt;/li&gt;\n &lt;li&gt;list item 5&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>You can attach a click handler to every <code>&lt;li&gt;</code> that evaluates the number of <code>&lt;strong&gt;</code> elements within the clicked <code>&lt;li&gt;</code> at that time like so:</p>\n <pre><code>\n$( \"li\" ).click(function() {\n var li = $( this ),\n isWithTwo = li.is(function() {\n return $( \"strong\", this ).length === 2;\n });\n if ( isWithTwo ) {\n li.css( \"background-color\", \"green\" );\n } else {\n li.css( \"background-color\", \"red\" );\n }\n});\n </code></pre>",
"examples": [{
"desc": "Shows a few ways is() can be used inside an event handler.",
"code": "$( \"div\" ).one( \"click\", function() {\n if ( $( this ).is( \":first-child\" ) ) {\n $( \"p\" ).text( \"It's the first div.\" );\n } else if ( $( this ).is( \".blue,.red\" ) ) {\n $( \"p\" ).text( \"It's a blue or red div.\" );\n } else if ( $( this ).is( \":contains('Peter')\" ) ) {\n $( \"p\" ).text( \"It's Peter!\" );\n } else {\n $( \"p\" ).html( \"It's nothing <em>special</em>.\" );\n }\n $( \"p\" ).hide().slideDown( \"slow\" );\n $( this ).css({\n \"border-style\": \"inset\",\n cursor: \"default\"\n });\n});",
"html": "<div></div>\n<div class=\"blue\"></div>\n<div></div>\n<div class=\"red\"></div>\n<div><br/><span>Peter</span></div>\n<div class=\"blue\"></div>\n<p>&nbsp;</p>",
"css": "div {\n width: 60px;\n height: 60px;\n margin: 5px;\n float: left;\n border: 4px outset;\n background: green;\n text-align: center;\n font-weight: bolder;\n cursor: pointer;\n }\n .blue {\n background: blue;\n }\n .red {\n background: red;\n }\n span {\n color: white;\n font-size: 16px;\n }\n p {\n color: red;\n font-weight: bolder;\n background: yellow;\n margin: 3px;\n clear: left;\n display: none;\n }"
},
{
"desc": "Returns true, because the parent of the input is a form element.",
"code": "var isFormParent = $( \"input[type='checkbox']\" ).parent().is( \"form\" );\n$( \"div\" ).text( \"isFormParent = \" + isFormParent );",
"html": "<form>\n <input type=\"checkbox\">\n</form>\n<div></div>",
"css": "div {\n color: red;\n }"
},
{
"desc": "Returns false, because the parent of the input is a p element.",
"code": "var isFormParent = $( \"input[type='checkbox']\" ).parent().is( \"form\" );\n$( \"div\" ).text( \"isFormParent = \" + isFormParent );",
"html": "<form>\n <p><input type=\"checkbox\"></p>\n</form>\n<div></div>",
"css": "div {\n color: red;\n }"
},
{
"desc": "Checks against an existing collection of alternating list elements. Blue, alternating list elements slide up while others turn red.",
"code": "var alt = $( \"#browsers li:nth-child(2n)\" ).css( \"background\", \"#0ff\" );\n$( \"li\" ).click(function() {\n var li = $( this );\n if ( li.is( alt ) ) {\n li.slideUp();\n } else {\n li.css( \"background\", \"red\" );\n }\n});",
"html": "<ul id=\"browsers\">\n <li>Chrome</li>\n <li>Safari</li>\n <li>Firefox</li>\n <li>Opera</li>\n</ul>",
"css": "li {\n cursor: pointer;\n }"
},
{
"desc": "An alternate way to achieve the above example using an element rather than a jQuery object. Checks against an existing collection of alternating list elements. Blue, alternating list elements slide up while others turn red.",
"code": "var alt = $( \"#browsers li:nth-child(2n)\" ).css( \"background\", \"#0ff\" );\n$( \"li\" ).click(function() {\n if ( alt.is( this ) ) {\n $( this ).slideUp();\n } else {\n $( this ).css( \"background\", \"red\" );\n }\n});",
"html": "<ul id=\"browsers\">\n <li>Chrome</li>\n <li>Safari</li>\n <li>Firefox</li>\n <li>Opera</li>\n</ul>",
"css": "li {\n cursor: pointer;\n }"
}
],
"categories": [
"traversing/filtering",
"version/1.0",
"version/1.6",
"version/1.7"
]
},
{
"title": "jQuery.Callbacks()",
"name": "jQuery.Callbacks",
"type": "method",
"return": "Callbacks",
"signatures": [{
"arguments": [{
"name": "flags",
"type": "String",
"desc": "An optional list of space-separated flags that change how the callback list behaves."
}],
"added": "1.7"
}],
"desc": "A multi-purpose callbacks list object that provides a powerful way to manage callback lists.",
"longdesc": "<p>The <code>$.Callbacks()</code> function is internally used to provide the base functionality behind the jQuery <code>$.ajax()</code> and <code>$.Deferred()</code> components. It can be used as a similar base to define functionality for new components.</p>\n <p><code>$.Callbacks()</code> supports a number of methods including <code><a href=\"/callbacks.add/\">callbacks.add()</a></code>,<code><a href=\"/callbacks.remove/\">callbacks.remove()</a></code>, <code><a href=\"/callbacks.fire/\">callbacks.fire()</a></code> and <code><a href=\"/callbacks.disable/\">callbacks.disable()</a></code>.</p>\n <h3 id=\"getting-started\">Getting started</h3>\n <p>The following are two sample methods named <code>fn1</code> and <code>fn2</code>:</p>\n <pre><code>\nfunction fn1( value ) {\n console.log( value );\n}\n\nfunction fn2( value ) {\n console.log( \"fn2 says: \" + value );\n return false;\n}\n </code></pre>\n <p>These can be added as callbacks to a <code>$.Callbacks</code> list and invoked as follows:</p>\n <pre><code>\nvar callbacks = $.Callbacks();\ncallbacks.add( fn1 );\n\n// Outputs: foo!\ncallbacks.fire( \"foo!\" );\n\ncallbacks.add( fn2 );\n\n// Outputs: bar!, fn2 says: bar!\ncallbacks.fire( \"bar!\" );\n </code></pre>\n <p>The result of this is that it becomes simple to construct complex lists of callbacks where input values can be passed through to as many functions as needed with ease.</p>\n <p>Two specific methods were being used above: <code>.add()</code> and <code>.fire()</code>. The <code>.add()</code> method supports adding new callbacks to the callback list, while the <code>.fire()</code> method executes the added functions and provides a way to pass arguments to be processed by the callbacks in the same list.</p>\n <p>Another method supported by <code>$.Callbacks</code> is <code>.remove()</code>, which has the ability to remove a particular callback from the callback list. Here's a practical example of <code>.remove()</code> being used:</p>\n <pre><code>\nvar callbacks = $.Callbacks();\ncallbacks.add( fn1 );\n\n// Outputs: foo!\ncallbacks.fire( \"foo!\" );\n\ncallbacks.add( fn2 );\n\n// Outputs: bar!, fn2 says: bar!\ncallbacks.fire( \"bar!\" );\n\ncallbacks.remove( fn2 );\n\n// Only outputs foobar, as fn2 has been removed.\ncallbacks.fire( \"foobar\" );\n </code></pre>\n <h3 id=\"supported-flags\">Supported Flags</h3>\n <p>The <code>flags</code> argument is an optional argument to <code>$.Callbacks()</code>, structured as a list of space-separated strings that change how the callback list behaves (eg. <code>$.Callbacks( \"unique stopOnFalse\" )</code>).</p>\n <h2>Possible flags:</h2>\n <ul>\n <li><code>once</code>: Ensures the callback list can only be fired once (like a Deferred).</li>\n <li><code>memory</code>: Keeps track of previous values and will call any callback added after the list has been fired right away with the latest \"memorized\" values (like a Deferred).</li>\n <li><code>unique</code>: Ensures a callback can only be added once (so there are no duplicates in the list).</li>\n <li><code>stopOnFalse</code>: Interrupts callings when a callback returns false.</li>\n </ul>\n <p>By default a callback list will act like an event callback list and can be \"fired\" multiple times.</p>\n <p>For examples of how <code>flags</code> should ideally be used, see below:</p>\n <h2 id=\"once\"><code>$.Callbacks( \"once\" )</code>:</h2>\n <pre><code>\nvar callbacks = $.Callbacks( \"once\" );\ncallbacks.add( fn1 );\ncallbacks.fire( \"foo\" );\ncallbacks.add( fn2 );\ncallbacks.fire( \"bar\" );\ncallbacks.remove( fn2 );\ncallbacks.fire( \"foobar\" );\n\n/*\noutput:\nfoo\n*/\n </code></pre>\n <h2 id=\"memory\"><code>$.Callbacks( \"memory\" )</code>:</h2>\n <pre><code>\nvar callbacks = $.Callbacks( \"memory\" );\ncallbacks.add( fn1 );\ncallbacks.fire( \"foo\" );\ncallbacks.add( fn2 );\ncallbacks.fire( \"bar\" );\ncallbacks.remove( fn2 );\ncallbacks.fire( \"foobar\" );\n\n/*\noutput:\nfoo\nfn2 says:foo\nbar\nfn2 says:bar\nfoobar\n*/\n </code></pre>\n <h2 id=\"unique\"><code>$.Callbacks( \"unique\" )</code>:</h2>\n <pre><code>\nvar callbacks = $.Callbacks( \"unique\" );\ncallbacks.add( fn1 );\ncallbacks.fire( \"foo\" );\ncallbacks.add( fn1 ); // Repeat addition\ncallbacks.add( fn2 );\ncallbacks.fire( \"bar\" );\ncallbacks.remove( fn2 );\ncallbacks.fire( \"foobar\" );\n\n/*\noutput:\nfoo\nbar\nfn2 says:bar\nfoobar\n*/\n </code></pre>\n <h2 id=\"stopOnFalse\"><code>$.Callbacks( \"stopOnFalse\" )</code>:</h2>\n <pre><code>\nfunction fn1( value ) {\n console.log( value );\n return false;\n}\n\nfunction fn2( value ) {\n fn1( \"fn2 says: \" + value );\n return false;\n}\n\nvar callbacks = $.Callbacks( \"stopOnFalse\" );\ncallbacks.add( fn1 );\ncallbacks.fire( \"foo\" );\ncallbacks.add( fn2 );\ncallbacks.fire( \"bar\" );\ncallbacks.remove( fn2 );\ncallbacks.fire( \"foobar\" );\n\n/*\noutput:\nfoo\nbar\nfoobar\n*/\n </code></pre>\n <p>Because <code>$.Callbacks()</code> supports a list of flags rather than just one, setting several flags has a cumulative effect similar to \"&amp;&amp;\". This means it's possible to combine flags to create callback lists that, say, both are <i>unique</i> and <i>ensure if list was already fired, adding more callbacks will have it called with the latest fired value</i> (i.e. <code>$.Callbacks(\"unique memory\")</code>).</p>\n <h2 id=\"unique-memory\"><code>$.Callbacks( 'unique memory' )</code>:</h2>\n <pre><code>\nfunction fn1( value ) {\n console.log( value );\n return false;\n}\n\nfunction fn2( value ) {\n fn1( \"fn2 says: \" + value );\n return false;\n}\n\nvar callbacks = $.Callbacks( \"unique memory\" );\ncallbacks.add( fn1 );\ncallbacks.fire( \"foo\" );\ncallbacks.add( fn1 ); // Repeat addition\ncallbacks.add( fn2 );\ncallbacks.fire( \"bar\" );\ncallbacks.add( fn2 );\ncallbacks.fire( \"baz\" );\ncallbacks.remove( fn2 );\ncallbacks.fire( \"foobar\" );\n\n/*\noutput:\nfoo\nfn2 says:foo\nbar\nfn2 says:bar\nbaz\nfn2 says:baz\nfoobar\n*/\n</code></pre>\n <p>Flag combinations with <code>$.Callbacks()</code> are internally in jQuery for the <code>.done()</code> and <code>.fail()</code> functions on a Deferred — both of which use <code>$.Callbacks('memory once')</code>.</p>\n <p>The methods of <code>$.Callbacks</code> can also be detached, should there be a need to define short-hand versions for convenience:</p>\n <pre><code>\nvar callbacks = $.Callbacks(),\n add = callbacks.add,\n remove = callbacks.remove,\n fire = callbacks.fire;\n\nadd( fn1 );\nfire( \"hello world\" );\nremove( fn1 );\n </code></pre>\n <h3 id=\"pubsub\">$.Callbacks, $.Deferred and Pub/Sub</h3>\n <p>The general idea behind pub/sub (Publish/Subscribe, or, the Observer pattern) is the promotion of loose coupling in applications. Rather than single objects calling on the methods of other objects, an object instead subscribes to a specific task or activity of another object and is notified when it occurs. Observers are also called Subscribers, and we refer to the object being observed as the Publisher (or the subject). Publishers notify subscribers when events occur.</p>\n <p>To demonstrate the component-creation capabilities of <code>$.Callbacks()</code>, it's possible to implement a Pub/Sub system using only callback lists. Using <code>$.Callbacks</code> as a topics queue, a system for publishing and subscribing to topics can be implemented as follows:</p>\n <pre><code>\nvar topics = {};\n\njQuery.Topic = function( id ) {\n var callbacks, method,\n topic = id &amp;&amp; topics[ id ];\n\n if ( !topic ) {\n callbacks = jQuery.Callbacks();\n topic = {\n publish: callbacks.fire,\n subscribe: callbacks.add,\n unsubscribe: callbacks.remove\n };\n if ( id ) {\n topics[ id ] = topic;\n }\n }\n return topic;\n};\n </code></pre>\n <p>This can then be used by parts of your application to publish and subscribe to events of interest quite easily:</p>\n <pre><code>\n// Subscribers\n$.Topic( \"mailArrived\" ).subscribe( fn1 );\n$.Topic( \"mailArrived\" ).subscribe( fn2 );\n$.Topic( \"mailSent\" ).subscribe( fn1 );\n\n// Publisher\n$.Topic( \"mailArrived\" ).publish( \"hello world!\" );\n$.Topic( \"mailSent\" ).publish( \"woo! mail!\" );\n\n// Here, \"hello world!\" gets pushed to fn1 and fn2\n// when the \"mailArrived\" notification is published\n// with \"woo! mail!\" also being pushed to fn1 when\n// the \"mailSent\" notification is published.\n\n/*\noutput:\nhello world!\nfn2 says: hello world!\nwoo! mail!\n*/\n </code></pre>\n <p>While this is useful, the implementation can be taken further. Using <code>$.Deferreds</code>, it's possible to ensure publishers only publish notifications for subscribers once particular tasks have been completed (resolved). See the below code sample for some further comments on how this could be used in practice:</p>\n <pre><code>\n// Subscribe to the mailArrived notification\n$.Topic( \"mailArrived\" ).subscribe( fn1 );\n\n// Create a new instance of Deferreds\nvar dfd = $.Deferred();\n\n// Define a new topic (without directly publishing)\nvar topic = $.Topic( \"mailArrived\" );\n\n// When the deferred has been resolved, publish a\n// notification to subscribers\ndfd.done( topic.publish );\n\n// Here the Deferred is being resolved with a message\n// that will be passed back to subscribers. It's possible to\n// easily integrate this into a more complex routine\n// (eg. waiting on an Ajax call to complete) so that\n// messages are only published once the task has actually\n// finished.\ndfd.resolve( \"it's been published!\" );\n </code></pre>",
"examples": [],
"categories": [
"callbacks-object",
"version/1.7"
]
},
{
"title": "jQuery.Deferred()",
"name": "jQuery.Deferred",
"type": "method",
"return": "Deferred",
"signatures": [{
"arguments": [{
"name": "beforeStart",
"type": "Function",
"optional": "true",
"desc": "A function that is called just before the constructor returns.",
"arguments": [{
"name": "deferred",
"type": "Deferred"
}]
}],
"added": "1.5"
}],
"desc": "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.",
"longdesc": "<p>The <code>jQuery.Deferred()</code> factory creates a new <code>deferred</code> object.</p>\n <p>The <code>jQuery.Deferred</code> method can be passed an optional function, which is called just before the method returns and is passed the new <code>deferred</code> object as both the <code>this</code> object and as the first argument to the function. The called function can attach callbacks using <a href=\"/deferred.then/\"><code>deferred.then()</code></a>, for example.</p>\n <p>A Deferred object starts in the <em>pending</em> state. Any callbacks added to the object with <a href=\"/deferred.then/\"><code>deferred.then()</code></a>, <a href=\"/deferred.always/\"><code>deferred.always()</code></a>, <a href=\"/deferred.done/\"><code>deferred.done()</code></a>, or <a href=\"/deferred.fail/\"><code>deferred.fail()</code></a> are queued to be executed later. Calling <a href=\"/deferred.resolve/\"><code>deferred.resolve()</code></a> or <a href=\"/deferred.resolveWith/\"><code>deferred.resolveWith()</code></a> transitions the Deferred into the <em>resolved</em> state and immediately executes any <code>doneCallbacks</code> that are set. Calling <a href=\"/deferred.reject/\"><code>deferred.reject()</code></a> or <a href=\"/deferred.rejectWith/\"><code>deferred.rejectWith()</code></a> transitions the Deferred into the <em>rejected</em> state and immediately executes any <code>failCallbacks</code> that are set. Once the object has entered the resolved or rejected state, it stays in that state. Callbacks can still be added to the resolved or rejected Deferred — they will execute immediately.</p>\n <h4>\n Enhanced Callbacks with jQuery Deferred\n </h4>\n <p>In JavaScript it is common to invoke functions that optionally accept callbacks that are called within that function. For example, in versions prior to jQuery 1.5, asynchronous processes such as <code>jQuery.ajax()</code> accept callbacks to be invoked some time in the near-future upon success, error, and completion of the ajax request.</p>\n <p><code>jQuery.Deferred()</code> introduces several enhancements to the way callbacks are managed and invoked. In particular, <code>jQuery.Deferred()</code> provides flexible ways to provide multiple callbacks, and these callbacks can be invoked regardless of whether the original callback dispatch has already occurred. jQuery Deferred is based on the <a href=\"http://wiki.commonjs.org/wiki/Promises/A\">CommonJS Promises/A</a> design.</p>\n <p>One model for understanding Deferred is to think of it as a chain-aware function wrapper. The <a href=\"/deferred.then/\"><code>deferred.then()</code></a>, <a href=\"/deferred.always/\"><code>deferred.always()</code></a>, <a href=\"/deferred.done/\"><code>deferred.done()</code></a>, and <a href=\"/deferred.fail/\"><code>deferred.fail()</code></a> methods specify the functions to be called and the <a href=\"/deferred.resolve/\"><code>deferred.resolve(args)</code></a> or <a href=\"/deferred.reject/\"><code>deferred.reject(args)</code></a> methods \"call\" the functions with the arguments you supply. Once the Deferred has been resolved or rejected it stays in that state; a second call to <code>deferred.resolve()</code>, for example, is ignored. If more functions are added by <code>deferred.then()</code>, for example, after the Deferred is resolved, they are called immediately with the arguments previously provided.</p>\n <p>In most cases where a jQuery API call returns a Deferred or Promise-compatible object, such as <a href=\"/jQuery.ajax/\"><code>jQuery.ajax()</code></a> or <a href=\"/jQuery.when/\"><code>jQuery.when()</code></a>, you will only want to use the <a href=\"/deferred.then/\"><code>deferred.then()</code></a>, <a href=\"/deferred.done/\"><code>deferred.done()</code></a>, and <a href=\"/deferred.fail/\"><code>deferred.fail()</code></a> methods to add callbacks to the Deferred's queues. The internals of the API call or code that created the Deferred will invoke <a href=\"/deferred.resolve/\"><code>deferred.resolve()</code></a> or <a href=\"/deferred.reject/\"><code>deferred.reject()</code></a> on the deferred at some point, causing the appropriate callbacks to run.</p>",
"examples": [],
"categories": [
"deferred-object",
"version/1.5"
]
},
{
"title": "jQuery.ajax()",
"type": "method",
"name": "jQuery.ajax",
"return": "jqXHR",
"signatures": [{
"arguments": [{
"name": "url",
"type": "String",
"desc": "A string containing the URL to which the request is sent."
},
{
"name": "settings",
"type": "PlainObject",
"optional": "true",
"desc": "A set of key/value pairs that configure the Ajax request. All settings are optional. A default can be set for any option with <a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a>. See <a href=\"#jQuery-ajax-settings\">jQuery.ajax( settings )</a> below for a complete list of all settings."
}
],
"added": "1.5"
},
{
"arguments": [{
"name": "settings",
"type": "PlainObject",
"optional": "true",
"desc": "A set of key/value pairs that configure the Ajax request. All settings are optional. A default can be set for any option with <a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a>.",
"properties": [{
"default": "depends on dataType",
"name": "accepts",
"type": "PlainObject",
"desc": "A set of key/value pairs that map a given <code>dataType</code> to its MIME type, which gets sent in the <code>Accept</code> request header. This header tells the server what kind of response it will accept in return. For example, the following defines a custom type <code>mycustomtype</code> to be sent with the request:\n <pre><code>\n$.ajax({\n accepts: {\n mycustomtype: 'application/x-some-custom-type'\n },\n\n // Instructions for how to deserialize a `mycustomtype`\n converters: {\n 'text mycustomtype': function(result) {\n // Do Stuff\n return newresult;\n }\n },\n\n // Expect a `mycustomtype` back from server\n dataType: 'mycustomtype'\n});\n </code></pre>\n <strong>Note:</strong> You will need to specify a complementary entry for this type in <code>converters</code> for this to work properly.",
"arguments": []
},
{
"default": "true",
"name": "async",
"type": "Boolean",
"desc": "By default, all requests are sent asynchronously (i.e. this is set to <code>true</code> by default). If you need synchronous requests, set this option to <code>false</code>. Cross-domain requests and <code>dataType: \"jsonp\"</code> requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. <strong>As of jQuery 1.8</strong>, the use of <code>async: false</code> with jqXHR (<code>$.Deferred</code>) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as <code>jqXHR.done()</code>.",
"arguments": []
},
{
"name": "beforeSend",
"type": "Function",
"desc": "A pre-request callback function that can be used to modify the jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object before it is sent. Use this to set custom headers, etc. The jqXHR and settings objects are passed as arguments. This is an <a href=\"/Ajax_Events/\">Ajax Event</a>. Returning <code>false</code> in the <code>beforeSend</code> function will cancel the request. <strong>As of jQuery 1.5</strong>, the <code>beforeSend</code> option will be called regardless of the type of request.",
"arguments": [{
"name": "jqXHR",
"type": "jqXHR"
},
{
"name": "settings",
"type": "PlainObject"
}
]
},
{
"name": "cache",
"default": "true, false for dataType 'script' and 'jsonp'",
"type": "Boolean",
"desc": "If set to <code>false</code>, it will force requested pages not to be cached by the browser. <strong>Note:</strong> Setting <code>cache</code> to false will only work correctly with HEAD and GET requests. It works by appending \"_={timestamp}\" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.",
"arguments": []
},
{
"name": "complete",
"type": "Function",
"desc": "A function to be called when the request finishes (after <code>success</code> and <code>error</code> callbacks are executed). The function gets passed two arguments: The jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object and a string categorizing the status of the request (<code>\"success\"</code>, <code>\"notmodified\"</code>, <code>\"nocontent\"</code>, <code>\"error\"</code>, <code>\"timeout\"</code>, <code>\"abort\"</code>, or <code>\"parsererror\"</code>). <strong>As of jQuery 1.5</strong>, the <code>complete</code> setting can accept an array of functions. Each function will be called in turn. This is an <a href=\"/Ajax_Events/\">Ajax Event</a>.",
"arguments": [{
"name": "jqXHR",
"type": "jqXHR"
},
{
"name": "textStatus",
"type": "String"
}
]
},
{
"name": "contents",
"type": "PlainObject",
"added": "1.5",
"desc": "An object of string/regular-expression pairs that determine how jQuery will parse the response, given its content type.",
"arguments": []
},
{
"default": "'application/x-www-form-urlencoded; charset=UTF-8'",
"name": "contentType",
"type": [
"Boolean",
"String"
],
"desc": "When sending data to the server, use this content type. Default is \"application/x-www-form-urlencoded; charset=UTF-8\", which is fine for most cases. If you explicitly pass in a content-type to <code>$.ajax()</code>, then it is always sent to the server (even if no data is sent). As of jQuery 1.6 you can pass <code>false</code> to tell jQuery to not set any content type header. <strong>Note:</strong> The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding. <strong>Note:</strong> For cross-domain requests, setting the content type to anything other than <code>application/x-www-form-urlencoded</code>, <code>multipart/form-data</code>, or <code>text/plain</code> will trigger the browser to send a preflight OPTIONS request to the server.",
"arguments": []
},
{
"name": "context",
"type": "PlainObject",
"desc": "This object will be the context of all Ajax-related callbacks. By default, the context is an object that represents the Ajax settings used in the call (<code>$.ajaxSettings</code> merged with the settings passed to <code>$.ajax</code>). For example, specifying a DOM element as the context will make that the context for the <code>complete</code> callback of a request, like so:\n <pre><code>\n$.ajax({\n url: \"test.html\",\n context: document.body\n}).done(function() {\n $( this ).addClass( \"done\" );\n});\n </code></pre>",
"arguments": []
},
{
"name": "converters",
"type": "PlainObject",
"default": "{\"* text\": window.String, \"text html\": true, \"text json\": jQuery.parseJSON, \"text xml\": jQuery.parseXML}",
"added": "1.5",
"desc": "An object containing dataType-to-dataType converters. Each converter's value is a function that returns the transformed value of the response.",
"arguments": []
},
{
"name": "crossDomain",
"type": "Boolean",
"default": "false for same-domain requests, true for cross-domain requests",
"added": "1.5",
"desc": "If you wish to force a crossDomain request (such as JSONP) on the same domain, set the value of crossDomain to <code>true</code>. This allows, for example, server-side redirection to another domain.",
"arguments": []
},
{
"name": "data",
"type": [
"PlainObject",
"String",
"Array"
],
"desc": "Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See <code>processData</code> option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key based on the value of the <code>traditional</code> setting (described below).",
"arguments": []
},
{
"name": "dataFilter",
"type": "Function",
"desc": "A function to be used to handle the raw response data of XMLHttpRequest. This is a pre-filtering function to sanitize the response. You should return the sanitized data. The function accepts two arguments: The raw data returned from the server and the 'dataType' parameter.",
"arguments": [{
"name": "data",
"type": "String"
},
{
"name": "type",
"type": "String"
}
]
},
{
"name": "dataType",
"default": "Intelligent Guess (xml, json, script, or html)",
"type": "String",
"desc": "The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string). The available types (and the result passed as the first argument to your success callback) are:\n <ul>\n <li><code>\"xml\"</code>: Returns a XML document that can be processed via jQuery.</li>\n <li><code>\"html\"</code>: Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.</li>\n <li><code>\"script\"</code>: Evaluates the response as JavaScript and returns it as plain text. Disables caching by appending a query string parameter, <code>_=[TIMESTAMP]</code>, to the URL unless the <code>cache</code> option is set to <code>true</code>. <strong>Note:</strong> This will turn POSTs into GETs for remote-domain requests.</li>\n <li><code>\"json\"</code>: Evaluates the response as JSON and returns a JavaScript object. Cross-domain <code>\"json\"</code> requests that have a callback placeholder, e.g. <code>?callback=?</code>, are performed using <a href=\"https://bob.ippoli.to/archives/2005/12/05/remote-json-jsonp/\">JSONP</a> unless the request includes <code>jsonp: false</code> in its request options. The JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. As of jQuery 1.9, an empty response is also rejected; the server should return a response of <code>null</code> or <code>{}</code> instead. (See <a href=\"https://json.org/\">json.org</a> for more information on proper JSON formatting.)</li>\n <li><code>\"jsonp\"</code>: Loads in a JSON block using <a href=\"https://bob.ippoli.to/archives/2005/12/05/remote-json-jsonp/\">JSONP</a>. Adds an extra <code>\"?callback=?\"</code> to the end of your URL to specify the callback. Disables caching by appending a query string parameter, <code>\"_=[TIMESTAMP]\"</code>, to the URL unless the <code>cache</code> option is set to <code>true</code>.</li>\n <li><code>\"text\"</code>: A plain text string.</li>\n <li>multiple, space-separated values: <strong>As of jQuery 1.5</strong>, jQuery can convert a dataType from what it received in the Content-Type header to what you require. For example, if you want a text response to be treated as XML, use <code>\"text xml\"</code> for the dataType. You can also make a JSONP request, have it received as text, and interpreted by jQuery as XML: <code>\"jsonp text xml\"</code>. Similarly, a shorthand string such as <code>\"jsonp xml\"</code> will first attempt to convert from jsonp to xml, and, failing that, convert from jsonp to text, and then from text to xml.</li>\n </ul>",
"arguments": []
},
{
"name": "error",
"type": "Function",
"desc": "A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides <code>null</code>) are <code>\"timeout\"</code>, <code>\"error\"</code>, <code>\"abort\"</code>, and <code>\"parsererror\"</code>. When an HTTP error occurs, <code>errorThrown</code> receives the textual portion of the HTTP status, such as \"Not Found\" or \"Internal Server Error.\" (in HTTP/2 it may instead be an empty string) <strong>As of jQuery 1.5</strong>, the <code>error</code> setting can accept an array of functions. Each function will be called in turn. <strong>Note:</strong> <em>This handler is not called for cross-domain script and cross-domain JSONP requests.</em> This is an <a href=\"/Ajax_Events/\">Ajax Event</a>.",
"arguments": [{
"name": "jqXHR",
"type": "jqXHR"
},
{
"name": "textStatus",
"type": "String"
},
{
"name": "errorThrown",
"type": "String"
}
]
},
{
"default": "true",
"name": "global",
"type": "Boolean",
"desc": "Whether to trigger global Ajax event handlers for this request. The default is <code>true</code>. Set to <code>false</code> to prevent the global handlers like <code>ajaxStart</code> or <code>ajaxStop</code> from being triggered. This can be used to control various <a href=\"/Ajax_Events/\">Ajax Events</a>.",
"arguments": []
},
{
"name": "headers",
"type": "PlainObject",
"default": "{}",
"added": "1.5",
"desc": "An object of additional header key/value pairs to send along with requests using the XMLHttpRequest transport. The header <code>X-Requested-With: XMLHttpRequest</code> is always added, but its default <code>XMLHttpRequest</code> value can be changed here. Values in the <code>headers</code> setting can also be overwritten from within the <code>beforeSend</code> function.",
"arguments": []
},
{
"default": "false",
"name": "ifModified",
"type": "Boolean",
"desc": "Allow the request to be successful only if the response has changed since the last request. This is done by checking the Last-Modified header. Default value is <code>false</code>, ignoring the header. In jQuery 1.4 this technique also checks the 'etag' specified by the server to catch unmodified data.",
"arguments": []
},
{
"default": "depends on current location protocol",
"name": "isLocal",
"type": "Boolean",
"added": "1.5.1",
"desc": "Allow the current environment to be recognized as \"local,\" (e.g. the filesystem), even if jQuery does not recognize it as such by default. The following protocols are currently recognized as local: <code>file</code>, <code>*-extension</code>, and <code>widget</code>. If the <code>isLocal</code> setting needs modification, it is recommended to do so once in the <code>$.ajaxSetup()</code> method.",
"arguments": []
},
{
"name": "jsonp",
"type": [
"String",
"Boolean"
],
"desc": "Override the callback function name in a JSONP request. This value will be used instead of 'callback' in the 'callback=?' part of the query string in the url. So <code>{jsonp:'onJSONPLoad'}</code> would result in <code>'onJSONPLoad=?'</code> passed to the server. <strong>As of jQuery 1.5</strong>, setting the <code>jsonp</code> option to <code>false</code> prevents jQuery from adding the \"?callback\" string to the URL or attempting to use \"=?\" for transformation. In this case, you should also explicitly set the <code>jsonpCallback</code> setting. For example, <code>{ jsonp: false, jsonpCallback: \"callbackName\" }</code>. If you don't trust the target of your Ajax requests, consider setting the <code>jsonp</code> property to <code>false</code> for security reasons.",
"arguments": []
},
{
"name": "jsonpCallback",
"type": [
"String",
"Function"
],
"desc": "Specify the callback function name for a JSONP request. This value will be used instead of the random name automatically generated by jQuery. It is preferable to let jQuery generate a unique name as it'll make it easier to manage the requests and provide callbacks and error handling. You may want to specify the callback when you want to enable better browser caching of GET requests. <strong>As of jQuery 1.5</strong>, you can also use a function for this setting, in which case the value of <code>jsonpCallback</code> is set to the return value of that function.",
"arguments": []
},
{
"default": "'GET'",
"name": "method",
"type": "String",
"added": "1.9.0",
"desc": "The HTTP method to use for the request (e.g. <code>\"POST\"</code>, <code>\"GET\"</code>, <code>\"PUT\"</code>).",
"arguments": []
},
{
"name": "mimeType",
"type": "String",
"added": "1.5.1",
"desc": "A mime type to override the <abbr title=\"XMLHttpRequest\">XHR</abbr> mime type.",
"arguments": []
},
{
"name": "password",
"type": "String",
"desc": "A password to be used with XMLHttpRequest in response to an HTTP access authentication request.",
"arguments": []
},
{
"default": "true",
"name": "processData",
"type": "Boolean",
"desc": "By default, data passed in to the <code>data</code> option as an object (technically, anything other than a string) will be processed and transformed into a query string, fitting to the default content-type \"application/x-www-form-urlencoded\". If you want to send a DOMDocument, or other non-processed data, set this option to <code>false</code>.",
"arguments": []
},
{
"name": "scriptAttrs",
"type": "PlainObject",
"added": "3.4.0",
"desc": "Defines an object with additional attributes to be used in a \"script\" or \"jsonp\" request. The key represents the name of the attribute and the value is the attribute's value. If this object is provided it will force the use of a script-tag transport. For example, this can be used to set <code>nonce</code>, <code>integrity</code>, or <code>crossorigin</code> attributes to satisfy Content Security Policy requirements.",
"arguments": []
},
{
"name": "scriptCharset",
"type": "String",
"desc": "Only applies when the \"script\" transport is used. Sets the <code>charset</code> attribute on the script tag used in the request. Used when the character set on the local page is not the same as the one on the remote script. Alternatively, the <code>charset</code> attribute can be specified in <code>scriptAttrs</code> instead, which will also ensure the use of the \"script\" transport.",
"arguments": []
},
{
"name": "statusCode",
"type": "PlainObject",
"default": "{}",
"added": "1.5",
"desc": "<p>An object of numeric HTTP codes and functions to be called when the response has the corresponding code. For example, the following will alert when the response status is a 404:</p>\n <pre><code>\n$.ajax({\n statusCode: {\n 404: function() {\n alert( \"page not found\" );\n }\n }\n});\n </code></pre>\n <p>If the request is successful, the status code functions take the same parameters as the success callback; if it results in an error (including 3xx redirect), they take the same parameters as the <code>error</code> callback.</p>",
"arguments": []
},
{
"name": "success",
"type": "Function",
"desc": "A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the <code>dataType</code> parameter or the <code>dataFilter</code> callback function, if specified; a string describing the status; and the <code>jqXHR</code> (in jQuery 1.4.x, XMLHttpRequest) object. <strong>As of jQuery 1.5</strong>, <em>the success setting can accept an array of functions. Each function will be called in turn.</em> This is an <a href=\"/Ajax_Events/\">Ajax Event</a>.",
"arguments": [{
"name": "data",
"type": "Anything"
},
{
"name": "textStatus",
"type": "String"
},
{
"name": "jqXHR",
"type": "jqXHR"
}
]
},
{
"name": "timeout",
"type": "Number",
"desc": "Set a timeout (in milliseconds) for the request. A value of 0 means there will be no timeout. This will override any global timeout set with <a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a>. The timeout period starts at the point the <code>$.ajax</code> call is made; if several other requests are in progress and the browser has no connections available, it is possible for a request to time out before it can be sent. <strong>In jQuery 1.4.x and below,</strong> the XMLHttpRequest object will be in an invalid state if the request times out; accessing any object members may throw an exception. <strong>In Firefox 3.0+ only,</strong> script and JSONP requests cannot be cancelled by a timeout; the script will run even if it arrives after the timeout period.",
"arguments": []
},
{
"name": "traditional",
"type": "Boolean",
"desc": "Set this to <code>true</code> if you wish to use the traditional style of <a href=\"/jQuery.param/\">param serialization</a>.",
"arguments": []
},
{
"default": "'GET'",
"name": "type",
"type": "String",
"desc": "An alias for <code>method</code>. You should use <code>type</code> if you're using versions of jQuery prior to 1.9.0.",
"arguments": []
},
{
"default": "The current page",
"name": "url",
"type": "String",
"desc": "A string containing the URL to which the request is sent.",
"arguments": []
},
{
"name": "username",
"type": "String",
"desc": "A username to be used with XMLHttpRequest in response to an HTTP access authentication request.",
"arguments": []
},
{
"name": "xhr",
"type": "Function",
"default": "ActiveXObject when available (IE), the XMLHttpRequest otherwise",
"desc": "Callback for creating the XMLHttpRequest object. Defaults to the ActiveXObject when available (IE), the XMLHttpRequest otherwise. Override to provide your own implementation for XMLHttpRequest or enhancements to the factory.",
"arguments": []
},
{
"name": "xhrFields",
"type": "PlainObject",
"added": "1.5.1",
"desc": "<p>An object of fieldName-fieldValue pairs to set on the native <code><abbr title=\"XMLHttpRequest\">XHR</abbr></code> object. For example, you can use it to set <code>withCredentials</code> to <code>true</code> for cross-domain requests if needed.</p>\n <pre><code>\n$.ajax({\n url: a_cross_domain_url,\n xhrFields: {\n withCredentials: true\n }\n});\n </code></pre>\n <p><strong>In jQuery 1.5</strong>, the <code>withCredentials</code> property was not propagated to the native <code>XHR</code> and thus CORS requests requiring it would ignore this flag. For this reason, we recommend using jQuery 1.5.1+ should you require the use of it.</p>",
"arguments": []
}
]
}],
"added": "1.0"
}
],
"desc": "Perform an asynchronous HTTP (Ajax) request.",
"longdesc": "<p>The <code>$.ajax()</code> function underlies all Ajax requests sent by jQuery. It is often unnecessary to directly call this function, as several higher-level alternatives like <code><a href=\"/jQuery.get/\">$.get()</a></code> and <code><a href=\"/load/\">.load()</a></code> are available and are easier to use. If less common options are required, though, <code>$.ajax()</code> can be used more flexibly.</p>\n <p>At its simplest, the <code>$.ajax()</code> function can be called with no arguments:</p>\n <pre><code>\n$.ajax();\n </code></pre>\n <p><strong>Note:</strong> Default settings can be set globally by using the <code><a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a></code> function.</p>\n <p>This example, using no options, loads the contents of the current page, but does nothing with the result. To use the result, you can implement one of the callback functions.</p>\n <h4 id=\"jqXHR\">The jqXHR Object</h4>\n <p>The jQuery XMLHttpRequest (jqXHR) object returned by <code>$.ajax()</code> <strong>as of jQuery 1.5</strong> is a superset of the browser's native XMLHttpRequest object. For example, it contains <code>responseText</code> and <code>responseXML</code> properties, as well as a <code>getResponseHeader()</code> method. When the transport mechanism is something other than XMLHttpRequest (for example, a script tag for a JSONP request) the <code>jqXHR</code> object simulates native XHR functionality where possible. </p>\n <p><strong>As of jQuery 1.5.1</strong>, the <code>jqXHR</code> object also contains the <code>overrideMimeType()</code> method (it was available in jQuery 1.4.x, as well, but was temporarily removed in jQuery 1.5). The <code>.overrideMimeType()</code> method may be used in the <code>beforeSend()</code> callback function, for example, to modify the response content-type header:</p>\n <pre><code>\n$.ajax({\n url: \"https://fiddle.jshell.net/favicon.png\",\n beforeSend: function( xhr ) {\n xhr.overrideMimeType( \"text/plain; charset=x-user-defined\" );\n }\n})\n .done(function( data ) {\n if ( console &amp;&amp; console.log ) {\n console.log( \"Sample of data:\", data.slice( 0, 100 ) );\n }\n });\n </code></pre>\n <p>The jqXHR objects returned by <code>$.ajax()</code> as of jQuery 1.5 implement the Promise interface, giving them all the properties, methods, and behavior of a Promise (see <a href=\"/category/deferred-object/\">Deferred object</a> for more information). These methods take one or more function arguments that are called when the <code>$.ajax()</code> request terminates. This allows you to assign multiple callbacks on a single request, and even to assign callbacks after the request may have completed. (If the request is already complete, the callback is fired immediately.) Available Promise methods of the jqXHR object include: </p>\n <ul>\n <li>\n <strong>jqXHR.done(function( data, textStatus, jqXHR ) {});</strong>\n <p>An alternative construct to the success callback option, refer to <code><a href=\"/deferred.done/\">deferred.done()</a></code> for implementation details.</p>\n </li>\n <li>\n <strong>jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});</strong>\n <p>An alternative construct to the error callback option, the <code>.fail()</code> method replaces the deprecated <code>.error()</code> method. Refer to <code><a href=\"/deferred.fail/\">deferred.fail()</a></code> for implementation details.\n </p>\n </li>\n <li>\n <strong>jqXHR.always(function( data|jqXHR, textStatus, jqXHR|errorThrown ) { });</strong> (added in jQuery 1.6)\n <p>An alternative construct to the complete callback option, the <code>.always()</code> method replaces the deprecated <code>.complete()</code> method.</p>\n <p>In response to a successful request, the function's arguments are the same as those of <code>.done()</code>: data, textStatus, and the jqXHR object. For failed requests the arguments are the same as those of <code>.fail()</code>: the jqXHR object, textStatus, and errorThrown. Refer to <code><a href=\"/deferred.always/\">deferred.always()</a></code> for implementation details.</p>\n </li>\n <li>\n <strong>jqXHR.then(function( data, textStatus, jqXHR ) {}, function( jqXHR, textStatus, errorThrown ) {});</strong>\n <p>Incorporates the functionality of the <code>.done()</code> and <code>.fail()</code> methods, allowing (as of jQuery 1.8) the underlying Promise to be manipulated. Refer to <a href=\"/deferred.then/\"><code>deferred.then()</code></a> for implementation details.\n </p>\n </li>\n </ul>\n <div class=\"warning\">\n <p><strong>Deprecation Notice:</strong> The <code>jqXHR.success()</code>, <code>jqXHR.error()</code>, and <code>jqXHR.complete()</code> callbacks are removed as of jQuery 3.0. You can use <code>jqXHR.done()</code>, <code>jqXHR.fail()</code>, and <code>jqXHR.always()</code> instead.</p>\n </div>\n <pre><code>\n// Assign handlers immediately after making the request,\n// and remember the jqXHR object for this request\nvar jqxhr = $.ajax( \"example.php\" )\n .done(function() {\n alert( \"success\" );\n })\n .fail(function() {\n alert( \"error\" );\n })\n .always(function() {\n alert( \"complete\" );\n });\n\n// Perform other work here ...\n\n// Set another completion function for the request above\njqxhr.always(function() {\n alert( \"second complete\" );\n});\n </code></pre>\n <p>The <code>this</code> reference within all callbacks is the object in the <code>context</code> option passed to <code>$.ajax</code> in the settings; if <code>context</code> is not specified, <code>this</code> is a reference to the Ajax settings themselves.</p>\n <p>For backward compatibility with <code>XMLHttpRequest</code>, a <code>jqXHR</code> object will expose the following properties and methods:</p>\n <ul>\n <li>\n <code>readyState</code>\n </li>\n <li>\n <code>responseXML</code> and/or <code>responseText</code> when the underlying request responded with xml and/or text, respectively\n </li>\n <li>\n <code>status</code>\n </li>\n <li>\n <code>statusText</code> (may be an empty string in HTTP/2)\n </li>\n <li>\n <code>abort( [ statusText ] )</code>\n </li>\n <li>\n <code>getAllResponseHeaders()</code> as a string\n </li>\n <li>\n <code>getResponseHeader( name )</code>\n </li>\n <li>\n <code>overrideMimeType( mimeType )</code>\n </li>\n <li>\n <code>setRequestHeader( name, value )</code> which departs from the standard by replacing the old value with the new one rather than concatenating the new value to the old one\n </li>\n <li>\n <code>statusCode( callbacksByStatusCode )</code>\n </li>\n </ul>\n <p>No <code>onreadystatechange</code> mechanism is provided, however, since <code>done</code>, <code>fail</code>, <code>always</code>, and <code>statusCode</code> cover all conceivable requirements.</p>\n <h4 id=\"callback-functions\">Callback Function Queues</h4>\n <p>The <code>beforeSend</code>, <code>error</code>, <code>dataFilter</code>, <code>success</code> and <code>complete</code> options all accept callback functions that are invoked at the appropriate times.</p>\n <p><strong>As of jQuery 1.5</strong>, the <code>fail</code> and <code>done</code>, and, as of jQuery 1.6, <code>always</code> callback hooks are first-in, first-out managed queues, allowing for more than one callback for each hook. See <a href=\"/category/deferred-object/\">Deferred object methods</a>, which are implemented internally for these <code>$.ajax()</code> callback hooks.</p>\n <p>The callback hooks provided by <code>$.ajax()</code> are as follows:</p>\n <ol>\n <li><code>beforeSend</code> callback option is invoked; it receives the <code>jqXHR</code> object and the <code>settings</code> object as parameters.</li>\n <li><code>error</code> callback option is invoked, if the request fails. It receives the <code>jqXHR</code>, a string indicating the error type, and an exception object if applicable. Some built-in errors will provide a string as the exception object: \"abort\", \"timeout\", \"No Transport\".</li>\n <li><code>dataFilter</code> callback option is invoked immediately upon successful receipt of response data. It receives the returned data and the value of <code>dataType</code>, and must return the (possibly altered) data to pass on to <code>success</code>.</li>\n <li><code>success</code> callback option is invoked, if the request succeeds. It receives the returned data, a string containing the success code, and the <code>jqXHR</code> object.</li>\n <li><strong>Promise callbacks</strong> — <code>.done()</code>, <code>.fail()</code>, <code>.always()</code>, and <code>.then()</code> — are invoked, in the order they are registered. </li>\n <li><code>complete</code> callback option fires, when the request finishes, whether in failure or success. It receives the <code>jqXHR</code> object, as well as a string containing the success or error code.</li>\n </ol>\n\n <h4 id=\"data-types\">Data Types</h4>\n <p>Different types of response to <code>$.ajax()</code> call are subjected to different kinds of pre-processing before being passed to the success handler. The type of pre-processing depends by default upon the Content-Type of the response, but can be set explicitly using the <code>dataType</code> option. If the <code>dataType</code> option is provided, the Content-Type header of the response will be disregarded.</p>\n <p>The available data types are <code>text</code>, <code>html</code>, <code>xml</code>, <code>json</code>, <code>jsonp</code>, and <code>script</code>.</p>\n <p>If <code>text</code> or <code>html</code> is specified, no pre-processing occurs. The data is simply passed on to the success handler, and made available through the <code>responseText</code> property of the <code>jqXHR</code> object.</p>\n <p>If <code>xml</code> is specified, the response is parsed using <a href=\"/jQuery.parseXML/\"><code>jQuery.parseXML</code></a> before being passed, as an <a href=\"https://api.jquery.com/Types/#XMLDocument\"><code>XMLDocument</code></a>, to the success handler. The XML document is made available through the <code>responseXML</code> property of the <code>jqXHR</code> object.</p>\n <p>If <code>json</code> is specified, the response is parsed using <a href=\"/jQuery.parseJSON/\"><code>jQuery.parseJSON</code></a> before being passed, as an object, to the success handler. The parsed JSON object is made available through the <code>responseJSON</code> property of the <code>jqXHR</code> object.</p>\n <p>If <code>script</code> is specified, <code>$.ajax()</code> will execute the JavaScript that is received from the server before passing it on to the success handler as a string.</p>\n <p>If <code>jsonp</code> is specified, <code>$.ajax()</code> will automatically append a query string parameter of (by default) <code>callback=?</code> to the URL. The <code>jsonp</code> and <code>jsonpCallback</code> properties of the settings passed to <code>$.ajax()</code> can be used to specify, respectively, the name of the query string parameter and the name of the JSONP callback function. The server should return valid JavaScript that passes the JSON response into the callback function. <code>$.ajax()</code> will execute the returned JavaScript, calling the JSONP callback function, before passing the JSON object contained in the response to the <code>$.ajax()</code> success handler.</p>\n <p>For more information on JSONP, see the <a href=\"https://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/\">original post detailing its use</a>.</p>\n <h4 id=\"sending-data-to-server\">Sending Data to the Server</h4>\n <p>By default, Ajax requests are sent using the GET HTTP method. If the POST method is required, the method can be specified by setting a value for the <code>type</code> option. This option affects how the contents of the <code>data</code> option are sent to the server. POST data will always be transmitted to the server using UTF-8 charset, per the W3C XMLHTTPRequest standard.</p>\n <p>The <code>data</code> option can contain either a query string of the form <code>key1=value1&amp;key2=value2</code>, or an object of the form <code>{key1: 'value1', key2: 'value2'}</code>. If the latter form is used, the data is converted into a query string using <code><a href=\"/jQuery.param/\">jQuery.param()</a></code> before it is sent. This processing can be circumvented by setting <code>processData</code> to <code>false</code>. The processing might be undesirable if you wish to send an XML object to the server; in this case, change the <code>contentType</code> option from <code>application/x-www-form-urlencoded</code> to a more appropriate MIME type.</p>\n <h4 id=\"advanced-options\">Advanced Options</h4>\n <p>The <code>global</code> option prevents handlers registered using <code><a href=\"/ajaxSend/\">.ajaxSend()</a></code>, <code><a href=\"/ajaxError/\">.ajaxError()</a></code>, and similar methods from firing when this request would trigger them. This can be useful to, for example, suppress a loading indicator that was implemented with <code><a href=\"/ajaxSend/\">.ajaxSend()</a></code> if the requests are frequent and brief. With cross-domain script and JSONP requests, the global option is automatically set to <code>false</code>. See the descriptions of these methods below for more details.</p>\n <p>If the server performs HTTP authentication before providing a response, the user name and password pair can be sent via the <code>username</code> and <code>password</code> options.</p>\n <p>Ajax requests are time-limited, so errors can be caught and handled to provide a better user experience. Request timeouts are usually either left at their default or set as a global default using <code><a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a></code> rather than being overridden for specific requests with the <code>timeout</code> option.</p>\n <p>By default, requests are always issued, but the browser may serve results out of its cache. To disallow use of the cached results, set <code>cache</code> to <code>false</code>. To cause the request to report failure if the asset has not been modified since the last request, set <code>ifModified</code> to <code>true</code>.</p>\n <p>The <code>scriptCharset</code> allows the character set to be explicitly specified for requests that use a <code>&lt;script&gt;</code> tag (that is, a type of <code>script</code> or <code>jsonp</code>). This is useful if the script and host page have differing character sets.</p>\n <p>The first letter in Ajax stands for \"asynchronous,\" meaning that the operation occurs in parallel and the order of completion is not guaranteed. The <code>async</code> option to <code>$.ajax()</code> defaults to <code>true</code>, indicating that code execution can continue after the request is made. Setting this option to <code>false</code> (and thus making the call no longer asynchronous) is strongly discouraged, as it can cause the browser to become unresponsive.</p>\n <p>The <code>$.ajax()</code> function returns the <code>XMLHttpRequest</code> object that it creates. Normally jQuery handles the creation of this object internally, but a custom function for manufacturing one can be specified using the <code>xhr</code> option. The returned object can generally be discarded, but does provide a lower-level interface for observing and manipulating the request. In particular, calling <code>.abort()</code> on the object will halt the request before it completes.</p>\n\n <h4 id=\"extending-ajax\">Extending Ajax</h4>\n <p><strong>As of jQuery 1.5</strong>, jQuery's Ajax implementation includes <a href=\"/jQuery.ajaxPrefilter/\">prefilters</a>, <a href=\"/jQuery.ajaxTransport/\">transports</a>, and converters that allow you to extend Ajax with a great deal of flexibility.</p>\n\n <h4 id=\"using-converters\">Using Converters</h4>\n <p><code>$.ajax()</code> converters support mapping data types to other data types. If, however, you want to map a custom data type to a known type (e.g <code>json</code>), you must add a correspondence between the response Content-Type and the actual data type using the <code>contents</code> option:</p>\n <pre><code>\n$.ajaxSetup({\n contents: {\n mycustomtype: /mycustomtype/\n },\n converters: {\n \"mycustomtype json\": function( result ) {\n // Do stuff\n return newresult;\n }\n }\n});\n </code></pre>\n <p>This extra object is necessary because the response Content-Types and data types never have a strict one-to-one correspondence (hence the regular expression).</p>\n <p>To convert from a supported type (e.g <code>text</code>, <code>json</code>) to a custom data type and back again, use another pass-through converter:</p>\n <pre><code>\n$.ajaxSetup({\n contents: {\n mycustomtype: /mycustomtype/\n },\n converters: {\n \"text mycustomtype\": true,\n \"mycustomtype json\": function( result ) {\n // Do stuff\n return newresult;\n }\n }\n});\n </code></pre>\n <p>The above now allows passing from <code>text</code> to <code>mycustomtype</code> and then <code>mycustomtype</code> to <code>json</code>.</p>",
"note": [{
"type": "additional",
"text": "Script and JSONP requests are not subject to the same origin policy restrictions."
},
{
"type": "additional",
"text": "Script and JSONP requests are not subject to the same origin policy restrictions."
}
],
"examples": [{
"desc": "Save some data to the server and notify the user once it's complete.",
"code": "$.ajax({\n method: \"POST\",\n url: \"some.php\",\n data: { name: \"John\", location: \"Boston\" }\n})\n .done(function( msg ) {\n alert( \"Data Saved: \" + msg );\n });",
"html": "",
"css": ""
},
{
"desc": "Retrieve the latest version of an HTML page.",
"code": "$.ajax({\n url: \"test.html\",\n cache: false\n})\n .done(function( html ) {\n $( \"#results\" ).append( html );\n });",
"html": "",
"css": ""
},
{
"desc": "Send an xml document as data to the server. By setting the processData\n option to <code>false</code>, the automatic conversion of data to strings is prevented.",
"code": "var xmlDocument = [create xml document];\nvar xmlRequest = $.ajax({\n url: \"page.php\",\n processData: false,\n data: xmlDocument\n});\n\nxmlRequest.done( handleResponse );",
"html": "",
"css": ""
},
{
"desc": "Send an id as data to the server, save some data to the server, and notify the user once it's complete. If the request fails, alert the user.",
"code": "var menuId = $( \"ul.nav\" ).first().attr( \"id\" );\nvar request = $.ajax({\n url: \"script.php\",\n method: \"POST\",\n data: { id : menuId },\n dataType: \"html\"\n});\n\nrequest.done(function( msg ) {\n $( \"#log\" ).html( msg );\n});\n\nrequest.fail(function( jqXHR, textStatus ) {\n alert( \"Request failed: \" + textStatus );\n});",
"html": "",
"css": ""
},
{
"desc": "Load and execute a JavaScript file.",
"code": "$.ajax({\n method: \"GET\",\n url: \"test.js\",\n dataType: \"script\"\n});",
"html": "",
"css": ""
}
],
"categories": [
"ajax/low-level-interface",
"version/1.0",
"version/1.5",
"version/1.5.1"
]
},
{
"title": "jQuery.ajaxPrefilter()",
"type": "method",
"name": "jQuery.ajaxPrefilter",
"return": "undefined",
"signatures": [{
"arguments": [{
"name": "dataTypes",
"optional": "true",
"type": "String",
"desc": "An optional string containing one or more space-separated dataTypes"
},
{
"name": "handler",
"type": "Function",
"desc": "A handler to set default values for future Ajax requests.",
"arguments": [{
"name": "options",
"type": "PlainObject"
},
{
"name": "originalOptions",
"type": "PlainObject"
},
{
"name": "jqXHR",
"type": "jqXHR"
}
]
}
],
"added": "1.5"
}],
"desc": "Handle custom Ajax options or modify existing options before each request is sent and before they are processed by <code>$.ajax()</code>.",
"longdesc": "<p>A typical prefilter registration using <code>$.ajaxPrefilter()</code> looks like this:</p>\n <pre><code>\n$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {\n // Modify options, control originalOptions, store jqXHR, etc\n});\n </code></pre>\n <p>where:</p>\n <ul>\n <li><code>options</code> are the request options</li>\n <li><code>originalOptions</code> are the options as provided to the <code>$.ajax()</code> method, unmodified and, thus, without defaults from <code>ajaxSettings</code></li>\n <li><code>jqXHR</code> is the jqXHR object of the request</li>\n </ul>\n <p>Prefilters are a perfect fit when custom options need to be handled. Given the following code, for example, a call to <code>$.ajax()</code> would automatically abort a request to the same URL if the custom <code>abortOnRetry</code> option is set to <code>true</code>:</p>\n <pre><code>\nvar currentRequests = {};\n\n$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {\n if ( options.abortOnRetry ) {\n if ( currentRequests[ options.url ] ) {\n currentRequests[ options.url ].abort();\n }\n currentRequests[ options.url ] = jqXHR;\n }\n});\n </code></pre>\n <p>Prefilters can also be used to modify existing options. For example, the following proxies cross-domain requests through https://mydomain.net/proxy/:</p>\n <pre><code>\n$.ajaxPrefilter(function( options ) {\n if ( options.crossDomain ) {\n options.url = \"https://mydomain.net/proxy/\" + encodeURIComponent( options.url );\n options.crossDomain = false;\n }\n});\n </code></pre>\n <p>If the optional <code>dataTypes</code> argument is supplied, the prefilter will be only be applied to requests with the indicated dataTypes. For example, the following only applies the given prefilter to JSON and script requests:</p>\n <pre><code>\n$.ajaxPrefilter( \"json script\", function( options, originalOptions, jqXHR ) {\n // Modify options, control originalOptions, store jqXHR, etc\n});\n </code></pre>\n <p>The <code>$.ajaxPrefilter()</code> method can also redirect a request to another dataType by returning that dataType. For example, the following sets a request as \"script\" if the URL has some specific properties defined in a custom <code>isActuallyScript()</code> function:</p>\n <pre><code>\n$.ajaxPrefilter(function( options ) {\n if ( isActuallyScript( options.url ) ) {\n return \"script\";\n }\n});\n </code></pre>\n <p>This would ensure not only that the request is considered \"script\" but also that all the prefilters specifically attached to the script dataType would be applied to it.</p>",
"examples": [],
"categories": [
"ajax/low-level-interface",
"version/1.5"
]
},
{
"title": "jQuery.ajaxSetup()",
"type": "method",
"name": "jQuery.ajaxSetup",
"return": "PlainObject",
"signatures": [{
"arguments": [{
"name": "options",
"type": "PlainObject",
"desc": "A set of key/value pairs that configure the default Ajax request. All options are optional."
}],
"added": "1.1"
}],
"desc": "Set default values for future Ajax requests. Its use is not recommended.",
"longdesc": "<p>For details on the settings available for <code>$.ajaxSetup()</code>, see <code><a href=\"/jQuery.ajax/\">$.ajax()</a></code>. </p>\n <p>All subsequent Ajax calls using any function will use the new settings, unless overridden by the individual calls, until the next invocation of <code>$.ajaxSetup()</code>.</p>\n <p><strong>Note:</strong> The settings specified here will affect <em>all</em> calls to <code>$.ajax</code> or Ajax-based derivatives such as <code>$.get()</code>. This can cause undesirable behavior since other callers (for example, plugins) may be expecting the normal default settings. For that reason we <em>strongly recommend against using this API</em>. Instead, set the options explicitly in the call or define a simple plugin to do so.</p>\n <p>For example, the following sets a default for the <code>url</code> parameter before pinging the server repeatedly:</p>\n <pre><code>\n$.ajaxSetup({\n url: \"ping.php\"\n});\n </code></pre>\n <p>Now each time an Ajax request is made, the \"ping.php\" URL will be used automatically:</p>\n <pre><code>\n$.ajax({\n // url not set here; uses ping.php\n data: { \"name\": \"Dan\" }\n});\n </code></pre>\n <div class=\"warning\">\n <p>Note: Global callback functions should be set with their respective global Ajax event handler methods—<code><a href=\"/ajaxStart/\">.ajaxStart()</a></code>, <code><a href=\"/ajaxStop/\">.ajaxStop()</a></code>, <code><a href=\"/ajaxComplete/\">.ajaxComplete()</a></code>, <code><a href=\"/ajaxError/\">.ajaxError()</a></code>, <code><a href=\"/ajaxSuccess/\">.ajaxSuccess()</a></code>, <code><a href=\"/ajaxSend/\">.ajaxSend()</a></code>—rather than within the <code>options</code> object for <code>$.ajaxSetup()</code>.</p>\n </div>",
"examples": [{
"desc": "Sets the defaults for Ajax requests to the url \"/xmlhttp/\", disables global handlers and uses POST instead of GET. The following Ajax requests then sends some data without having to set anything else.",
"code": "$.ajaxSetup({\n url: \"/xmlhttp/\",\n global: false,\n type: \"POST\"\n});\n$.ajax({ data: myData });",
"html": "",
"css": ""
}],
"categories": [
"ajax/low-level-interface",
"version/1.1"
]
},
{
"title": "jQuery.ajaxTransport()",
"type": "method",
"name": "jQuery.ajaxTransport",
"return": "undefined",
"signatures": [{
"arguments": [{
"name": "dataType",
"type": "String",
"desc": "A string identifying the data type to use"
},
{
"name": "handler",
"type": "Function",
"desc": "A handler to return the new transport object to use with the data type provided in the first argument.",
"arguments": [{
"name": "options",
"type": "PlainObject"
},
{
"name": "originalOptions",
"type": "PlainObject"
},
{
"name": "jqXHR",
"type": "jqXHR"
}
]
}
],
"added": "1.5"
}],
"desc": "Creates an object that handles the actual transmission of Ajax data.",
"longdesc": "<p>A transport is an object that provides two methods, <code>send</code> and <code>abort</code>, that are used internally by <code>$.ajax()</code> to issue requests. A transport is the most advanced way to enhance <code>$.ajax()</code> and should be used only as a last resort when prefilters and converters are insufficient.</p>\n <p>Since each request requires its own transport object instance, transports cannot be registered directly. Therefore, you should provide a function that returns a transport instead.</p>\n <p>Transports factories are registered using <code>$.ajaxTransport()</code>. A typical registration looks like this:</p>\n <pre><code>\n$.ajaxTransport( dataType, function( options, originalOptions, jqXHR ) {\n if( /* transportCanHandleRequest */ ) {\n return {\n send: function( headers, completeCallback ) {\n // Send code\n },\n abort: function() {\n // Abort code\n }\n };\n }\n});\n </code></pre>\n <p>where:</p>\n <ul>\n <li><code>options</code> are the request options</li>\n <li><code>originalOptions</code> are the options as provided to the <code>$.ajax()</code> method, unmodified and, thus, without defaults from ajaxSettings</li>\n <li><code>jqXHR</code> is the jqXHR object of the request</li>\n <li><code>headers</code> is an object of (key-value) request headers that the transport can transmit if it supports it</li>\n <li><code>completeCallback</code> is the callback used to notify Ajax of the completion of the request</li>\n </ul>\n <p><code>completeCallback</code> has the following signature:</p>\n <pre><code>\nfunction( status, statusText, responses, headers ) {}\n </code></pre>\n <p>where:</p>\n <ul>\n <li><code>status</code> is the HTTP status code of the response, like 200 for a typical success, or 404 for when the resource is not found.</li>\n <li><code>statusText</code> is the statusText of the response.</li>\n <li><code>responses</code> (Optional) is An object containing dataType/value that contains the response in all the formats the transport could provide (for instance, a native XMLHttpRequest object would set responses to <code>{ xml: XMLData, text: textData }</code> for a response that is an XML document)</li>\n <li><code>headers</code> (Optional) is a string containing all the response headers if the transport has access to them (akin to what <code>XMLHttpRequest.getAllResponseHeaders()</code> would provide).</li>\n </ul>\n <p>Just like prefilters, a transport's factory function can be attached to a specific dataType:</p>\n <pre><code>\n$.ajaxTransport( \"script\", function( options, originalOptions, jqXHR ) {\n // Will only be called for script requests\n});\n </code></pre>\n <p>The following example shows how a minimal image transport could be implemented:</p>\n <pre><code>\n$.ajaxTransport( \"image\", function( s ) {\n if ( s.type === \"GET\" &amp;&amp; s.async ) {\n var image;\n return {\n send: function( _ , callback ) {\n image = new Image();\n function done( status ) {\n if ( image ) {\n var statusText = ( status === 200 ) ? \"success\" : \"error\",\n tmp = image;\n image = image.onreadystatechange = image.onerror = image.onload = null;\n callback( status, statusText, { image: tmp } );\n }\n }\n image.onreadystatechange = image.onload = function() {\n done( 200 );\n };\n image.onerror = function() {\n done( 404 );\n };\n image.src = s.url;\n },\n abort: function() {\n if ( image ) {\n image = image.onreadystatechange = image.onerror = image.onload = null;\n }\n }\n };\n }\n});\n </code></pre>\n <h4 id=\"handling-custom-data-types\">Handling Custom Data Types</h4>\n <p>The jQuery Ajax implementation comes with a set of standard dataTypes, such as text, json, xml, and html.</p>\n <p>Use the <code>converters</code> option in <code><a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a></code> to augment or modify the data type conversion strategies used by <code>$.ajax()</code>.</p>\n <p> The unminified jQuery source itself includes a list of default converters, which effectively illustrates how they can be used: </p>\n <pre><code>\n// List of data converters\n// 1) Key format is \"source_type destination_type\"\n// (a single space in-between)\n// 2) The catchall symbol \"*\" can be used for source_type\nconverters: {\n // Convert anything to text\n \"* text\": window.String,\n // Text to html (true = no transformation)\n \"text html\": true,\n // Evaluate text as a json expression\n \"text json\": jQuery.parseJSON,\n // Parse text as xml\n \"text xml\": jQuery.parseXML\n}\n </code></pre>\n <p>When you specify a <code>converters</code> option globally in <code>$.ajaxSetup()</code> or per call in <code>$.ajax()</code>, the object will map onto the default converters, overwriting those you specify and leaving the others intact.</p>\n <p>For example, the jQuery source uses <code>$.ajaxSetup()</code> to add a converter for \"text script\":</p>\n <pre><code>\njQuery.ajaxSetup({\n accepts: {\n script: \"text/javascript, application/javascript\"\n },\n contents: {\n script: /javascript/\n },\n converters: {\n \"text script\": jQuery.globalEval\n }\n});\n </code></pre>",
"examples": [],
"categories": [
"ajax/low-level-interface",
"version/1.5"
]
},
{
"title": "jQuery.boxModel",
"type": "property",
"name": "jQuery.boxModel",
"return": "Boolean",
"deprecated": "1.3",
"removed": "1.8",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "States if the current page, in the user's browser, is being rendered using the <a href=\"https://www.w3.org/TR/REC-CSS2/box.html\">W3C CSS Box Model</a>.",
"longdesc": "<div class=\"warning\">\n <p>Note: This API has been removed in jQuery 3.0; check if <code>.document.compatMode</code> is equal to <code>\"CSS1Compat\"</code> instead. Or, even better - always specify a DOCTYPE and avoid using quirks mode which jQuery doesn't support.</p>\n </div>",
"examples": [],
"categories": [
"utilities",
"version/1.0",
"deprecated/deprecated-1.3",
"removed"
]
},
{
"entries": [{
"title": "jQuery.browser",
"type": "property",
"name": "jQuery.browser",
"return": "PlainObject",
"deprecated": "1.3",
"removed": "1.9",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Contains flags for the useragent, read from navigator.userAgent. <strong>This property was removed in jQuery 1.9</strong> and is available only through the jQuery.migrate plugin. Please try to use feature detection instead.",
"longdesc": "<div class=\"warning\">\n <p>Note: This API has been removed in jQuery 1.9; please rely on feature detection instead.</p>\n </div>\n <p>The <code>$.browser</code> property provides information about the web browser that is accessing the page, as reported by the browser itself. It contains flags for each of the four most prevalent browser classes (Internet Explorer, Mozilla, Webkit, and Opera) as well as version information.</p>\n <p>Available flags are:</p>\n <ul>\n <li>webkit (as of jQuery 1.4)</li>\n <li>safari (deprecated)</li>\n <li>opera</li>\n <li>msie</li>\n <li>mozilla</li>\n </ul>\n <p>This property is available immediately. It is therefore safe to use it to determine whether or not to call <code>$(document).ready()</code>.\n The <code>$.browser</code> property is deprecated in jQuery 1.3, and its functionality may be moved to a team-supported plugin in a future release of jQuery.</p>\n <p>Because <code>$.browser</code> uses <code>navigator.userAgent</code> to determine the platform, it is vulnerable to spoofing by the user or misrepresentation by the browser itself. It is always best to avoid browser-specific code entirely where possible. Instead of relying on <code>$.browser</code> it's better to use libraries like <a href=\"https://modernizr.com/\">Modernizr</a>.</p>",
"examples": [{
"desc": "Show the browser info.",
"code": "jQuery.each( jQuery.browser, function( i, val ) {\n $( \"<div>\" + i + \" : <span>\" + val + \"</span>\" )\n .appendTo( document.body );\n});",
"html": "",
"css": ""
},
{
"desc": "Return true if the current useragent is some version of Microsoft's Internet Explorer. <strong>Will not work in jQuery 1.9 or later</strong> unless the <a href=\"https://github.com/jquery/jquery-migrate/#readme\">jQuery Migrate</a> plugin is included.",
"code": "$.browser.msie;",
"html": "",
"css": ""
},
{
"desc": "Alert \"this is WebKit!\" only for WebKit browsers. <strong>Will not work in jQuery 1.9 or later</strong> unless the <a href=\"https://github.com/jquery/jquery-migrate/#readme\">jQuery Migrate</a> plugin is included.",
"code": "if ( $.browser.webkit ) {\n alert( \"This is WebKit!\" );\n }",
"html": "",
"css": ""
}
],
"categories": [
"properties/global-jquery-object-properties",
"utilities",
"version/1.0",
"version/1.1.3",
"deprecated/deprecated-1.3",
"removed"
]
},
{
"title": "",
"type": "property",
"name": "jQuery.browser.version",
"return": "String",
"deprecated": "1.3",
"removed": "1.9",
"signatures": [{
"arguments": [],
"added": "1.1.3"
}],
"desc": "The version number of the rendering engine for the user's browser. <strong>This property was removed in jQuery 1.9</strong> and is available only through the jQuery.migrate plugin.",
"longdesc": "<div class=\"warning\">\n <p>Note: This API has been removed in jQuery 1.9; please rely on feature detection instead.</p>\n </div>\n <p>Here are some typical results:</p>\n <ul>\n <li>Internet Explorer: 6.0, 7.0, 8.0</li>\n <li>Mozilla/Firefox/Flock/Camino: 1.7.12, 1.8.1.3, 1.9</li>\n <li>Opera: 10.06, 11.01</li>\n <li>Safari/Webkit: 312.8, 418.9</li>\n </ul>\n <p>Note that IE8 claims to be 7 in Compatibility View.</p>",
"examples": [{
"desc": "Return the version number of the rendering engine used by the user's current browser. For example, FireFox 4 returns 2.0 (the version of the Gecko rendering engine it utilizes). <strong>Will not work in jQuery 1.9 or later</strong> unless the <a href=\"https://github.com/jquery/jquery-migrate/#readme\">jQuery Migrate</a> plugin is included.",
"code": "$( \"p\" ).html( \"The version # of the browser's rendering engine is: <span>\" +\n $.browser.version + \"</span>\" );",
"html": "",
"css": ""
},
{
"desc": "Alert the version of IE's rendering engine that is being used. <strong>Will not work in jQuery 1.9 or later</strong> unless the <a href=\"https://github.com/jquery/jquery-migrate/#readme\">jQuery Migrate</a> plugin is included.",
"code": "if ( $.browser.msie ) {\n alert( $.browser.version );\n}",
"html": "",
"css": ""
}
],
"categories": [
"properties/global-jquery-object-properties",
"utilities",
"version/1.0",
"version/1.1.3",
"deprecated/deprecated-1.3",
"removed"
]
}
]
},
{
"title": "jQuery.contains()",
"type": "method",
"name": "jQuery.contains",
"return": "Boolean",
"signatures": [{
"arguments": [{
"name": "container",
"type": "Element",
"desc": "The DOM element that may contain the other element."
},
{
"name": "contained",
"type": "Element",
"desc": "The DOM element that may be contained by (a descendant of) the other element."
}
],
"added": "1.4"
}],
"desc": "Check to see if a DOM element is a descendant of another DOM element.",
"longdesc": "<p>The <code>$.contains()</code> method returns <code>true</code> if the DOM element provided by the second argument is a descendant of the DOM element provided by the first argument, whether it is a direct child or nested more deeply. Otherwise, it returns <code>false</code>. Only <em>element</em> nodes are supported; if the second argument is a text or comment node, <code>$.contains()</code> will return <code>false</code>.</p>\n <div class=\"warning\">\n <p><strong>Note:</strong> The first argument <em>must</em> be a DOM element, not a jQuery object or plain JavaScript object.</p>\n </div>",
"examples": [{
"desc": "Check if an element is a descendant of another.",
"code": "$.contains( document.documentElement, document.body ); // true\n$.contains( document.body, document.documentElement ); // false",
"html": "",
"css": ""
}],
"categories": [
"utilities",
"version/1.4"
]
},
{
"title": "jQuery.cssHooks",
"type": "property",
"name": "jQuery.cssHooks",
"return": "Object",
"signatures": [{
"arguments": [],
"added": "1.4.3"
}],
"desc": "Hook directly into jQuery to override how particular CSS properties are retrieved or set, normalize CSS property naming, or create custom properties.",
"longdesc": "<p>The <code>$.cssHooks</code> object provides a way to define functions for getting and setting particular CSS values. It can also be used to create new cssHooks for normalizing CSS3 features such as box shadows and gradients. </p>\n <p>For example, some versions of Webkit-based browsers require <code>-webkit-border-radius</code> to set the <code>border-radius</code> on an element, while earlier Firefox versions require <code>-moz-border-radius</code>. A css hook can normalize these vendor-prefixed properties to let <code>.css()</code> accept a single, standard property name (<code>border-radius</code>, or with DOM property syntax, <code>borderRadius</code>).</p>\n <p>In addition to providing fine-grained control over how specific style properties are handled, <code>$.cssHooks</code> also extends the set of properties available to the <code>.animate()</code> method.</p>\n <p>Defining a new css hook is straight-forward. The skeleton template below can serve as a guide to creating your own. </p>\n <pre><code>\n(function( $ ) {\n\n// First, check to see if cssHooks are supported\nif ( !$.cssHooks ) {\n // If not, output an error message\n throw( new Error( \"jQuery 1.4.3 or above is required for this plugin to work\" ) );\n}\n\n// Wrap in a document ready call, because jQuery writes\n// cssHooks at this time and will blow away your functions\n// if they exist.\n$(function () {\n $.cssHooks[ \"someCSSProp\" ] = {\n get: function( elem, computed, extra ) {\n // Handle getting the CSS property\n },\n set: function( elem, value ) {\n // Handle setting the CSS value\n }\n };\n});\n\n})( jQuery );\n </code></pre>\n <h4 id=\"feature-testing\">Feature Testing</h4>\n <p>Before normalizing a vendor-specific CSS property, first determine whether the browser supports the standard property or a vendor-prefixed variation. For example, to check for support of the <code>border-radius</code> property, see if any variation is a member of a temporary element's <code>style</code> object.</p>\n <pre><code>\n(function( $ ) {\n\nfunction styleSupport( prop ) {\n var vendorProp, supportedProp,\n\n // Capitalize first character of the prop to test vendor prefix\n capProp = prop.charAt( 0 ).toUpperCase() + prop.slice( 1 ),\n prefixes = [ \"Moz\", \"Webkit\", \"ms\" ],\n div = document.createElement( \"div\" );\n\n if ( prop in div.style ) {\n\n // Browser supports standard CSS property name\n supportedProp = prop;\n } else {\n\n // Otherwise test support for vendor-prefixed property names\n for ( var i = 0; i &lt; prefixes.length; i++ ) {\n vendorProp = prefixes[ i ] + capProp;\n if ( vendorProp in div.style ) {\n supportedProp = vendorProp;\n break;\n }\n }\n }\n\n // Avoid memory leak in IE\n div = null;\n\n // Add property to $.support so it can be accessed elsewhere\n $.support[ prop ] = supportedProp;\n return supportedProp;\n}\n\n// Call the function, e.g. testing for \"border-radius\" support:\nstyleSupport( \"borderRadius\" );\n\n})( jQuery );\n </code></pre>\n <h4 id=\"defining-complete-csshook\">Defining a complete css hook</h4>\n <p>To define a complete css hook, combine the support test with a filled-out version of the skeleton template provided in the first example:</p>\n <pre><code>\n(function( $ ) {\n\nif ( !$.cssHooks ) {\n throw( new Error( \"jQuery 1.4.3+ is needed for this plugin to work\" ) );\n}\n\nfunction styleSupport( prop ) {\n var vendorProp, supportedProp,\n capProp = prop.charAt( 0 ).toUpperCase() + prop.slice( 1 ),\n prefixes = [ \"Moz\", \"Webkit\", \"ms\" ],\n div = document.createElement( \"div\" );\n\n if ( prop in div.style ) {\n supportedProp = prop;\n } else {\n for ( var i = 0; i &lt; prefixes.length; i++ ) {\n vendorProp = prefixes[ i ] + capProp;\n if ( vendorProp in div.style ) {\n supportedProp = vendorProp;\n break;\n }\n }\n }\n\n div = null;\n $.support[ prop ] = supportedProp;\n return supportedProp;\n}\n\nvar borderRadius = styleSupport( \"borderRadius\" );\n\n// Set cssHooks only for browsers that support a vendor-prefixed border radius\nif ( borderRadius &amp;&amp; borderRadius !== \"borderRadius\" ) {\n $.cssHooks.borderRadius = {\n get: function( elem, computed, extra ) {\n return $.css( elem, borderRadius );\n },\n set: function( elem, value) {\n elem.style[ borderRadius ] = value;\n }\n };\n}\n\n})( jQuery );\n </code></pre>\n <p>You can then set the border radius in a supported browser using either the DOM (camelCased) style or the CSS (hyphenated) style:</p>\n <pre><code>\n$( \"#element\" ).css( \"borderRadius\", \"10px\" );\n$( \"#another\" ).css( \"border-radius\", \"20px\" );\n </code></pre>\n <p>If the browser lacks support for any form of the CSS property, vendor-prefixed or not, the style is not applied to the element. However, if the browser supports a proprietary alternative, it can be applied to the cssHooks instead. </p>\n <pre><code>\n(function( $ ) {\n\n// Feature test for support of a CSS property\n// and a proprietary alternative\n// ...\nif ( $.support.someCSSProp &amp;&amp; $.support.someCSSProp !== \"someCSSProp\" ) {\n\n // Set cssHooks for browsers that\n // support only a vendor-prefixed someCSSProp\n $.cssHooks.someCSSProp = {\n get: function( elem, computed, extra ) {\n return $.css( elem, $.support.someCSSProp );\n },\n set: function( elem, value) {\n elem.style[ $.support.someCSSProp ] = value;\n }\n };\n} else if ( supportsProprietaryAlternative ) {\n $.cssHooks.someCSSProp = {\n get: function( elem, computed, extra ) {\n // Handle crazy conversion from the proprietary alternative\n },\n set: function( elem, value ) {\n // Handle crazy conversion to the proprietary alternative\n }\n }\n}\n\n})( jQuery );\n </code></pre>\n <h4 id=\"special-units\">Special units</h4>\n <p>By default, jQuery adds a \"px\" unit to the values passed to the <code>.css()</code> method. This behavior can be prevented by adding the property to the <a href=\"/jQuery.cssNumer/\"><code>jQuery.cssNumber</code></a> object</p>\n <pre><code>\n$.cssNumber.someCSSProp = true;\n </code></pre>\n <h4 id=\"animating\">Animating with cssHooks</h4>\n <p>A css hook can also hook into jQuery's animation mechanism by adding a property to the <code>jQuery.fx.step</code> object:</p>\n <pre><code>\n$.fx.step.someCSSProp = function( fx ) {\n $.cssHooks.someCSSProp.set( fx.elem, fx.now + fx.unit );\n};\n </code></pre>\n <p>Note that this works best for simple numeric-value animations. More custom code may be required depending on the CSS property, the type of value it returns, and the animation's complexity.</p>",
"examples": [],
"categories": [
"css",
"version/1.4.3"
]
},
{
"title": "jQuery.cssNumber",
"type": "property",
"name": "jQuery.cssNumber",
"return": "Object",
"signatures": [{
"arguments": [],
"added": "1.4.3"
}],
"desc": "An object containing all CSS properties that may be used without a unit. The <a href=\"/css/\"><code>.css()</code></a> method uses this object to see if it may append <code>px</code> to unitless values.",
"longdesc": "<p>You can think about <code>jQuery.cssNumber</code> as a list of all CSS properties you might use without a unit. It's used by <a href=\"/css/\"><code>.css()</code></a> to determine if it needs to add <code>px</code> to unitless values.</p>\n <p>The keys of the <code>jQuery.cssNumber</code> object are camel-cased and the values are all set to <code>true</code>. If you want to prevent the <a href=\"/css/\"><code>.css()</code></a> method from automatically adding the <code>px</code> unit for a specific CSS property, you can add an extra property to the <code>jQuery.cssNumber</code> object.</p>\n <pre><code>\njQuery.cssNumber.someCSSProp = true;\n </code></pre>\n <p>By default the object contains the following properties:</p>\n <ul>\n <li><code>zIndex</code></li>\n <li><code>fontWeight</code></li>\n <li><code>opacity</code></li>\n <li><code>zoom</code></li>\n <li><code>lineHeight</code></li>\n <li><code>widows</code> (added in jQuery 1.6)</li>\n <li><code>orphans</code> (added in jQuery 1.6)</li>\n <li><code>fillOpacity</code> (added in jQuery 1.6.2)</li>\n <li><code>columnCount</code> (added in jQuery 1.9)</li>\n <li><code>order</code> (added in jQuery 1.10.2)</li>\n <li><code>flexGrow</code> (added in jQuery 1.11.1)</li>\n <li><code>flexShrink</code> (added in jQuery 1.11.1)</li>\n </ul>",
"examples": [],
"categories": [
"css",
"manipulation/style-properties",
"version/1.4.3"
]
},
{
"entries": [{
"title": "jQuery.data()",
"type": "method",
"name": "jQuery.data",
"return": "Object",
"signatures": [{
"arguments": [{
"name": "element",
"type": "Element",
"desc": "The DOM element to associate with the data."
},
{
"name": "key",
"type": "String",
"desc": "A string naming the piece of data to set."
},
{
"name": "value",
"type": "Anything",
"desc": "The new data value; this can be any Javascript type except <code>undefined</code>."
}
],
"added": "1.2.3"
}],
"desc": "Store arbitrary data associated with the specified element. Returns the value that was set.",
"longdesc": "<p><strong>Note:</strong> This is a low-level method; a more convenient <code><a href=\"/data/\">.data()</a></code> is also available.</p>\n <p>The <code>jQuery.data()</code> method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore free from memory leaks. jQuery ensures that the data is removed when DOM elements are removed via jQuery methods, and when the user leaves the page. We can set several distinct values for a single element and retrieve them later:</p>\n <pre><code>\njQuery.data( document.body, \"foo\", 52 );\njQuery.data( document.body, \"bar\", \"test\" );\n </code></pre>",
"note": [{
"type": "additional",
"text": "Note that this method currently does not provide cross-platform support for setting data on XML documents, as Internet Explorer does not allow data to be attached via expando properties."
},
{
"type": "additional",
"text": "<code>undefined</code> is not recognized as a data value. Calls such as <code>jQuery.data( el, \"name\", undefined )</code> will return the corresponding data for \"name\", and is therefore the same as <code>jQuery.data( el, \"name\" )</code>."
}
],
"examples": [{
"desc": "Store then retrieve a value from the div element.",
"code": "var div = $( \"div\" )[ 0 ];\njQuery.data( div, \"test\", {\n first: 16,\n last: \"pizza!\"\n});\n$( \"span\" ).first().text( jQuery.data( div, \"test\" ).first );\n$( \"span\" ).last().text( jQuery.data( div, \"test\" ).last );",
"html": "<div>\n The values stored were\n <span></span>\n and\n <span></span>\n</div>",
"css": "div {\n color: blue;\n }\n span {\n color: red;\n }"
}],
"categories": [
"data",
"utilities",
"version/1.2.3",
"version/1.4",
"version/1.4.3"
]
},
{
"title": "",
"type": "method",
"name": "jQuery.data",
"return": "Object",
"signatures": [{
"arguments": [{
"name": "element",
"type": "Element",
"desc": "The DOM element to query for the data."
},
{
"name": "key",
"type": "String",
"desc": "Name of the data stored."
}
],
"added": "1.2.3"
},
{
"arguments": [{
"name": "element",
"type": "Element",
"desc": "The DOM element to query for the data."
}],
"added": "1.4"
}
],
"desc": "Returns value at named data store for the element, as set by <code>jQuery.data(element, name, value)</code>, or the full data store for the element.",
"longdesc": "<p><strong>Note:</strong> This is a low-level method; a more convenient <code><a href=\"/data/\">.data()</a></code> is also available.</p>\n <p><strong>Regarding HTML5 data-* attributes:</strong> This low-level method does NOT retrieve the <code>data-*</code> attributes unless the more convenient <code><a href=\"/data/\">.data()</a></code> method has already retrieved them.</p>\n <p>The <code>jQuery.data()</code> method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore from memory leaks. We can retrieve several distinct values for a single element one at a time, or as a set:</p>\n <pre><code>\nalert( jQuery.data( document.body, \"foo\" ) );\nalert( jQuery.data( document.body ) );\n </code></pre>\n <p>The above lines alert the data values that were set on the <code>body</code> element. If nothing was set on that element, an empty string is returned.</p>\n <p>Calling <code>jQuery.data( element )</code> retrieves all of the element's associated values as a JavaScript object. Note that jQuery itself uses this method to store data for internal use, such as event handlers, so do not assume that it contains only data that your own code has stored.</p>\n <p><em>Note:</em> this method currently does not provide cross-platform support for setting data on XML documents, as Internet Explorer does not allow data to be attached via expando properties.</p>",
"examples": [{
"desc": "Get the data named \"blah\" stored at for an element.",
"code": "$( \"button\" ).click( function() {\n var value,\n div = $( \"div\" )[ 0 ];\n switch ( $( \"button\" ).index( this ) ) {\n case 0 :\n value = jQuery.data( div, \"blah\" );\n break;\n case 1 :\n jQuery.data( div, \"blah\", \"hello\" );\n value = \"Stored!\";\n break;\n case 2 :\n jQuery.data( div, \"blah\", 86 );\n value = \"Stored!\";\n break;\n case 3 :\n jQuery.removeData( div, \"blah\" );\n value = \"Removed!\";\n break;\n }\n $( \"span\" ).text( \"\" + value );\n});",
"html": "<div>A div</div>\n<button>Get \"blah\" from the div</button>\n<button>Set \"blah\" to \"hello\"</button>\n<button>Set \"blah\" to 86</button>\n<button>Remove \"blah\" from the div</button>\n<p>The \"blah\" value of this div is <span>?</span></p>",
"css": "div {\n margin: 5px;\n background: yellow;\n }\n button {\n margin: 5px;\n font-size: 14px;\n }\n p {\n margin: 5px;\n color: blue;\n }\n span {\n color: red;\n }"
}],
"categories": [
"data",
"utilities",
"version/1.2.3",
"version/1.4",
"version/1.4.3"
]
}
]
},
{
"title": "jQuery.dequeue()",
"type": "method",
"name": "jQuery.dequeue",
"return": "undefined",
"signatures": [{
"arguments": [{
"name": "element",
"type": "Element",
"desc": "A DOM element from which to remove and execute a queued function."
},
{
"name": "queueName",
"optional": "true",
"type": "String",
"desc": "A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue."
}
],
"added": "1.3"
}],
"desc": "Execute the next function on the queue for the matched element.",
"longdesc": "<p><strong>Note:</strong> This is a low-level method, you should probably use <code><a href=\"/dequeue/\">.dequeue()</a></code> instead.</p>\n <p>When <code>jQuery.dequeue()</code> is called, the next function on the queue is removed from the queue, and then executed. This function should in turn (directly or indirectly) cause <code>jQuery.dequeue()</code> to be called, so that the sequence can continue.</p>",
"examples": [{
"desc": "Use jQuery.dequeue() to end a custom queue function which allows the queue to keep going.",
"code": "$( \"button\" ).click(function() {\n $( \"div\" )\n .animate({ left: '+=200px' }, 2000 )\n .animate({ top: '0px' }, 600 )\n .queue(function() {\n $( this ).toggleClass( \"red\" );\n $.dequeue( this );\n })\n .animate({ left:'10px', top:'30px' }, 700 );\n});",
"html": "<button>Start</button>\n<div></div>",
"css": "div {\n margin: 3px;\n width: 50px;\n position: absolute;\n height: 50px;\n left: 10px;\n top: 30px;\n background-color: yellow;\n }\n div.red {\n background-color: red;\n }"
}],
"categories": [
"data",
"utilities",
"version/1.3"
]
},
{
"title": "jQuery.each()",
"type": "method",
"name": "jQuery.each",
"return": "Object",
"signatures": [{
"arguments": [{
"name": "array",
"type": "ArrayLikeObject",
"desc": "The array or array-like object to iterate over."
},
{
"name": "callback",
"type": "Function",
"desc": "The function that will be executed on every value.",
"arguments": [{
"name": "indexInArray",
"type": "Integer"
},
{
"name": "value",
"type": "Object"
}
]
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "object",
"type": "Object",
"desc": "The object to iterate over."
},
{
"name": "callback",
"type": "Function",
"desc": "The function that will be executed on every value.",
"arguments": [{
"name": "propertyName",
"type": "String"
},
{
"name": "valueOfProperty",
"type": "Object"
}
]
}
],
"added": "1.0"
}
],
"desc": "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.",
"longdesc": "<p>The <code>$.each()</code> function is not the same as <a href=\"/each/\">$(selector).each()</a>, which is used to iterate, exclusively, over a jQuery object. The <code>$.each()</code> function can be used to iterate over any collection, whether it is an object or an array. In the case of an array, the callback is passed an array index and a corresponding array value each time. (The value can also be accessed through the <code>this</code> keyword, but Javascript will always wrap the <code>this</code> value as an <code>Object</code> even if it is a simple string or number value.) The method returns its first argument, the object that was iterated.</p>\n <pre><code>\n$.each([ 52, 97 ], function( index, value ) {\n alert( index + \": \" + value );\n});\n </code></pre>\n <p>This produces two messages:</p>\n <p>\n <samp>0: 52</samp>\n <br/>\n <samp>1: 97</samp>\n </p>\n <p>If an object is used as the collection, the callback is passed a key-value pair each time:</p>\n <pre><code>\nvar obj = {\n \"flammable\": \"inflammable\",\n \"duh\": \"no duh\"\n};\n$.each( obj, function( key, value ) {\n alert( key + \": \" + value );\n});\n </code></pre>\n <p>Once again, this produces two messages:</p>\n <p>\n <samp>flammable: inflammable</samp>\n <br/>\n <samp>duh: no duh</samp>\n </p>\n <p>We can break the <code>$.each()</code> loop at a particular iteration by making the callback function return <code>false</code>. Returning <em>non-false</em> is the same as a <code>continue</code> statement in a for loop; it will skip immediately to the next iteration.</p>",
"examples": [{
"desc": "Iterates through the array displaying each number as both a word and numeral",
"code": "var arr = [ \"one\", \"two\", \"three\", \"four\", \"five\" ];\nvar obj = { one: 1, two: 2, three: 3, four: 4, five: 5 };\n\njQuery.each( arr, function( i, val ) {\n $( \"#\" + val ).text( \"Mine is \" + val + \".\" );\n\n // Will stop running after \"three\"\n return ( val !== \"three\" );\n});\n\njQuery.each( obj, function( i, val ) {\n $( \"#\" + i ).append( document.createTextNode( \" - \" + val ) );\n});",
"html": "<div id=\"one\"></div>\n<div id=\"two\"></div>\n<div id=\"three\"></div>\n<div id=\"four\"></div>\n<div id=\"five\"></div>",
"css": "div {\n color: blue;\n }\n div#five {\n color: red;\n }"
},
{
"desc": "Iterates over items in an array, accessing both the current item and its index.",
"code": "$.each( [ \"a\", \"b\", \"c\" ], function( i, l ){\n alert( \"Index #\" + i + \": \" + l );\n});",
"html": "",
"css": ""
},
{
"desc": "Iterates over the properties in an object, accessing both the current item and its key.",
"code": "$.each({ name: \"John\", lang: \"JS\" }, function( k, v ) {\n alert( \"Key: \" + k + \", Value: \" + v );\n});",
"html": "",
"css": ""
}
],
"categories": [
"utilities",
"version/1.0"
]
},
{
"title": "jQuery.error()",
"type": "method",
"name": "jQuery.error",
"return": "",
"signatures": [{
"arguments": [{
"name": "message",
"type": "String",
"desc": "The message to send out."
}],
"added": "1.4.1"
}],
"desc": "Takes a string and throws an exception containing it.",
"longdesc": "<p>This method exists primarily for plugin developers who wish to override it and provide a better display (or more information) for the error messages.</p>",
"examples": [{
"desc": "Override jQuery.error for display in Firebug.",
"code": "jQuery.error = console.error;",
"html": "",
"css": ""
}],
"categories": [
"internals",
"version/1.4.1"
]
},
{
"title": "jQuery.escapeSelector()",
"type": "method",
"name": "jQuery.escapeSelector",
"return": "Selector",
"signatures": [{
"arguments": [{
"name": "selector",
"type": "Selector",
"desc": "A string containing a selector expression to escape."
}],
"added": "3.0"
}],
"desc": "Escapes any character that has a special meaning in a CSS selector.",
"longdesc": "<p>This method is useful for situations where a class name or an ID contains characters that have a special meaning in CSS, such as the dot or the semicolon.</p>\n <p>The method is essentially a shim for the <a href=\"https://drafts.csswg.org/cssom/#the-css.escape()-method\">CSS Working Group's CSS.escape() method</a>. The main difference is that <code>$.escapeSelector()</code> can be reliably used in all of jQuery's supported browsers.</p>",
"examples": [{
"desc": "Escape an ID containing a hash.",
"code": "$.escapeSelector( \"#target\" ); // \"\\#target\"",
"html": "",
"css": ""
},
{
"desc": "Select all the elements having a class name of <code>.box</code> inside a <code>div</code>.",
"code": "$( \"div\" ).find( \".\" + $.escapeSelector( \".box\" ) );",
"html": "",
"css": ""
}
],
"categories": [
"css",
"version/3.0"
]
},
{
"title": "jQuery.extend()",
"type": "method",
"name": "jQuery.extend",
"return": "Object",
"signatures": [{
"arguments": [{
"name": "target",
"type": "Object",
"desc": "An object that will receive the new properties if additional objects are passed in or that will extend the jQuery namespace if it is the sole argument."
},
{
"name": "object1",
"type": "Object",
"optional": "true",
"desc": "An object containing additional properties to merge in."
},
{
"name": "objectN",
"optional": "true",
"type": "Object",
"desc": "Additional objects containing properties to merge in."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "deep",
"optional": "true",
"type": "Boolean",
"desc": "If true, the merge becomes recursive (aka. deep copy). Passing <code>false</code> for this argument is not supported."
},
{
"name": "target",
"type": "Object",
"desc": "The object to extend. It will receive the new properties."
},
{
"name": "object1",
"type": "Object",
"desc": "An object containing additional properties to merge in."
},
{
"name": "objectN",
"optional": "true",
"type": "Object",
"desc": "Additional objects containing properties to merge in."
}
],
"added": "1.1.4"
}
],
"desc": "Merge the contents of two or more objects together into the first object.",
"longdesc": "<p>When two or more object arguments are supplied to <code>$.extend()</code>, properties from all of the objects are added to the target object. Arguments that are <code>null</code> or <code>undefined</code> are ignored.</p>\n <p>If only one argument is supplied to <code>$.extend()</code>, this means the target argument was omitted. In this case, the jQuery object itself is assumed to be the target. By doing this, you can add new functions to the jQuery namespace. This can be useful for plugin authors wishing to add new methods to JQuery.</p>\n <p>Keep in mind that the target object (first argument) will be modified, and will also be returned from <code>$.extend()</code>. If, however, you want to preserve both of the original objects, you can do so by passing an empty object as the target:</p>\n <pre><code>var object = $.extend({}, object1, object2);</code></pre>\n <p>The merge performed by <code>$.extend()</code> is not recursive by default; if a property of the first object is itself an object or array, it will be completely overwritten by a property with the same key in the second or subsequent object. The values are not merged. This can be seen in the example below by examining the value of banana. However, by passing <code>true</code> for the first function argument, objects will be recursively merged.</p>\n <p><strong>Warning</strong>: Passing <code>false</code> for the first argument is not supported.</p>\n <p>Undefined properties are not copied. However, properties inherited from the object's prototype <em>will</em> be copied over. Properties that are an object constructed via <code>new MyCustomObject(args)</code>, or built-in JavaScript types such as Date or RegExp, are not re-constructed and will appear as plain Objects in the resulting object or array.</p>\n <p>On a <code>deep</code> extend, Object and Array are extended, but object wrappers on primitive types such as String, Boolean, and Number are not. Deep-extending a cyclical data structure will result in an error.</p>\n <p>For needs that fall outside of this behavior, write a custom extend method instead, or use a library like <a href=\"https://lodash.com\">lodash</a>. </p>",
"examples": [{
"desc": "Merge two objects, modifying the first.",
"code": "var object1 = {\n apple: 0,\n banana: { weight: 52, price: 100 },\n cherry: 97\n};\nvar object2 = {\n banana: { price: 200 },\n durian: 100\n};\n\n// Merge object2 into object1\n$.extend( object1, object2 );\n\n// Assuming JSON.stringify - not available in IE<8\n$( \"#log\" ).append( JSON.stringify( object1 ) );",
"html": "<div id=\"log\"></div>",
"css": ""
},
{
"desc": "Merge two objects recursively, modifying the first.",
"code": "var object1 = {\n apple: 0,\n banana: { weight: 52, price: 100 },\n cherry: 97\n};\nvar object2 = {\n banana: { price: 200 },\n durian: 100\n};\n\n// Merge object2 into object1, recursively\n$.extend( true, object1, object2 );\n\n// Assuming JSON.stringify - not available in IE<8\n$( \"#log\" ).append( JSON.stringify( object1 ) );",
"html": "<div id=\"log\"></div>",
"css": ""
},
{
"desc": "Merge defaults and options, without modifying the defaults. This is a common plugin development pattern.",
"code": "var defaults = { validate: false, limit: 5, name: \"foo\" };\nvar options = { validate: true, name: \"bar\" };\n\n// Merge defaults and options, without modifying defaults\nvar settings = $.extend( {}, defaults, options );\n\n// Assuming JSON.stringify - not available in IE<8\n$( \"#log\" ).append( \"<div><b>defaults -- </b>\" + JSON.stringify( defaults ) + \"</div>\" );\n$( \"#log\" ).append( \"<div><b>options -- </b>\" + JSON.stringify( options ) + \"</div>\" );\n$( \"#log\" ).append( \"<div><b>settings -- </b>\" + JSON.stringify( settings ) + \"</div>\" );",
"html": "<div id=\"log\"></div>",
"css": ""
}
],
"categories": [
"utilities",
"version/1.0"
]
},
{
"title": "jQuery.fn.extend()",
"type": "method",
"name": "jQuery.fn.extend",
"return": "Object",
"signatures": [{
"arguments": [{
"name": "object",
"type": "Object",
"desc": "An object to merge onto the jQuery prototype."
}],
"added": "1.0"
}],
"desc": "Merge the contents of an object onto the jQuery prototype to provide new jQuery instance methods.",
"longdesc": "The <code>jQuery.fn.extend()</code> method extends the jQuery prototype (<code>$.fn</code>) object to provide new methods that can be chained to the <code>jQuery()</code> function.",
"examples": [{
"desc": "Add two methods to the jQuery prototype (<code>$.fn</code>) object and then use one of them.",
"code": "jQuery.fn.extend({\n check: function() {\n return this.each(function() {\n this.checked = true;\n });\n },\n uncheck: function() {\n return this.each(function() {\n this.checked = false;\n });\n }\n});\n\n// Use the newly created .check() method\n$( \"input[type='checkbox']\" ).check();",
"html": "<label><input type=\"checkbox\" name=\"foo\"> Foo</label>\n<label><input type=\"checkbox\" name=\"bar\"> Bar</label>",
"css": "label {\n display: block;\n margin: .5em;\n }"
}],
"categories": [
"utilities",
"version/1.0"
]
},
{
"title": "jQuery.fx.interval",
"type": "property",
"name": "jQuery.fx.interval",
"return": "Number",
"deprecated": "3.0",
"signatures": [{
"arguments": [],
"added": "1.4.3"
}],
"desc": "The rate (in milliseconds) at which animations fire.",
"longdesc": "<p>This property is deprecated as of version 3.0, and has no effect in browsers that support the <a href=\"https://caniuse.com/#feat=requestanimationframe\"><code>requestAnimationFrame</code></a> method.</p>\n <p>On browsers that do not support <code>requestAnimationFrame</code>, this property can be changed to adjust the interval at which animations will run. The default is 13 milliseconds.</p>\n <p>Since jQuery uses one global interval, no animation should be running or all animations should stop for the change of this property to take effect.</p>",
"examples": [{
"desc": "Cause all animations to run with less frames.",
"code": "jQuery.fx.interval = 100;\n$( \"input\" ).click(function() {\n $( \"div\" ).toggle( 3000 );\n});",
"html": "<p><input type=\"button\" value=\"Run\"></p>\n<div></div>",
"css": "div {\n width: 50px;\n height: 30px;\n margin: 5px;\n float: left;\n background: green;\n }"
}],
"categories": [
"effects/custom-effects",
"properties/global-jquery-object-properties",
"version/1.4.3",
"deprecated/deprecated-3.0"
]
},
{
"title": "jQuery.fx.off",
"type": "property",
"name": "jQuery.fx.off",
"return": "Boolean",
"signatures": [{
"arguments": [],
"added": "1.3"
}],
"desc": "Globally disable all animations.",
"longdesc": "<p>When this property is set to <code>true</code>, all animation methods will immediately set elements to their final state when called, rather than displaying an effect. This may be desirable for a couple reasons:</p>\n <ul>\n <li>jQuery is being used on a low-resource device.</li>\n <li>Users are encountering accessibility problems with the animations.</li>\n </ul>\n <p>Animations can be turned back on by setting the property to <code>false</code>.</p>",
"examples": [{
"desc": "Toggle animation on and off",
"code": "var toggleFx = function() {\n $.fx.off = !$.fx.off;\n};\ntoggleFx();\n$( \"button\" ).click( toggleFx );\n$( \"input\" ).click(function() {\n $( \"div\" ).toggle( \"slow\" );\n});",
"html": "<input type=\"button\" value=\"Run\">\n<button>Toggle fx</button>\n<div></div>",
"css": "div {\n width: 50px;\n height: 30px;\n margin: 5px;\n float: left;\n background: green;\n }"
}],
"categories": [
"effects/custom-effects",
"properties/global-jquery-object-properties",
"version/1.3"
]
},
{
"title": "jQuery.get()",
"type": "method",
"name": "jQuery.get",
"return": "jqXHR",
"signatures": [{
"arguments": [{
"name": "url",
"type": "String",
"desc": "A string containing the URL to which the request is sent."
},
{
"name": "data",
"optional": "true",
"type": [
"PlainObject",
"String"
],
"desc": "A plain object or string that is sent to the server with the request."
},
{
"name": "success",
"optional": "true",
"type": "Function",
"desc": "A callback function that is executed if the request succeeds. Required if <code>dataType</code> is provided, but you can use <code>null</code> or <a href=\"/jQuery.noop/\"><code>jQuery.noop</code></a> as a placeholder.",
"arguments": [{
"name": "data",
"type": "PlainObject"
},
{
"name": "textStatus",
"type": "String"
},
{
"name": "jqXHR",
"type": "jqXHR"
}
]
},
{
"name": "dataType",
"optional": "true",
"type": "String",
"desc": "The type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html)."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "settings",
"type": "PlainObject",
"optional": "false",
"desc": "A set of key/value pairs that configure the Ajax request. All properties except for <code>url</code> are optional. A default can be set for any option with <a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a>. See <a href=\"/jquery.ajax/#jQuery-ajax-settings\">jQuery.ajax( settings )</a> for a complete list of all settings. The type option will automatically be set to <code>GET</code>."
}],
"added": "1.12/2.2"
}
],
"desc": "Load data from the server using a HTTP GET request.",
"longdesc": "<p>This is a shorthand Ajax function, which is equivalent to:</p>\n <pre><code>\n$.ajax({\n url: url,\n data: data,\n success: success,\n dataType: dataType\n});\n </code></pre>\n <p>The <code>success</code> callback function is passed the returned data, which will be an XML root element, text string, JavaScript file, or JSON object, depending on the MIME type of the response. It is also passed the text status of the response. </p>\n <p><strong>As of jQuery 1.5</strong>, the <code>success</code> callback function is also passed a <a href=\"#jqxhr-object\">\"jqXHR\" object</a> (in <strong>jQuery 1.4</strong>, it was passed the <code>XMLHttpRequest</code> object). However, since JSONP and cross-domain GET requests do not use <abbr title=\"XMLHTTPRequest\">XHR</abbr>, in those cases the <code>jqXHR</code> and <code>textStatus</code> parameters passed to the success callback are undefined.</p>\n <p>Most implementations will specify a success handler:</p>\n <pre><code>\n$.get( \"ajax/test.html\", function( data ) {\n $( \".result\" ).html( data );\n alert( \"Load was performed.\" );\n});\n </code></pre>\n <p>This example fetches the requested HTML snippet and inserts it on the page.</p>\n <h4 id=\"jqxhr-object\">The jqXHR Object</h4>\n <p><strong>As of jQuery 1.5</strong>, all of jQuery's Ajax methods return a superset of the <code>XMLHTTPRequest</code> object. This jQuery XHR object, or \"jqXHR,\" returned by <code>$.get()</code> implements the Promise interface, giving it all the properties, methods, and behavior of a Promise (see <a href=\"/category/deferred-object/\">Deferred object</a> for more information). The <code>jqXHR.done()</code> (for success), <code>jqXHR.fail()</code> (for error), and <code>jqXHR.always()</code> (for completion, whether success or error; added in jQuery 1.6) methods take a function argument that is called when the request terminates. For information about the arguments this function receives, see the <a href=\"/jQuery.ajax/#jqXHR\">jqXHR Object</a> section of the <code>$.ajax()</code> documentation.</p>\n <p>The Promise interface also allows jQuery's Ajax methods, including <code>$.get()</code>, to chain multiple <code>.done()</code>, <code>.fail()</code>, and <code>.always()</code> callbacks on a single request, and even to assign these callbacks after the request may have completed. If the request is already complete, the callback is fired immediately.</p>\n <pre><code>\n// Assign handlers immediately after making the request,\n// and remember the jqxhr object for this request\nvar jqxhr = $.get( \"example.php\", function() {\n alert( \"success\" );\n})\n .done(function() {\n alert( \"second success\" );\n })\n .fail(function() {\n alert( \"error\" );\n })\n .always(function() {\n alert( \"finished\" );\n });\n\n// Perform other work here ...\n\n// Set another completion function for the request above\njqxhr.always(function() {\n alert( \"second finished\" );\n});\n </code></pre>\n <h4>Deprecation Notice</h4>\n <p>The <code>jqXHR.success()</code>, <code>jqXHR.error()</code>, and <code>jqXHR.complete()</code> callback methods are <strong>removed as of jQuery 3.0</strong>. You can use <code>jqXHR.done()</code>, <code>jqXHR.fail()</code>, and <code>jqXHR.always()</code> instead.</p>",
"note": [{
"type": "additional",
"text": "Script and JSONP requests are not subject to the same origin policy restrictions."
},
{
"type": "additional",
"text": "If a request with jQuery.get() returns an error code, it will fail silently unless the script has also called the global <a href=\"/ajaxError/\">.ajaxError() </a> method. Alternatively, as of jQuery 1.5, the <code>.error()</code> method of the <code>jqXHR</code> object returned by jQuery.get() is also available for error handling."
},
{
"type": "additional",
"text": "Script and JSONP requests are not subject to the same origin policy restrictions."
}
],
"examples": [{
"desc": "Request the test.php page, but ignore the return results.",
"code": "$.get( \"test.php\" );",
"html": "",
"css": ""
},
{
"desc": "Request the test.php page and send some additional data along (while still ignoring the return results).",
"code": "$.get( \"test.php\", { name: \"John\", time: \"2pm\" } );",
"html": "",
"css": ""
},
{
"desc": "Pass arrays of data to the server (while still ignoring the return results).",
"code": "$.get( \"test.php\", { \"choices[]\": [\"Jon\", \"Susan\"] } );",
"html": "",
"css": ""
},
{
"desc": "Alert the results from requesting test.php (HTML or XML, depending on what was returned).",
"code": "$.get( \"test.php\", function( data ) {\n alert( \"Data Loaded: \" + data );\n});",
"html": "",
"css": ""
},
{
"desc": "Alert the results from requesting test.cgi with an additional payload of data (HTML or XML, depending on what was returned).",
"code": "$.get( \"test.cgi\", { name: \"John\", time: \"2pm\" } )\n .done(function( data ) {\n alert( \"Data Loaded: \" + data );\n });",
"html": "",
"css": ""
},
{
"desc": "Get the test.php page contents, which has been returned in json format (&lt;?php echo json_encode( array( \"name\"=&gt;\"John\",\"time\"=&gt;\"2pm\" ) ); ?&gt;), and add it to the page.",
"code": "$.get( \"test.php\", function( data ) {\n $( \"body\" )\n .append( \"Name: \" + data.name ) // John\n .append( \"Time: \" + data.time ); // 2pm\n}, \"json\" );",
"html": "",
"css": ""
}
],
"categories": [
"ajax/shorthand-methods",
"version/1.0",
"version/1.5"
]
},
{
"title": "jQuery.getJSON()",
"type": "method",
"name": "jQuery.getJSON",
"return": "jqXHR",
"signatures": [{
"arguments": [{
"name": "url",
"type": "String",
"desc": "A string containing the URL to which the request is sent."
},
{
"name": "data",
"optional": "true",
"type": [
"PlainObject",
"String"
],
"desc": "A plain object or string that is sent to the server with the request."
},
{
"name": "success",
"optional": "true",
"type": "Function",
"desc": "A callback function that is executed if the request succeeds.",
"arguments": [{
"name": "data",
"type": "PlainObject"
},
{
"name": "textStatus",
"type": "String"
},
{
"name": "jqXHR",
"type": "jqXHR"
}
]
}
],
"added": "1.0"
}],
"desc": "Load JSON-encoded data from the server using a GET HTTP request.",
"longdesc": "<p>This is a shorthand Ajax function, which is equivalent to:</p>\n <pre><code>\n$.ajax({\n dataType: \"json\",\n url: url,\n data: data,\n success: success\n});\n </code></pre>\n <p>Data that is sent to the server is appended to the URL as a query string. If the value of the <code>data</code> parameter is a plain object, it is converted to a string and url-encoded before it is appended to the URL.</p>\n <p>Most implementations will specify a success handler:</p>\n <pre><code>\n$.getJSON( \"ajax/test.json\", function( data ) {\n var items = [];\n $.each( data, function( key, val ) {\n items.push( \"&lt;li id='\" + key + \"'&gt;\" + val + \"&lt;/li&gt;\" );\n });\n\n $( \"&lt;ul/&gt;\", {\n \"class\": \"my-new-list\",\n html: items.join( \"\" )\n }).appendTo( \"body\" );\n});\n</code></pre>\n <p>This example, of course, relies on the structure of the JSON file:</p>\n <pre><code>\n{\n \"one\": \"Singular sensation\",\n \"two\": \"Beady little eyes\",\n \"three\": \"Little birds pitch by my doorstep\"\n}\n </code></pre>\n <p>Using this structure, the example loops through the requested data, builds an unordered list, and appends it to the body.</p>\n <p>The <code>success</code> callback is passed the returned data, which is typically a JavaScript object or array as defined by the JSON structure and parsed using the <code><a href=\"/jQuery.parseJSON/\">$.parseJSON()</a></code> method. It is also passed the text status of the response.</p>\n <p><strong>As of jQuery 1.5</strong>, the <code>success</code> callback function receives a <a href=\"/jQuery.get/#jqxhr-object\">\"jqXHR\" object</a> (in <strong>jQuery 1.4</strong>, it received the <code>XMLHttpRequest</code> object). However, since JSONP and cross-domain GET requests do not use <abbr title=\"XMLHTTPRequest\">XHR</abbr>, in those cases the <code>jqXHR</code> and <code>textStatus</code> parameters passed to the success callback are undefined.</p>\n <div class=\"warning\">\n <p><strong>Important:</strong> As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually fail silently. Avoid frequent hand-editing of JSON data for this reason. JSON is a data-interchange format with syntax rules that are stricter than those of JavaScript's object literal notation. For example, all strings represented in JSON, whether they are properties or values, must be enclosed in double-quotes. For details on the JSON format, see <a href=\"https://json.org/\">https://json.org/</a>.</p>\n </div>\n <h4 id=\"jsonp\">JSONP</h4>\n <p>If the URL includes the string \"callback=?\" (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the <code>jsonp</code> data type in <code><a href=\"/jQuery.ajax/\">$.ajax()</a></code> for more details.</p>\n <h4 id=\"jqxhr-object\">The jqXHR Object</h4>\n <p><strong>As of jQuery 1.5</strong>, all of jQuery's Ajax methods return a superset of the <code>XMLHTTPRequest</code> object. This jQuery XHR object, or \"jqXHR,\" returned by <code>$.getJSON()</code> implements the Promise interface, giving it all the properties, methods, and behavior of a Promise (see <a href=\"/category/deferred-object/\">Deferred object</a> for more information). The <code>jqXHR.done()</code> (for success), <code>jqXHR.fail()</code> (for error), and <code>jqXHR.always()</code> (for completion, whether success or error; added in jQuery 1.6) methods take a function argument that is called when the request terminates. For information about the arguments this function receives, see the <a href=\"/jQuery.ajax/#jqXHR\">jqXHR Object</a> section of the <code>$.ajax()</code> documentation.</p>\n <p>The Promise interface in jQuery 1.5 also allows jQuery's Ajax methods, including <code>$.getJSON()</code>, to chain multiple <code>.done()</code>, <code>.always()</code>, and <code>.fail()</code> callbacks on a single request, and even to assign these callbacks after the request may have completed. If the request is already complete, the callback is fired immediately.</p>\n <pre><code>\n// Assign handlers immediately after making the request,\n// and remember the jqxhr object for this request\nvar jqxhr = $.getJSON( \"example.json\", function() {\n console.log( \"success\" );\n})\n .done(function() {\n console.log( \"second success\" );\n })\n .fail(function() {\n console.log( \"error\" );\n })\n .always(function() {\n console.log( \"complete\" );\n });\n\n// Perform other work here ...\n\n// Set another completion function for the request above\njqxhr.always(function() {\n console.log( \"second complete\" );\n});\n </code></pre>\n <h4>Deprecation Notice</h4>\n <p>The <code>jqXHR.success()</code>, <code>jqXHR.error()</code>, and <code>jqXHR.complete()</code> callback methods are <strong>removed as of jQuery 3.0</strong>. You can use <code>jqXHR.done()</code>, <code>jqXHR.fail()</code>, and <code>jqXHR.always()</code> instead.</p>",
"note": [{
"type": "additional",
"text": "Script and JSONP requests are not subject to the same origin policy restrictions."
},
{
"type": "additional",
"text": "Script and JSONP requests are not subject to the same origin policy restrictions."
}
],
"examples": [{
"desc": "Loads the four most recent pictures of Mount Rainier from the Flickr JSONP API.",
"code": "(function() {\n var flickerAPI = \"https://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?\";\n $.getJSON( flickerAPI, {\n tags: \"mount rainier\",\n tagmode: \"any\",\n format: \"json\"\n })\n .done(function( data ) {\n $.each( data.items, function( i, item ) {\n $( \"<img>\" ).attr( \"src\", item.media.m ).appendTo( \"#images\" );\n if ( i === 3 ) {\n return false;\n }\n });\n });\n})();",
"html": "<div id=\"images\"></div>",
"css": "img {\n height: 100px;\n float: left;\n }"
},
{
"desc": "Load the JSON data from test.js and access a name from the returned JSON data.",
"code": "$.getJSON( \"test.js\", function( json ) {\n console.log( \"JSON Data: \" + json.users[ 3 ].name );\n });",
"html": "",
"css": ""
},
{
"desc": "Load the JSON data from test.js, passing along additional data, and access a name from the returned JSON data.\n If an error occurs, log an error message instead.",
"code": "$.getJSON( \"test.js\", { name: \"John\", time: \"2pm\" } )\n .done(function( json ) {\n console.log( \"JSON Data: \" + json.users[ 3 ].name );\n })\n .fail(function( jqxhr, textStatus, error ) {\n var err = textStatus + \", \" + error;\n console.log( \"Request Failed: \" + err );\n});",
"html": "",
"css": ""
}
],
"categories": [
"ajax/shorthand-methods",
"version/1.0",
"version/1.5"
]
},
{
"title": "jQuery.getScript()",
"type": "method",
"name": "jQuery.getScript",
"return": "jqXHR",
"signatures": [{
"arguments": [{
"name": "url",
"type": "String",
"desc": "A string containing the URL to which the request is sent."
},
{
"name": "success",
"optional": "true",
"type": "Function",
"desc": "A callback function that is executed if the request succeeds.",
"arguments": [{
"name": "script",
"type": "String"
},
{
"name": "textStatus",
"type": "String"
},
{
"name": "jqXHR",
"type": "jqXHR"
}
]
}
],
"added": "1.0"
}],
"desc": "Load a JavaScript file from the server using a GET HTTP request, then execute it.",
"longdesc": "<p>This is a shorthand Ajax function, which is equivalent to:</p>\n <pre><code>\n$.ajax({\n url: url,\n dataType: \"script\",\n success: success\n});\n </code></pre>\n <p>The script is executed in the global context, so it can refer to other variables and use jQuery functions. Included scripts can have some impact on the current page.</p>\n <h4 id=\"success-callback\">\n Success Callback\n </h4>\n <p>The callback is fired once the script has been loaded but not necessarily executed.</p>\n <p>Scripts are included and run by referencing the file name:</p>\n <pre><code>\n$.getScript( \"ajax/test.js\", function( data, textStatus, jqxhr ) {\n console.log( data ); // Data returned\n console.log( textStatus ); // Success\n console.log( jqxhr.status ); // 200\n console.log( \"Load was performed.\" );\n});\n </code></pre>\n <h4 id=\"handling-errors\">Handling Errors</h4>\n <p>As of jQuery 1.5, you may use <a href=\"/deferred.fail/\"><code>.fail()</code></a> to account for errors:</p>\n <pre><code>\n$.getScript( \"ajax/test.js\" )\n .done(function( script, textStatus ) {\n console.log( textStatus );\n })\n .fail(function( jqxhr, settings, exception ) {\n $( \"div.log\" ).text( \"Triggered ajaxError handler.\" );\n});\n </code></pre>\n <p>Prior to jQuery 1.5, the global <code>.ajaxError()</code> callback event had to be used in order to handle <code>$.getScript()</code> errors:</p>\n <pre><code>\n$( \"div.log\" ).ajaxError(function( e, jqxhr, settings, exception ) {\n if ( settings.dataType == \"script\" ) {\n $( this ).text( \"Triggered ajaxError handler.\" );\n }\n});\n </code></pre>\n <h4 id=\"caching-requests\">Caching Responses</h4>\n <p>By default, <code>$.getScript()</code> sets the cache setting to <code>false</code>. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. You can override this feature by setting the cache property globally using <a href=\"/jquery.ajaxsetup/\"><code>$.ajaxSetup()</code></a>: </p>\n <pre><code>\n$.ajaxSetup({\n cache: true\n});\n </code></pre>\n <p>Alternatively, you could define a new method that uses the more flexible <code>$.ajax()</code> method.</p>",
"examples": [{
"desc": "Define a $.cachedScript() method that allows fetching a cached script:",
"code": "jQuery.cachedScript = function( url, options ) {\n\n // Allow user to set any option except for dataType, cache, and url\n options = $.extend( options || {}, {\n dataType: \"script\",\n cache: true,\n url: url\n });\n\n // Use $.ajax() since it is more flexible than $.getScript\n // Return the jqXHR object so we can chain callbacks\n return jQuery.ajax( options );\n};\n\n// Usage\n$.cachedScript( \"ajax/test.js\" ).done(function( script, textStatus ) {\n console.log( textStatus );\n});",
"html": "",
"css": ""
},
{
"desc": "Load the <a href=\"https://github.com/jquery/jquery-color\">official jQuery Color Animation plugin</a> dynamically and bind some color animations to occur once the new functionality is loaded.",
"code": "var url = \"https://code.jquery.com/color/jquery.color.js\";\n$.getScript( url, function() {\n $( \"#go\" ).click(function() {\n $( \".block\" )\n .animate({\n backgroundColor: \"rgb(255, 180, 180)\"\n }, 1000 )\n .delay( 500 )\n .animate({\n backgroundColor: \"olive\"\n }, 1000 )\n .delay( 500 )\n .animate({\n backgroundColor: \"#00f\"\n }, 1000 );\n });\n});",
"html": "<button id=\"go\">&raquo; Run</button>\n<div class=\"block\"></div>",
"css": ".block {\n background-color: blue;\n width: 150px;\n height: 70px;\n margin: 10px;\n }"
}
],
"categories": [
"ajax/shorthand-methods",
"version/1.0",
"version/1.5"
]
},
{
"title": "jQuery.globalEval()",
"type": "method",
"name": "jQuery.globalEval",
"return": "Anything",
"signatures": [{
"arguments": [{
"name": "code",
"type": "String",
"desc": "The JavaScript code to execute."
}],
"added": "1.0.4"
},
{
"arguments": [{
"name": "code",
"type": "String",
"desc": "The JavaScript code to execute."
},
{
"name": "options",
"type": "PlainObject",
"optional": "true",
"properties": [{
"name": "nonce",
"type": "string",
"desc": "The nonce attribute passed to the executed script.",
"arguments": []
}]
}
],
"added": "3.4.0"
}
],
"desc": "Execute some JavaScript code globally.",
"longdesc": "<p>This method behaves differently from using a normal JavaScript <code>eval()</code> in that it's executed within the global context (which is important for loading external scripts dynamically).</p>",
"examples": [{
"desc": "Execute a script in the global context.",
"code": "function test() {\n jQuery.globalEval( \"var newVar = true;\" );\n}\ntest();\n// newVar === true",
"html": "",
"css": ""
},
{
"desc": "Execute a script with a nonce value on a site with Content Security Policy enabled.",
"code": "function test() {\n jQuery.globalEval( \"var newVar = true;\", {\n nonce: \"nonce-2726c7f26c\"\n } );\n}\ntest();\n// newVar === true",
"html": "",
"css": ""
}
],
"categories": [
"utilities",
"version/1.0.4"
]
},
{
"title": "jQuery.grep()",
"type": "method",
"name": "jQuery.grep",
"return": "Array",
"signatures": [{
"arguments": [{
"name": "array",
"type": "ArrayLikeObject",
"desc": "The array-like object to search through."
},
{
"name": "function",
"type": "Function",
"desc": "The function to process each item against. The first argument to the function is the item, and the second argument is the index. The function should return a Boolean value. <code>this</code> will be the global window object.",
"arguments": [{
"name": "elementOfArray",
"type": "Object"
},
{
"name": "indexInArray",
"type": "Integer"
}
]
},
{
"name": "invert",
"optional": "true",
"type": "Boolean",
"desc": "If \"invert\" is false, or not provided, then the function returns an array consisting of all elements for which \"callback\" returns true. If \"invert\" is true, then the function returns an array consisting of all elements for which \"callback\" returns false."
}
],
"added": "1.0"
}],
"desc": "Finds the elements of an array which satisfy a filter function. The original array is not affected.",
"longdesc": "<p>The <code>$.grep()</code> method removes items from an array as necessary so that all remaining items pass a provided test. The test is a function that is passed an array item and the index of the item within the array. Only if the test returns true will the item be in the result array.</p>\n <p> The filter function will be passed two arguments: the current array item and its index. The filter function must return 'true' to include the item in the result array.</p>",
"examples": [{
"desc": "Filters the original array of numbers leaving that are not 5 and have an index greater than 4. Then it removes all 9s.",
"code": "var arr = [ 1, 9, 3, 8, 6, 1, 5, 9, 4, 7, 3, 8, 6, 9, 1 ];\n$( \"div\" ).text( arr.join( \", \" ) );\n\narr = jQuery.grep(arr, function( n, i ) {\n return ( n !== 5 && i > 4 );\n});\n$( \"p\" ).text( arr.join( \", \" ) );\n\narr = jQuery.grep(arr, function( a ) {\n return a !== 9;\n});\n\n$( \"span\" ).text( arr.join( \", \" ) );",
"html": "<div></div>\n<p></p>\n<span></span>",
"css": "div {\n color: blue;\n }\n p {\n color: green;\n margin: 0;\n }\n span {\n color: red;\n }"
},
{
"desc": "Filter an array of numbers to include only numbers bigger then zero.",
"code": "$.grep( [ 0, 1, 2 ], function( n, i ) {\n return n > 0;\n});",
"html": "",
"css": ""
},
{
"desc": "Filter an array of numbers to include numbers that are not bigger than zero.",
"code": "$.grep( [ 0, 1, 2 ], function( n, i ) {\n return n > 0;\n}, true );",
"html": "",
"css": ""
}
],
"categories": [
"utilities",
"version/1.0"
]
},
{
"title": "jQuery.hasData()",
"type": "method",
"name": "jQuery.hasData",
"return": "Boolean",
"signatures": [{
"arguments": [{
"name": "element",
"type": "Element",
"desc": "A DOM element to be checked for data."
}],
"added": "1.5"
}],
"desc": "Determine whether an element has any jQuery data associated with it.",
"longdesc": "<p>The <code>jQuery.hasData()</code> method provides a way to determine if an element currently has any values that were set using <code><a href=\"/jQuery.data/\">jQuery.data()</a></code>. If there is no data object associated with an element, the method returns <code>false</code>; otherwise it returns <code>true</code>.</p>\n <p>The primary advantage of <code>jQuery.hasData(element)</code> is that it does not create and associate a data object with the element if none currently exists. In contrast, <code>jQuery.data(element)</code> always returns a data object to the caller, creating one if no data object previously existed.\n</p>\n <p>Note that jQuery's event system uses the jQuery data API to store event handlers. Therefore, binding an event to an element using <code>.on()</code>, <code>.bind()</code>, <code>.live()</code>, <code>.delegate()</code>, or one of the shorthand event methods also associates a data object with that element.\n</p>",
"examples": [{
"desc": "Set data on an element and see the results of hasData.",
"code": "var $p = jQuery( \"p\" ), p = $p[ 0 ];\n$p.append( jQuery.hasData( p ) + \" \" ); // false\n\n$.data( p, \"testing\", 123 );\n$p.append( jQuery.hasData( p ) + \" \" ); // true\n\n$.removeData( p, \"testing\" );\n$p.append( jQuery.hasData( p ) + \" \" ); // false\n\n$p.on( \"click\", function() {} );\n$p.append( jQuery.hasData( p ) + \" \" ); // true\n\n$p.off( \"click\" );\n$p.append( jQuery.hasData( p ) + \" \" ); // false",
"html": "<p>Results: </p>",
"css": ""
}],
"categories": [
"data",
"version/1.5"
]
},
{
"title": "jQuery.holdReady()",
"type": "method",
"name": "jQuery.holdReady",
"return": "undefined",
"signatures": [{
"arguments": [{
"name": "hold",
"type": "Boolean",
"desc": "Indicates whether the ready hold is being requested or released"
}],
"added": "1.6"
}],
"desc": "Holds or releases the execution of jQuery's ready event.",
"longdesc": "<p>The <code>$.holdReady()</code> method allows the caller to delay jQuery's ready event. This <em>advanced feature</em> would typically be used by dynamic script loaders that want to load additional JavaScript such as jQuery plugins before allowing the ready event to occur, even though the DOM may be ready. This method must be called early in the document, such as in the <code>&lt;head&gt;</code> immediately after the jQuery script tag. Calling this method after the ready event has already fired will have no effect. </p>\n <p>To delay the ready event, first call <code>$.holdReady( true )</code>. When the ready event should be released to execute, call <code>$.holdReady( false )</code>. Note that multiple holds can be put on the ready event, one for each <code>$.holdReady( true )</code> call. The ready event will not actually fire until all holds have been released with a corresponding number of <code>$.holdReady( false )</code> calls <em>and</em> the normal document ready conditions are met. (See <a href=\"/ready/\"><code>ready</code></a> for more information.)</p>",
"examples": [{
"desc": "Delay the ready event until a custom plugin has loaded.",
"code": "$.holdReady( true );\n$.getScript( \"myplugin.js\", function() {\n $.holdReady( false );\n});",
"html": "",
"css": ""
}],
"categories": [
"core",
"properties/global-jquery-object-properties",
"events/document-loading",
"version/1.6"
]
},
{
"title": "jQuery.htmlPrefilter()",
"type": "method",
"name": "jQuery.htmlPrefilter",
"return": "String",
"signatures": [{
"arguments": [{
"name": "html",
"type": "String",
"desc": "The HTML string on which to operate."
}],
"added": "1.12/2.2"
}],
"desc": "Modify and filter HTML strings passed through <a href=\"/category/manipulation/\">jQuery manipulation methods</a>.",
"longdesc": "<p>This method rarely needs to be called directly. Instead, use it as an entry point to modify existing <a href=\"/category/manipulation/\">jQuery manipulation methods</a>. For instance, to remove all <code>&lt;del&gt;</code> tags from incoming HTML strings, do this:</p>\n <pre><code>\nvar htmlPrefilter = $.htmlPrefilter,\n rdel = /&lt;(del)(?=[\\s&gt;])[\\w\\W]*?&lt;\\/\\1\\s*&gt;/gi;\n\n$.htmlPrefilter = function( html ) {\n return htmlPrefilter.call( this, html ).replace( rdel, \"\" );\n};\n </code></pre>\n <p>This function can also be overwritten in order to bypass certain edge case issues. The default <code>htmlPrefilter</code> function in jQuery will greedily ensure that all tags are XHTML-compliant. This includes anything that looks like an HTML tag, but is actually within a string (e.g. <pre>&lt;a title=\"&lt;div /&gt;\"&gt;&lt;&gt;</pre>). The <code>jQuery.htmlPrefilter()</code> function can be used to bypass this:</p>\n <pre><code>\n$.htmlPrefilter = function( html ) {\n // Return HTML strings unchanged\n return html;\n};\n </code></pre>\n <p>However, while the above fix is short and simple, it puts the burden on you to ensure XHTML-compliant tags in any HTML strings. A more thorough fix for this issue would be this:</p>\n <pre><code>\nvar panything = \"[\\\\w\\\\W]*?\",\n\n // Whitespace\n // https://html.spec.whatwg.org/multipage/infrastructure.html#space-character\n pspace = \"[\\\\x20\\\\t\\\\r\\\\n\\\\f]\",\n\n // End of tag name (whitespace or greater-than)\n pnameEnd = pspace.replace( \"]\", \"&gt;]\" ),\n\n // Tag name (a leading letter, then almost anything)\n // https://html.spec.whatwg.org/multipage/syntax.html#tag-open-state\n // https://html.spec.whatwg.org/multipage/syntax.html#tag-name-state\n pname = \"[a-z]\" + pnameEnd.replace( \"[\", \"[^/\\\\0\" ) + \"*\",\n\n // Void element (end tag prohibited)\n // https://html.spec.whatwg.org/multipage/syntax.html#void-elements\n pvoidName = \"(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|\" +\n \"source|track|wbr)(?=\" + pnameEnd + \")\",\n\n // Attributes (double-quoted value, single-quoted value, unquoted value, or no value)\n // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2\n pattrs = \"(?:\" + pspace + \"+[^\\\\0-\\\\x20\\\\x7f-\\\\x9f=\\\"'/&gt;]+(?:\" + pspace + \"*=\" + pspace +\n \"*(?:\\\"\" + panything + \"\\\"|'\" + panything + \"'|\" +\n pnameEnd.replace( \"[\", \"[^\" ) + \"*(?!/)\" +\n \")|))*\" + pspace + \"*\",\n\n // Trailing content of a close tag\n pcloseTail = \"(?:\" + pspace + panything + \"|)\",\n\n rspecialHtml = new RegExp(\n // Non-void element that self-closes: $1–$5\n \"(&lt;)(?!\" + pvoidName + \")(\" + pname + \")(\" + pattrs + \")(\\\\/)(&gt;)|\" +\n // No-innerHTML container (element, comment, or CDATA): $6\n \"(&lt;(script|style|textarea)\" + pattrs + \"&gt;\" + panything + \"&lt;\\\\/\\\\7\" + pcloseTail + \"&gt;|\" +\n \"&lt;!--\" + panything + \"--)\",\n \"gi\"\n ),\n\n // \"&lt;\"; element name; attributes; \"&gt;\"; \"&lt;\"; \"/\"; element name; \"&gt;\"; no-innerHTML container\n pspecialReplacement = \"$1$2$3$5$1$4$2$5$6\";\n\n$.htmlPrefilter = function( html ) {\n return ( html + \"\" ).replace( rspecialHtml, pspecialReplacement );\n};\n </code></pre>",
"examples": [],
"categories": [
"manipulation"
]
},
{
"title": "jQuery.inArray()",
"type": "method",
"name": "jQuery.inArray",
"return": "Number",
"signatures": [{
"arguments": [{
"name": "value",
"type": "Anything",
"desc": "The value to search for."
},
{
"name": "array",
"type": "Array",
"desc": "An array through which to search."
},
{
"name": "fromIndex",
"type": "Number",
"optional": "true",
"desc": "The index of the array at which to begin the search. The default is 0, which will search the whole array."
}
],
"added": "1.2"
}],
"desc": "Search for a specified value within an array and return its index (or -1 if not found).",
"longdesc": "<p>The <code>$.inArray()</code> method is similar to JavaScript's native <code>.indexOf()</code> method in that it returns -1 when it doesn't find a match. If the first element within the array matches <code>value</code>, <code>$.inArray()</code> returns 0.</p>\n <p>Because JavaScript treats 0 as loosely equal to false (i.e. 0 == false, but 0 !== false), to check for the presence of <code>value</code> within <code>array</code>, you need to check if it's not equal to (or greater than) -1.</p>\n <p>The comparison between values is strict. The following will return <code>-1</code> (not found) because a number is being searched in an array of strings:</p>\n <pre><code>$.inArray( 5 + 5, [ \"8\", \"9\", \"10\", 10 + \"\" ] );</code></pre>",
"examples": [{
"desc": "Report the index of some elements in the array.",
"code": "var arr = [ 4, \"Pete\", 8, \"John\" ];\nvar $spans = $( \"span\" );\n$spans.eq( 0 ).text( jQuery.inArray( \"John\", arr ) );\n$spans.eq( 1 ).text( jQuery.inArray( 4, arr ) );\n$spans.eq( 2 ).text( jQuery.inArray( \"Karl\", arr ) );\n$spans.eq( 3 ).text( jQuery.inArray( \"Pete\", arr, 2 ) );",
"html": "<div>\"John\" found at <span></span></div>\n<div>4 found at <span></span></div>\n<div>\"Karl\" not found, so <span></span></div>\n<div>\"Pete\" is in the array, but not at or after index 2, so <span></span></div>",
"css": "div {\n color: blue;\n }\n span {\n color: red;\n }"
}],
"categories": [
"utilities",
"version/1.2"
]
},
{
"title": "jQuery.isArray()",
"type": "method",
"name": "jQuery.isArray",
"return": "boolean",
"signatures": [{
"arguments": [{
"name": "obj",
"type": "Object",
"desc": "Object to test whether or not it is an array."
}],
"added": "1.3"
}],
"desc": "Determine whether the argument is an array.",
"longdesc": "<p><code>$.isArray()</code> returns a Boolean indicating whether the object is a JavaScript array (not an array-like object, such as a jQuery object).</p>",
"examples": [{
"desc": "Finds out if the parameter is an array.",
"code": "$( \"b\" ).append( \"\" + $.isArray([]) );",
"html": "Is [] an Array? <b></b>",
"css": ""
}],
"categories": [
"utilities",
"version/1.3"
]
},
{
"title": "jQuery.isEmptyObject()",
"type": "method",
"name": "jQuery.isEmptyObject",
"return": "Boolean",
"signatures": [{
"arguments": [{
"name": "object",
"type": "Object",
"desc": "The object that will be checked to see if it's empty."
}],
"added": "1.4"
}],
"desc": "Check to see if an object is empty (contains no enumerable properties).",
"longdesc": "<p>As of jQuery 1.4 this method checks both properties on the object itself and properties inherited from prototypes (in that it doesn't use hasOwnProperty). The argument should always be a plain JavaScript <code>Object</code> as other types of object (DOM elements, primitive strings/numbers, host objects) may not give consistent results across browsers. To determine if an object is a plain JavaScript object, use <a href=\"/jQuery.isPlainObject/\"><code>$.isPlainObject()</code></a></p>",
"examples": [{
"desc": "Check an object to see if it's empty.",
"code": "jQuery.isEmptyObject({}); // true\njQuery.isEmptyObject({ foo: \"bar\" }); // false",
"html": "",
"css": ""
}],
"categories": [
"utilities",
"version/1.4"
]
},
{
"title": "jQuery.isFunction()",
"type": "method",
"name": "jQuery.isFunction",
"return": "boolean",
"deprecated": "3.3",
"signatures": [{
"arguments": [{
"name": "value",
"type": "Anything",
"desc": "The value to be tested."
}],
"added": "1.2"
}],
"desc": "Determines if its argument is callable as a function.",
"longdesc": "<p>As of jQuery 3.3, <code>jQuery.isFunction()</code> has been deprecated. In most cases, its use can be replaced by <code>typeof x === \"function\"</code>.</p>\n <p><strong>Note:</strong> As of jQuery 1.3, functions provided by the browser like <code>alert()</code> and DOM element methods like <code>getAttribute()</code> are not guaranteed to be detected as functions in browsers such as Internet Explorer.</p>",
"examples": [{
"desc": "Test a few parameter examples.",
"code": "function stub() {}\nvar objs = [\n function() {},\n { x:15, y:20 },\n null,\n stub,\n \"function\"\n];\n\njQuery.each( objs, function( i ) {\n var isFunc = jQuery.isFunction( objs[ i ]);\n $( \"span\" ).eq( i ).text( isFunc );\n});",
"html": "<div>jQuery.isFunction( objs[ 0 ] ) = <span></span></div>\n<div>jQuery.isFunction( objs[ 1 ] ) = <span></span></div>\n<div>jQuery.isFunction( objs[ 2 ] ) = <span></span></div>\n<div>jQuery.isFunction( objs[ 3 ] ) = <span></span></div>\n<div>jQuery.isFunction( objs[ 4 ] ) = <span></span></div>",
"css": "div {\n color: blue;\n margin: 2px;\n font-size: 14px;\n }\n span {\n color: red;\n }"
},
{
"desc": "Finds out if the parameter is a function.",
"code": "$.isFunction(function() {});",
"html": "",
"css": ""
}
],
"categories": [
"utilities",
"version/1.2",
"deprecated/deprecated-3.3"
]
},
{
"title": "jQuery.isNumeric()",
"type": "method",
"name": "jQuery.isNumeric",
"return": "Boolean",
"signatures": [{
"arguments": [{
"name": "value",
"type": "Anything",
"desc": "The value to be tested."
}],
"added": "1.7"
}],
"desc": "Determines whether its argument represents a JavaScript number.",
"longdesc": "<p>The <code>$.isNumeric()</code> method checks whether its argument represents a numeric value. If so, it returns <code>true</code>. Otherwise it returns <code>false</code>. The argument can be of any type.</p>\n <p>As of jQuery 3.0 <code>$.isNumeric()</code> returns <code>true</code> only if the argument is of type <a href=\"/Types/#Number\"><code>number</code></a>, or if it's of type <code>string</code> and it can be coerced into finite numbers. In all other cases, it returns <code>false</code>.</p>",
"examples": [{
"desc": "Sample return values of $.isNumeric with various inputs.",
"code": "// true (numeric)\n$.isNumeric( \"-10\" )\n$.isNumeric( \"0\" )\n$.isNumeric( 0xFF )\n$.isNumeric( \"0xFF\" )\n$.isNumeric( \"8e5\" )\n$.isNumeric( \"3.1415\" )\n$.isNumeric( +10 )\n$.isNumeric( 0144 )\n\n// false (non-numeric)\n$.isNumeric( \"-0x42\" )\n$.isNumeric( \"7.2acdgs\" )\n$.isNumeric( \"\" )\n$.isNumeric( {} )\n$.isNumeric( NaN )\n$.isNumeric( null )\n$.isNumeric( true )\n$.isNumeric( Infinity )\n$.isNumeric( undefined )",
"html": "",
"css": ""
}],
"categories": [
"utilities",
"version/1.7"
]
},
{
"title": "jQuery.isPlainObject()",
"type": "method",
"name": "jQuery.isPlainObject",
"return": "Boolean",
"signatures": [{
"arguments": [{
"name": "object",
"type": "PlainObject",
"desc": "The object that will be checked to see if it's a plain object."
}],
"added": "1.4"
}],
"desc": "Check to see if an object is a plain object (created using \"{}\" or \"new Object\").",
"longdesc": "<p><strong>Note:</strong> Host objects (or objects used by browser host environments to complete the execution environment of ECMAScript) have a number of inconsistencies which are difficult to robustly feature detect cross-platform. As a result of this, <code>$.isPlainObject()</code> may evaluate inconsistently across browsers in certain instances.</p>\n <p>An example of this is a test against <code>document.location</code> using <code>$.isPlainObject()</code> as follows:</p>\n <pre><code>\nconsole.log( $.isPlainObject( document.location ) );\n </code></pre>\n <p>which throws an invalid pointer exception in IE8. With this in mind, it's important to be aware of any of the gotchas involved in using <code>$.isPlainObject()</code> against older browsers. A couple basic examples that do function correctly cross-browser can be found below.</p>",
"examples": [{
"desc": "Check an object to see if it's a plain object.",
"code": "jQuery.isPlainObject({}) // true\njQuery.isPlainObject( \"test\" ) // false",
"html": "",
"css": ""
}],
"categories": [
"utilities",
"version/1.4"
]
},
{
"title": "jQuery.isWindow()",
"type": "method",
"name": "jQuery.isWindow",
"return": "boolean",
"deprecated": "3.3",
"signatures": [{
"arguments": [{
"name": "obj",
"type": "PlainObject",
"desc": "Object to test whether or not it is a window."
}],
"added": "1.4.3"
}],
"desc": "Determine whether the argument is a window.",
"longdesc": "<p>This is used in a number of places in jQuery to determine if we're operating against a browser window (such as the current window or an iframe).</p>",
"examples": [{
"desc": "Finds out if the parameter is a window.",
"code": "$( \"b\" ).append( \"\" + $.isWindow( window ) );",
"html": "Is 'window' a window? <b></b>",
"css": ""
}],
"categories": [
"utilities",
"version/1.4.3",
"deprecated/deprecated-3.3"
]
},
{
"title": "jQuery.isXMLDoc()",
"type": "method",
"name": "jQuery.isXMLDoc",
"return": "Boolean",
"signatures": [{
"arguments": [{
"name": "node",
"type": "Element",
"desc": "The DOM node that will be checked to see if it's in an XML document."
}],
"added": "1.1.4"
}],
"desc": "Check to see if a DOM node is within an XML document (or is an XML document).",
"longdesc": "",
"examples": [{
"desc": "Check an object to see if it's in an XML document.",
"code": "jQuery.isXMLDoc( document ) // false\njQuery.isXMLDoc( document.body ) // false",
"html": "",
"css": ""
}],
"categories": [
"utilities",
"version/1.1.4"
]
},
{
"title": "jQuery.makeArray()",
"type": "method",
"name": "jQuery.makeArray",
"return": "Array",
"signatures": [{
"arguments": [{
"name": "obj",
"type": "PlainObject",
"desc": "Any object to turn into a native Array."
}],
"added": "1.2"
}],
"desc": "Convert an array-like object into a true JavaScript array.",
"longdesc": "<p>Many methods, both in jQuery and in JavaScript in general, return objects that are array-like. For example, the jQuery factory function <code>$()</code> returns a jQuery object that has many of the properties of an array (a length, the <code>[]</code> array access operator, etc.), but is not exactly the same as an array and lacks some of an array's built-in methods (such as <code>.pop()</code> and <code>.reverse()</code>).</p>\n <p>Note that after the conversion, any special features the object had (such as the jQuery methods in our example) will no longer be present. The object is now a plain array.</p>",
"examples": [{
"desc": "Turn a collection of HTMLElements into an Array of them.",
"code": "// Returns a NodeList\nvar elems = document.getElementsByTagName( \"div\" );\n// Convert the NodeList to an Array\nvar arr = jQuery.makeArray( elems );\n// Use an Array method on list of dom elements\narr.reverse();\n$( arr ).appendTo( document.body );",
"html": "<div>First</div>\n<div>Second</div>\n<div>Third</div>\n<div>Fourth</div>",
"css": "div {\n color: red;\n }"
},
{
"desc": "Turn a jQuery object into an array",
"code": "var obj = $( \"li\" );\nvar arr = $.makeArray( obj );",
"html": "",
"css": ""
}
],
"categories": [
"utilities",
"version/1.2"
]
},
{
"title": "jQuery.map()",
"type": "method",
"name": "jQuery.map",
"return": "Array",
"signatures": [{
"arguments": [{
"name": "array",
"type": "Array",
"desc": "The Array to translate."
},
{
"name": "callback",
"type": "Function",
"desc": "The function to process each item against. The first argument to the function is the array item, the second argument is the index in array The function can return any value. A returned array will be flattened into the resulting array. Within the function, <code>this</code> refers to the global (window) object.",
"arguments": [{
"name": "elementOfArray",
"type": "Object"
},
{
"name": "indexInArray",
"type": "Integer"
}
]
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "object",
"type": "Object",
"desc": "The Object to translate."
},
{
"name": "callback",
"type": "Function",
"desc": "The function to process each item against. The first argument to the function is the value; the second argument is the key of the object property. The function can return any value to add to the array. A returned array will be flattened into the resulting array. Within the function, <code>this</code> refers to the global (window) object.",
"arguments": [{
"name": "propertyOfObject",
"type": "Object"
},
{
"name": "key",
"type": "String"
}
]
}
],
"added": "1.6"
}
],
"desc": "Translate all items in an array or object to new array of items.",
"longdesc": "<p>If you wish to process a jQuery object — for example, <code>$('div').map( callback );</code> — use <a href=\"/map/\">.map()</a> instead. </p>\n <p>The <code>$.map()</code> method applies a function to each item in an array or object and maps the results into a new array. <strong>Prior to jQuery 1.6</strong>, <code>$.map()</code> supports traversing <em>arrays only</em>. <strong>As of jQuery 1.6</strong> it also traverses objects.</p>\n <p>Array-like objects — those with a <code>.length</code> property <em>and</em> a value on the <code>.length - 1</code> index — must be converted to actual arrays before being passed to <code>$.map()</code>. The jQuery library provides <a href=\"/jQuery.makeArray/\">$.makeArray()</a> for such conversions.</p>\n <pre><code>\n// The following object masquerades as an array.\nvar fakeArray = { \"length\": 2, 0: \"Addy\", 1: \"Subtracty\" };\n\n// Therefore, convert it to a real array\nvar realArray = $.makeArray( fakeArray )\n\n// Now it can be used reliably with $.map()\n$.map( realArray, function( val, i ) {\n // Do something\n});\n </code></pre>\n <p>The translation function that is provided to this method is called for each top-level element in the array or object and is passed two arguments: The element's value and its index or key within the array or object.</p>\n <p>The function can return:</p>\n <ul>\n <li>the translated value, which will be mapped to the resulting array</li>\n <li><code>null</code> or <code>undefined</code>, to remove the item</li>\n <li>an array of values, which will be flattened into the full array</li>\n </ul>",
"examples": [{
"desc": "Use $.map() to change the values of an array.",
"code": "var arr = [ \"a\", \"b\", \"c\", \"d\", \"e\" ];\n$( \"div\" ).text( arr.join( \", \" ) );\n\narr = jQuery.map( arr, function( n, i ) {\n return ( n.toUpperCase() + i );\n});\n$( \"p\" ).text( arr.join( \", \" ) );\n\narr = jQuery.map( arr, function( a ) {\n return a + a;\n});\n$( \"span\" ).text( arr.join( \", \" ) );",
"html": "<div></div>\n<p></p>\n<span></span>",
"css": "div {\n color: blue;\n }\n p {\n color: green;\n margin: 0;\n }\n span {\n color: red;\n }"
},
{
"desc": "Map the original array to a new one and add 4 to each value.",
"code": "$.map( [ 0, 1, 2 ], function( n ) {\n return n + 4;\n});",
"html": "",
"css": ""
},
{
"desc": "Map the original array to a new one, adding 1 to each value if it is bigger then zero and removing it if not.",
"code": "$.map( [ 0, 1, 2 ], function( n ) {\n return n > 0 ? n + 1 : null;\n});",
"html": "",
"css": ""
},
{
"desc": "Map the original array to a new one; each element is added with its original value and the value plus one.",
"code": "$.map( [ 0, 1, 2 ], function( n ) {\n return [ n, n + 1 ];\n});",
"html": "",
"css": ""
},
{
"desc": "Map the original object to a new array and double each value.",
"code": "var dimensions = { width: 10, height: 15, length: 20 };\ndimensions = $.map( dimensions, function( value, index ) {\n return value * 2;\n});",
"html": "",
"css": ""
},
{
"desc": "Map an object's keys to an array.",
"code": "var dimensions = { width: 10, height: 15, length: 20 };\nvar keys = $.map( dimensions, function( value, key ) {\n return key;\n});",
"html": "",
"css": ""
},
{
"desc": "Map the original array to a new one; each element is squared.",
"code": "$.map( [ 0, 1, 2, 3 ], function( a ) {\n return a * a;\n});",
"html": "",
"css": ""
},
{
"desc": "Map the original array to a new one, removing numbers less than 50 by returning <code>null</code> and subtracting 45 from the rest.",
"code": "$.map( [ 0, 1, 52, 97 ], function( a ) {\n return (a > 50 ? a - 45 : null);\n});",
"html": "",
"css": ""
},
{
"desc": "Augment the resulting array by returning an array inside the function.",
"code": "var array = [ 0, 1, 52, 97 ];\narray = $.map( array, function( a, index ) {\n return [ a - 45, index ];\n});",
"html": "",
"css": ""
}
],
"categories": [
"utilities",
"version/1.0",
"version/1.6"
]
},
{
"title": "jQuery.merge()",
"type": "method",
"name": "jQuery.merge",
"return": "Array",
"signatures": [{
"arguments": [{
"name": "first",
"type": "ArrayLikeObject",
"desc": "The first array-like object to merge, the elements of second added."
},
{
"name": "second",
"type": "ArrayLikeObject",
"desc": "The second array-like object to merge into the first, unaltered."
}
],
"added": "1.0"
}],
"desc": "Merge the contents of two arrays together into the first array.",
"longdesc": "<p>The <code>$.merge()</code> operation forms an array that contains all elements from the two arrays. The orders of items in the arrays are preserved, with items from the second array appended. The <code>$.merge()</code> function is destructive. It alters the <code>length</code> and numeric index properties of the first object to include items from the second.</p>\n <p>If you need the original first array, make a copy of it before calling <code>$.merge()</code>. Fortunately, <code>$.merge()</code> itself can be used for this duplication:</p>\n <pre><code>\nvar newArray = $.merge([], oldArray);\n </code></pre>\n <p>This shortcut creates a new, empty array and merges the contents of oldArray into it, effectively cloning the array.</p>\n <p>Prior to jQuery 1.4, the arguments should be true Javascript Array objects; use <code>$.makeArray</code> if they are not.</p>",
"examples": [{
"desc": "Merges two arrays, altering the first argument.",
"code": "$.merge( [ 0, 1, 2 ], [ 2, 3, 4 ] )",
"html": "",
"css": ""
},
{
"desc": "Merges two arrays, altering the first argument.",
"code": "$.merge( [ 3, 2, 1 ], [ 4, 3, 2 ] )",
"html": "",
"css": ""
},
{
"desc": "Merges two arrays, but uses a copy, so the original isn't altered.",
"code": "var first = [ \"a\", \"b\", \"c\" ];\nvar second = [ \"d\", \"e\", \"f\" ];\n$.merge( $.merge( [], first ), second );",
"html": "",
"css": ""
}
],
"categories": [
"utilities",
"version/1.0"
]
},
{
"title": "jQuery.noConflict()",
"type": "method",
"name": "jQuery.noConflict",
"return": "Object",
"signatures": [{
"arguments": [{
"name": "removeAll",
"type": "Boolean",
"optional": "true",
"desc": "A Boolean indicating whether to remove all jQuery variables from the global scope (including jQuery itself)."
}],
"added": "1.0"
}],
"desc": "Relinquish jQuery's control of the <code>$</code> variable.",
"longdesc": "<p>Many JavaScript libraries use <code>$</code> as a function or variable name, just as jQuery does. In jQuery's case, <code>$</code> is just an alias for <code>jQuery</code>, so all functionality is available without using <code>$</code>. If you need to use another JavaScript library alongside jQuery, return control of <code>$</code> back to the other library with a call to <code>$.noConflict()</code>. Old references of <code>$</code> are saved during jQuery initialization; <code>noConflict()</code> simply restores them.</p>\n <p>If for some reason two versions of jQuery are loaded (which is not recommended), calling <code>$.noConflict( true )</code> from the second version will return the globally scoped jQuery variables to those of the first version.</p>\n <pre><code>\n&lt;script src=\"other_lib.js\"&gt;&lt;/script&gt;\n&lt;script src=\"jquery.js\"&gt;&lt;/script&gt;\n&lt;script&gt;\n$.noConflict();\n// Code that uses other library's $ can follow here.\n&lt;/script&gt;\n </code></pre>\n <p>This technique is especially effective in conjunction with the <code>.ready()</code> method's ability to alias the jQuery object, as within callback passed to <code>.ready()</code> you can use <code>$</code> if you wish without fear of conflicts later:</p>\n <pre><code>\n&lt;script src=\"other_lib.js\"&gt;&lt;/script&gt;\n&lt;script src=\"jquery.js\"&gt;&lt;/script&gt;\n&lt;script&gt;\n$.noConflict();\njQuery( document ).ready(function( $ ) {\n // Code that uses jQuery's $ can follow here.\n});\n// Code that uses other library's $ can follow here.\n&lt;/script&gt;\n </code></pre>\n <p>If necessary, you can free up the <code>jQuery</code> name as well by passing <code>true</code> as an argument to the method. This is rarely necessary, and if you must do this (for example, if you need to use multiple versions of the jQuery library on the same page), you need to consider that most plug-ins rely on the presence of the <code>jQuery</code> variable and may not operate correctly in this situation.</p>",
"examples": [{
"desc": "Map the original object that was referenced by $ back to $.",
"code": "jQuery.noConflict();\n// Do something with jQuery\njQuery( \"div p\" ).hide();\n// Do something with another library's $()\n$( \"content\" ).style.display = \"none\";",
"html": "",
"css": ""
},
{
"desc": "Revert the $ alias and then create and execute a function to provide the $ as a jQuery alias inside the function's scope. Inside the function the original $ object is not available. This works well for most plugins that don't rely on any other library.",
"code": "jQuery.noConflict();\n(function( $ ) {\n $(function() {\n // More code using $ as alias to jQuery\n });\n})(jQuery);\n\n// Other code using $ as an alias to the other library",
"html": "",
"css": ""
},
{
"desc": "Create a different alias instead of jQuery to use in the rest of the script.",
"code": "var j = jQuery.noConflict();\n\n// Do something with jQuery\nj( \"div p\" ).hide();\n\n// Do something with another library's $()\n$( \"content\" ).style.display = \"none\";",
"html": "",
"css": ""
},
{
"desc": "Completely move jQuery to a new namespace in another object.",
"code": "var dom = {};\ndom.query = jQuery.noConflict( true );",
"html": "",
"css": ""
},
{
"desc": "Load two versions of jQuery (not recommended). Then, restore jQuery's globally scoped variables to the first loaded jQuery.",
"code": "var $log = $( \"#log\" );\n\n$log.append( \"2nd loaded jQuery version ($): \" + $.fn.jquery + \"<br>\" );\n\n// Restore globally scoped jQuery variables to the first version loaded\n// (the newer version)\n\njq162 = jQuery.noConflict( true );\n\n$log.append( \"<h3>After $.noConflict(true)</h3>\" );\n$log.append( \"1st loaded jQuery version ($): \" + $.fn.jquery + \"<br>\" );\n$log.append( \"2nd loaded jQuery version (jq162): \" + jq162.fn.jquery + \"<br>\" );",
"html": "<div id=\"log\">\n <h3>Before $.noConflict(true)</h3>\n</div>\n<script src=\"https://code.jquery.com/jquery-1.6.2.js\"></script>",
"css": ""
}
],
"categories": [
"core",
"miscellaneous/setup-methods",
"version/1.0"
]
},
{
"title": "jQuery.noop()",
"type": "method",
"name": "jQuery.noop",
"return": "undefined",
"signatures": [{
"arguments": [],
"added": "1.4"
}],
"desc": "An empty function.",
"longdesc": "<p>You can use this empty function when you wish to pass around a function that will do nothing.</p>\n <p>This is useful for plugin authors who offer optional callbacks; in the case that no callback is given, something like <code>jQuery.noop</code> could execute.</p>",
"examples": [],
"categories": [
"utilities",
"version/1.4"
]
},
{
"title": "jQuery.now()",
"type": "method",
"name": "jQuery.now",
"return": "Number",
"signatures": [{
"arguments": [],
"added": "1.4.3"
}],
"desc": "Return a number representing the current time.",
"longdesc": "<p>The <code>$.now()</code> method is a shorthand for the number returned by the expression <code>(new Date).getTime()</code>.</p>",
"examples": [],
"categories": [
"utilities",
"version/1.4.3"
]
},
{
"title": "jQuery.param()",
"type": "method",
"name": "jQuery.param",
"return": "String",
"signatures": [{
"arguments": [{
"name": "obj",
"type": [
"Array",
"PlainObject",
"jQuery"
],
"desc": "An array, a plain object, or a jQuery object to serialize."
}],
"added": "1.2"
},
{
"arguments": [{
"name": "obj",
"type": [
"Array",
"PlainObject",
"jQuery"
],
"desc": "An array, a plain object, or a jQuery object to serialize."
},
{
"name": "traditional",
"type": "Boolean",
"desc": "A Boolean indicating whether to perform a traditional \"shallow\" serialization."
}
],
"added": "1.4"
}
],
"desc": "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.",
"longdesc": "<p>This function is used internally to convert form element values into a serialized string representation (See <a href=\"/serialize/\">.serialize()</a> for more information).</p>\n <p>As of jQuery 1.3, the return value of a function is used instead of the function as a String.</p>\n <p>As of jQuery 1.4, the <code>$.param()</code> method serializes deep objects recursively to accommodate modern scripting languages and frameworks such as PHP and Ruby on Rails. You can disable this functionality globally by setting <code>jQuery.ajaxSettings.traditional = true;</code>.</p>\n <p>As of jQuery 3.0, the <code>$.param()</code> method no longer uses <code>jQuery.ajaxSettings.traditional</code> as its default setting and will default to <code>false</code>. For best compatibility across versions, call <code>$.param()</code> with an explicit value for the second argument and do not use defaults.</p>\n <p>If the object passed is in an Array, it must be an array of objects in the format returned by <a href=\"/serializeArray/\">.serializeArray()</a></p>\n <pre><code>\n[\n { name: \"first\", value: \"Rick\" },\n { name: \"last\", value: \"Astley\" },\n { name: \"job\", value: \"Rock Star\" }\n]\n </code></pre>\n <div class=\"warning\">\n <p><strong>Note:</strong> Because some frameworks have limited ability to parse serialized arrays, developers should exercise caution when passing an <code>obj</code> argument that contains objects or arrays nested within another array.</p>\n </div>\n <div class=\"warning\">\n <p><strong>Note:</strong> Because there is no universally agreed-upon specification for param strings, it is not possible to encode complex data structures using this method in a manner that works ideally across all languages supporting such input. Use JSON format as an alternative for encoding complex data instead.</p>\n </div>\n <p>In jQuery 1.4, HTML5 input elements are also serialized.</p>\n <p>We can display a query string representation of an object and a URI-decoded version of the same as follows:</p>\n <pre><code>\nvar myObject = {\n a: {\n one: 1,\n two: 2,\n three: 3\n },\n b: [ 1, 2, 3 ]\n};\nvar recursiveEncoded = $.param( myObject );\nvar recursiveDecoded = decodeURIComponent( $.param( myObject ) );\n\nalert( recursiveEncoded );\nalert( recursiveDecoded );\n </code></pre>\n <p>The values of <code>recursiveEncoded</code> and <code>recursiveDecoded</code> are alerted as follows:</p>\n <p>\n <samp>a%5Bone%5D=1&amp;a%5Btwo%5D=2&amp;a%5Bthree%5D=3&amp;b%5B%5D=1&amp;b%5B%5D=2&amp;b%5B%5D=3</samp>\n <br/>\n <samp>a[one]=1&amp;a[two]=2&amp;a[three]=3&amp;b[]=1&amp;b[]=2&amp;b[]=3</samp>\n </p>\n <p>To emulate the behavior of <code>$.param()</code> prior to jQuery 1.4, we can set the <code>traditional</code> argument to <code>true</code>:</p>\n <pre><code>\nvar myObject = {\n a: {\n one: 1,\n two: 2,\n three: 3\n },\n b: [ 1, 2, 3 ]\n};\nvar shallowEncoded = $.param( myObject, true );\nvar shallowDecoded = decodeURIComponent( shallowEncoded );\n\nalert( shallowEncoded );\nalert( shallowDecoded );\n</code></pre>\n <p>The values of <code>shallowEncoded</code> and <code>shallowDecoded</code> are alerted as follows:</p>\n <p>\n <samp>a=%5Bobject+Object%5D&amp;b=1&amp;b=2&amp;b=3</samp>\n <br/>\n <samp>a=[object+Object]&amp;b=1&amp;b=2&amp;b=3</samp>\n </p>",
"examples": [{
"desc": "Serialize a key/value object.",
"code": "var params = { width:1680, height:1050 };\nvar str = jQuery.param( params );\n$( \"#results\" ).text( str );",
"html": "<div id=\"results\"></div>",
"css": "div {\n color: red;\n }"
},
{
"desc": "Serialize a few complex objects",
"code": "// <=1.3.2:\n$.param({ a: [ 2, 3, 4 ] }); // \"a=2&a=3&a=4\"\n// >=1.4:\n$.param({ a: [ 2, 3, 4 ] }); // \"a[]=2&a[]=3&a[]=4\"\n\n// <=1.3.2:\n$.param({ a: { b: 1, c: 2 }, d: [ 3, 4, { e: 5 } ] });\n// \"a=[object+Object]&d=3&d=4&d=[object+Object]\"\n\n// >=1.4:\n$.param({ a: { b: 1, c: 2 }, d: [ 3, 4, { e: 5 } ] });\n// \"a[b]=1&a[c]=2&d[]=3&d[]=4&d[2][e]=5\"",
"html": "",
"css": "div {\n color: red;\n }"
}
],
"categories": [
"miscellaneous/collection-manipulation",
"forms",
"ajax/helper-functions",
"version/1.2",
"version/1.4"
]
},
{
"title": "jQuery.parseHTML()",
"type": "method",
"name": "jQuery.parseHTML",
"return": "Array",
"signatures": [{
"arguments": [{
"name": "data",
"type": "String",
"desc": "HTML string to be parsed"
},
{
"name": "context",
"type": "Element",
"optional": "true",
"default": "document",
"desc": "Document element to serve as the context in which the HTML fragment will be created"
},
{
"name": "keepScripts",
"type": "Boolean",
"optional": "true",
"default": "false",
"desc": "A Boolean indicating whether to include scripts passed in the HTML string"
}
],
"added": "1.8"
}],
"desc": "Parses a string into an array of DOM nodes.",
"longdesc": "<p><code>jQuery.parseHTML</code> uses native methods to convert the string to a set of DOM nodes, which can then be inserted into the document. These methods do render all trailing or leading text (even if that's just whitespace). To prevent trailing/leading whitespace from being converted to text nodes you can pass the HTML string through <a href=\"/jQuery.trim/\"><code>jQuery.trim</code></a>.</p>\n <p>By default, the <code>context</code> is the current <code>document</code> if not specified or given as <code>null</code> or <code>undefined</code>. If the HTML was to be used in another document such as an iframe, that frame's document could be used.</p>\n <p>As of 3.0 the default behavior is changed. If the <code>context</code> is not specified or given as <code>null</code> or <code>undefined</code>, a new <code>document</code> is used. This can potentially improve security because inline events will not execute when the HTML is parsed. Once the parsed HTML is injected into a document it does execute, but this gives tools a chance to traverse the created DOM and remove anything deemed unsafe. This improvement does not apply to internal uses of <code>jQuery.parseHTML</code> as they usually pass in the current <code>document</code>. Therefore, a statement like <code>$( \"#log\" ).append( $( htmlString ) )</code> is still subject to the injection of malicious code.</p>\n\t<h2>Security Considerations</h2>\n\t<p>Most jQuery APIs that accept HTML strings will run scripts that are included in the HTML. <code>jQuery.parseHTML</code> does not run scripts in the parsed HTML unless <code>keepScripts</code> is explicitly <code>true</code>. However, it is still possible in most environments to execute scripts indirectly, for example via the <code>&lt;img onerror&gt;</code> attribute. The caller should be aware of this and guard against it by cleaning or escaping any untrusted inputs from sources such as the URL or cookies. For future compatibility, callers should not depend on the ability to run <em>any</em> script content when <code>keepScripts</code> is unspecified or <code>false</code>.</p>",
"examples": [{
"desc": "Create an array of DOM nodes using an HTML string and insert it into a div.",
"code": "var $log = $( \"#log\" ),\n str = \"hello, <b>my name is</b> jQuery.\",\n html = $.parseHTML( str ),\n nodeNames = [];\n\n// Append the parsed HTML\n$log.append( html );\n\n// Gather the parsed HTML's node names\n$.each( html, function( i, el ) {\n nodeNames[ i ] = \"<li>\" + el.nodeName + \"</li>\";\n});\n\n// Insert the node names\n$log.append( \"<h3>Node Names:</h3>\" );\n$( \"<ol></ol>\" )\n .append( nodeNames.join( \"\" ) )\n .appendTo( $log );",
"html": "<div id=\"log\">\n <h3>Content:</h3>\n</div>",
"css": ""
}],
"categories": [
"utilities",
"version/1.8"
]
},
{
"title": "jQuery.parseJSON()",
"type": "method",
"name": "jQuery.parseJSON",
"deprecated": "3.0",
"signatures": [{
"arguments": [{
"name": "json",
"type": "String",
"desc": "The JSON string to parse."
}],
"added": "1.4.1"
}],
"desc": "Takes a well-formed JSON string and returns the resulting JavaScript value.",
"longdesc": "<p>As of jQuery 3.0, <code>$.parseJSON</code> is deprecated. To parse JSON strings use the native <code>JSON.parse</code> method instead.</p>\n <p>Passing in a malformed JSON string results in a JavaScript exception being thrown. For example, the following are all invalid JSON strings:</p>\n <ul>\n <li><code>\"{test: 1}\"</code> (test does not have double quotes around it).</li>\n <li><code>\"{'test': 1}\"</code> ('test' is using single quotes instead of double quotes).</li>\n <li><code>\"'test'\"</code> ('test' is using single quotes instead of double quotes).</li>\n <li><code>\".1\"</code> (a number must start with a digit; <code>\"0.1\"</code> would be valid).</li>\n <li><code>\"undefined\"</code> (<code>undefined</code> cannot be represented in a JSON string; <code>null</code>, however, can be).</li>\n <li><code>\"NaN\"</code> (<code>NaN</code> cannot be represented in a JSON string; direct representation of <code>Infinity</code> is also not permitted).</li>\n </ul>\n <p>The JSON standard does not permit \"control characters\" such as a tab or newline. An example like <code>$.parseJSON( '{ \"testing\":\"1\\t2\\n3\" }' )</code> will throw an error in most implementations because the JavaScript parser converts the string's tab and newline escapes into literal tab and newline; doubling the backslashes like <code>\"1\\\\t2\\\\n3\"</code> yields expected results. This problem is often seen when injecting JSON into a JavaScript file from a server-side language such as PHP.</p>\n <p>Where the browser provides a native implementation of <code>JSON.parse</code>, jQuery uses it to parse the string. For details on the JSON format, see <a href=\"https://json.org/\">https://json.org/</a>.</p>\n <p>Prior to jQuery 1.9, <code>$.parseJSON</code> returned <code>null</code> instead of throwing an error if it was passed an empty string, <code>null</code>, or <code>undefined</code>, even though those are not valid JSON.</p>",
"examples": [{
"desc": "Parse a JSON string.",
"code": "var obj = jQuery.parseJSON( '{ \"name\": \"John\" }' );\nalert( obj.name === \"John\" );",
"html": "",
"css": ""
}],
"categories": [
"utilities",
"version/1.4.1",
"deprecated/deprecated-3.0"
]
},
{
"title": "jQuery.parseXML()",
"type": "method",
"name": "jQuery.parseXML",
"return": "XMLDocument",
"signatures": [{
"arguments": [{
"name": "data",
"type": "String",
"desc": "a well-formed XML string to be parsed"
}],
"added": "1.5"
}],
"desc": "Parses a string into an XML document.",
"longdesc": "<p><code>jQuery.parseXML</code> uses the native parsing function of the browser to create a valid XML Document. This document can then be passed to <code>jQuery</code> to create a typical jQuery object that can be traversed and manipulated.</p>",
"examples": [{
"desc": "Create a jQuery object using an XML string and obtain the value of the title node.",
"code": "var xml = \"<rss version='2.0'><channel><title>RSS Title</title></channel></rss>\",\n xmlDoc = $.parseXML( xml ),\n $xml = $( xmlDoc ),\n $title = $xml.find( \"title\" );\n\n// Append \"RSS Title\" to #someElement\n$( \"#someElement\" ).append( $title.text() );\n\n// Change the title to \"XML Title\"\n$title.text( \"XML Title\" );\n\n// Append \"XML Title\" to #anotherElement\n$( \"#anotherElement\" ).append( $title.text() );",
"html": "<p id=\"someElement\"></p>\n<p id=\"anotherElement\"></p>",
"css": ""
}],
"categories": [
"utilities",
"version/1.5"
]
},
{
"title": "jQuery.post()",
"type": "method",
"name": "jQuery.post",
"return": "jqXHR",
"signatures": [{
"arguments": [{
"name": "url",
"type": "String",
"desc": "A string containing the URL to which the request is sent."
},
{
"name": "data",
"optional": "true",
"type": [
"PlainObject",
"String"
],
"desc": "A plain object or string that is sent to the server with the request."
},
{
"name": "success",
"optional": "true",
"type": "Function",
"desc": "A callback function that is executed if the request succeeds. Required if <code>dataType</code> is provided, but can be <code>null</code> in that case.",
"arguments": [{
"name": "data",
"type": "PlainObject"
},
{
"name": "textStatus",
"type": "String"
},
{
"name": "jqXHR",
"type": "jqXHR"
}
]
},
{
"name": "dataType",
"optional": "true",
"type": "String",
"desc": "The type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html)."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "settings",
"type": "PlainObject",
"optional": "false",
"desc": "A set of key/value pairs that configure the Ajax request. All properties except for <code>url</code> are optional. A default can be set for any option with <a href=\"/jQuery.ajaxSetup/\">$.ajaxSetup()</a>. See <a href=\"/jquery.ajax/#jQuery-ajax-settings\">jQuery.ajax( settings )</a> for a complete list of all settings. Type will automatically be set to <code>POST</code>."
}],
"added": "1.12/2.2"
}
],
"desc": "Load data from the server using a HTTP POST request.",
"longdesc": "<p>This is a shorthand Ajax function, which is equivalent to:</p>\n <pre><code>\n$.ajax({\n type: \"POST\",\n url: url,\n data: data,\n success: success,\n dataType: dataType\n});\n </code></pre>\n <p>The <code>success</code> callback function is passed the returned data, which will be an XML root element or a text string depending on the MIME type of the response. It is also passed the text status of the response.</p>\n <p><strong>As of jQuery 1.5</strong>, the <code>success</code> callback function is also passed a <a href=\"#jqxhr-object\">\"jqXHR\" object</a> (in <strong>jQuery 1.4</strong>, it was passed the <code>XMLHttpRequest</code> object).</p>\n <p>Most implementations will specify a success handler:</p>\n <pre><code>\n$.post( \"ajax/test.html\", function( data ) {\n $( \".result\" ).html( data );\n});\n </code></pre>\n <p>This example fetches the requested HTML snippet and inserts it on the page.</p>\n <p>Pages fetched with <code>POST</code> are never cached, so the <code>cache</code> and <code>ifModified</code> options in <code><a href=\"/jQuery.ajaxSetup/\">jQuery.ajaxSetup()</a></code> have no effect on these requests.</p>\n <h4 id=\"jqxhr-object\">The jqXHR Object</h4>\n <p><strong>As of jQuery 1.5</strong>, all of jQuery's Ajax methods return a superset of the <code>XMLHTTPRequest</code> object. This jQuery XHR object, or \"jqXHR,\" returned by <code>$.post()</code> implements the Promise interface, giving it all the properties, methods, and behavior of a Promise (see <a href=\"/category/deferred-object/\">Deferred object</a> for more information). The <code>jqXHR.done()</code> (for success), <code>jqXHR.fail()</code> (for error), and <code>jqXHR.always()</code> (for completion, whether success or error; added in jQuery 1.6) methods take a function argument that is called when the request terminates. For information about the arguments this function receives, see the <a href=\"/jQuery.ajax/#jqXHR\">jqXHR Object</a> section of the <code>$.ajax()</code> documentation.</p>\n <p>The Promise interface also allows jQuery's Ajax methods, including <code>$.get()</code>, to chain multiple <code>.done()</code>, <code>.fail()</code>, and <code>.always()</code> callbacks on a single request, and even to assign these callbacks after the request may have completed. If the request is already complete, the callback is fired immediately.</p>\n <pre><code>\n// Assign handlers immediately after making the request,\n// and remember the jqxhr object for this request\nvar jqxhr = $.post( \"example.php\", function() {\n alert( \"success\" );\n})\n .done(function() {\n alert( \"second success\" );\n })\n .fail(function() {\n alert( \"error\" );\n })\n .always(function() {\n alert( \"finished\" );\n });\n\n// Perform other work here ...\n\n// Set another completion function for the request above\njqxhr.always(function() {\n alert( \"second finished\" );\n});\n </code></pre>\n\n <h4>Deprecation Notice</h4>\n <p>The <code>jqXHR.success()</code>, <code>jqXHR.error()</code>, and <code>jqXHR.complete()</code> callback methods are <strong>removed as of jQuery 3.0</strong>. You can use <code>jqXHR.done()</code>, <code>jqXHR.fail()</code>, and <code>jqXHR.always()</code> instead.</p>",
"note": [{
"type": "additional",
"text": "Script and JSONP requests are not subject to the same origin policy restrictions."
},
{
"type": "additional",
"text": "If a request with jQuery.post() returns an error code, it will fail silently unless the script has also called the global <a href=\"/ajaxError/\">.ajaxError() </a> method. Alternatively, as of jQuery 1.5, the <code>.error()</code> method of the <code>jqXHR</code> object returned by jQuery.post() is also available for error handling."
}
],
"examples": [{
"desc": "Request the test.php page, but ignore the return results.",
"code": "$.post( \"test.php\" );",
"html": "",
"css": ""
},
{
"desc": "Request the test.php page and send some additional data along (while still ignoring the return results).",
"code": "$.post( \"test.php\", { name: \"John\", time: \"2pm\" } );",
"html": "",
"css": ""
},
{
"desc": "Pass arrays of data to the server (while still ignoring the return results).",
"code": "$.post( \"test.php\", { 'choices[]': [ \"Jon\", \"Susan\" ] } );",
"html": "",
"css": ""
},
{
"desc": "Send form data using Ajax requests",
"code": "$.post( \"test.php\", $( \"#testform\" ).serialize() );",
"html": "",
"css": ""
},
{
"desc": "Alert the results from requesting test.php (HTML or XML, depending on what was returned).",
"code": "$.post( \"test.php\", function( data ) {\n alert( \"Data Loaded: \" + data );\n});",
"html": "",
"css": ""
},
{
"desc": "Alert the results from requesting test.php with an additional payload of data (HTML or XML, depending on what was returned).",
"code": "$.post( \"test.php\", { name: \"John\", time: \"2pm\" })\n .done(function( data ) {\n alert( \"Data Loaded: \" + data );\n });",
"html": "",
"css": ""
},
{
"desc": "Post to the test.php page and get content which has been returned in json format (&lt;?php echo json_encode(array(\"name\"=&gt;\"John\",\"time\"=&gt;\"2pm\")); ?&gt;).",
"code": "$.post( \"test.php\", { func: \"getNameAndTime\" }, function( data ) {\n console.log( data.name ); // John\n console.log( data.time ); // 2pm\n}, \"json\");",
"html": "",
"css": ""
},
{
"desc": "Post a form using Ajax and put results in a div",
"code": "// Attach a submit handler to the form\n$( \"#searchForm\" ).submit(function( event ) {\n\n // Stop form from submitting normally\n event.preventDefault();\n\n // Get some values from elements on the page:\n var $form = $( this ),\n term = $form.find( \"input[name='s']\" ).val(),\n url = $form.attr( \"action\" );\n\n // Send the data using post\n var posting = $.post( url, { s: term } );\n\n // Put the results in a div\n posting.done(function( data ) {\n var content = $( data ).find( \"#content\" );\n $( \"#result\" ).empty().append( content );\n });\n});",
"html": "<form action=\"/\" id=\"searchForm\">\n <input type=\"text\" name=\"s\" placeholder=\"Search...\">\n <input type=\"submit\" value=\"Search\">\n</form>\n<!-- the result of the search will be rendered inside this div -->\n<div id=\"result\"></div>",
"css": ""
}
],
"categories": [
"ajax/shorthand-methods",
"version/1.0",
"version/1.5"
]
},
{
"title": "jQuery.proxy()",
"type": "method",
"name": "jQuery.proxy",
"return": "Function",
"signatures": [{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "The function whose context will be changed."
},
{
"name": "context",
"type": "PlainObject",
"desc": "The object to which the context (<code>this</code>) of the function should be set."
}
],
"added": "1.4"
},
{
"arguments": [{
"name": "context",
"type": "PlainObject",
"desc": "The object to which the context of the function should be set."
},
{
"name": "name",
"type": "String",
"desc": "The name of the function whose context will be changed (should be a property of the <code>context</code> object)."
}
],
"added": "1.4"
},
{
"arguments": [{
"name": "function",
"type": "Function",
"desc": "The function whose context will be changed."
},
{
"name": "context",
"type": "PlainObject",
"desc": "The object to which the context (<code>this</code>) of the function should be set."
},
{
"name": "additionalArguments",
"type": "Anything",
"optional": "true",
"desc": "Any number of arguments to be passed to the function referenced in the <code>function</code> argument."
}
],
"added": "1.6"
},
{
"arguments": [{
"name": "context",
"type": "PlainObject",
"desc": "The object to which the context of the function should be set."
},
{
"name": "name",
"type": "String",
"desc": "The name of the function whose context will be changed (should be a property of the <code>context</code> object)."
},
{
"name": "additionalArguments",
"type": "Anything",
"optional": "true",
"desc": "Any number of arguments to be passed to the function named in the <code>name</code> argument."
}
],
"added": "1.6"
}
],
"desc": "Takes a function and returns a new one that will always have a particular context.",
"longdesc": "<p>This method is most useful for attaching event handlers to an element where the context is pointing back to a different object. Additionally, jQuery makes sure that even if you bind the function returned from <code>jQuery.proxy()</code> it will still unbind the correct function if passed the original.</p>\n <p>Be aware, however, that jQuery's event binding subsystem assigns a unique id to each event handling function in order to track it when it is used to specify the function to be unbound. The function represented by <code>jQuery.proxy()</code> is seen as a single function by the event subsystem, even when it is used to bind different contexts. To avoid unbinding the wrong handler, use a unique event namespace for binding and unbinding (e.g., <code>\"click.myproxy1\"</code>) rather than specifying the proxied function during unbinding.</p>\n <p><strong>As of jQuery 1.6</strong>, any number of additional arguments may be supplied to <code>$.proxy()</code>, and they will be passed to the function whose context will be changed.</p>\n <p><strong>As of jQuery 1.9</strong>, when the <code>context</code> is <code>null</code> or <code>undefined</code> the proxied function will be called with the same <code>this</code> object as the proxy was called with. This allows <code>$.proxy()</code> to be used to partially apply the arguments of a function without changing the context.</p>",
"examples": [{
"desc": "Change the context of functions bound to a click handler using the \"function, context\" signature. Unbind the first handler after first click.",
"code": "var me = {\n type: \"zombie\",\n test: function( event ) {\n // Without proxy, `this` would refer to the event target\n // use event.target to reference that element.\n var element = event.target;\n $( element ).css( \"background-color\", \"red\" );\n\n // With proxy, `this` refers to the me object encapsulating\n // this function.\n $( \"#log\" ).append( \"Hello \" + this.type + \"<br>\" );\n $( \"#test\" ).off( \"click\", this.test );\n }\n};\n\nvar you = {\n type: \"person\",\n test: function( event ) {\n $( \"#log\" ).append( this.type + \" \" );\n }\n};\n\n// Execute you.test() in the context of the `you` object\n// no matter where it is called\n// i.e. the `this` keyword will refer to `you`\nvar youClick = $.proxy( you.test, you );\n\n// attach click handlers to #test\n$( \"#test\" )\n // this === \"zombie\"; handler unbound after first click\n .on( \"click\", $.proxy( me.test, me ) )\n\n // this === \"person\"\n .on( \"click\", youClick )\n\n // this === \"zombie\"\n .on( \"click\", $.proxy( you.test, me ) )\n\n // this === \"<button> element\"\n .on( \"click\", you.test );",
"html": "<p><button type=\"button\" id=\"test\">Test</button></p>\n<div id=\"log\"></div>",
"css": ""
},
{
"desc": "Enforce the context of the function using the \"context, function name\" signature. Unbind the handler after first click.",
"code": "var obj = {\n name: \"John\",\n test: function() {\n $( \"#log\" ).append( this.name );\n $( \"#test\" ).off( \"click\", obj.test );\n }\n};\n$( \"#test\" ).on( \"click\", jQuery.proxy( obj, \"test\" ) );",
"html": "<p><button id=\"test\">Test</button></p>\n <p id=\"log\"></p>",
"css": ""
},
{
"desc": "Change the context of a function bound to the click handler,",
"code": "var me = {\n // I'm a dog\n type: \"dog\",\n\n // Note that event comes *after* one and two\n test: function( one, two, event ) {\n $( \"#log\" )\n\n // `one` maps to `you`, the 1st additional\n // argument in the $.proxy function call\n .append( \"<h3>Hello \" + one.type + \":</h3>\" )\n\n // The `this` keyword refers to `me`\n // (the 2nd, context, argument of $.proxy)\n .append( \"I am a \" + this.type + \", \" )\n\n // `two` maps to `they`, the 2nd additional\n // argument in the $.proxy function call\n .append( \"and they are \" + two.type + \".<br>\" )\n\n // The event type is \"click\"\n .append( \"Thanks for \" + event.type + \"ing.\" )\n\n // The clicked element is `event.target`,\n // and its type is \"button\"\n .append( \"the \" + event.target.type + \".\" );\n }\n};\n\nvar you = { type: \"cat\" };\nvar they = { type: \"fish\" };\n\n// Set up handler to execute me.test() in the context\n// of `me`, with `you` and `they` as additional arguments\nvar proxy = $.proxy( me.test, me, you, they );\n\n$( \"#test\" )\n .on( \"click\", proxy );",
"html": "<p><button type=\"button\" id=\"test\">Test</button></p>\n<div id=\"log\"></div>",
"css": ""
}
],
"categories": [
"events/event-handler-attachment",
"utilities",
"version/1.4",
"version/1.6"
]
},
{
"entries": [{
"title": "jQuery.queue()",
"type": "method",
"name": "jQuery.queue",
"return": "Array",
"signatures": [{
"arguments": [{
"name": "element",
"type": "Element",
"desc": "A DOM element to inspect for an attached queue."
},
{
"name": "queueName",
"optional": "true",
"type": "String",
"desc": "A string containing the name of the queue. Defaults to\n\t\t\t\t\t<code>\n\t\t\t\t\t\tfx\n\t\t\t\t\t</code>\n\t\t\t\t\t, the standard effects queue."
}
],
"added": "1.3"
}],
"desc": "Show the queue of functions to be executed on the matched element.",
"longdesc": "<p>\n\t\t\t\t<strong>\n\t\t\t\t\tNote:\n\t\t\t\t</strong>\n\t\t\t\tThis is a low-level method, you should probably use\n\t\t\t\t<code>\n\t\t\t\t\t<a href=\"/queue/\">\n\t\t\t\t\t\t.queue()\n\t\t\t\t\t</a>\n\t\t\t\t</code>\n\t\t\t\tinstead.\n\t\t\t</p>",
"examples": [{
"desc": "Show the length of the queue.",
"code": "$( \"#show\" ).click(function() {\n\t\t\t\tvar n = jQuery.queue( $( \"div\" )[ 0 ], \"fx\" );\n\t\t\t\t$( \"span\" ).text( \"Queue length is: \" + n.length );\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\tfunction runIt() {\n\t\t\t\t$( \"div\" )\n\t\t\t\t.show( \"slow\" )\n\t\t\t\t.animate({\n\t\t\t\tleft: \"+=200\"\n\t\t\t\t}, 2000 )\n\t\t\t\t.slideToggle( 1000 )\n\t\t\t\t.slideToggle( \"fast\" )\n\t\t\t\t.animate({\n\t\t\t\tleft: \"-=200\"\n\t\t\t\t}, 1500 )\n\t\t\t\t.hide( \"slow\" )\n\t\t\t\t.show( 1200 )\n\t\t\t\t.slideUp( \"normal\", runIt );\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\trunIt();",
"html": "<button id=\"show\">Show Length of Queue</button>\n\t\t\t\t<span></span>\n\t\t\t\t<div></div>",
"css": "div {\n\t\t\t\tmargin: 3px;\n\t\t\t\twidth: 40px;\n\t\t\t\theight: 40px;\n\t\t\t\tposition: absolute;\n\t\t\t\tleft: 0px;\n\t\t\t\ttop: 30px;\n\t\t\t\tbackground: green;\n\t\t\t\tdisplay: none;\n\t\t\t\t}\n\t\t\t\tdiv.newcolor {\n\t\t\t\tbackground: blue;\n\t\t\t\t}\n\t\t\t\tspan {\n\t\t\t\tcolor: red;\n\t\t\t\t}"
}],
"categories": [
"data",
"utilities",
"version/1.3"
]
},
{
"title": "",
"type": "method",
"name": "jQuery.queue",
"return": "Array",
"signatures": [{
"arguments": [{
"name": "element",
"type": "Element",
"desc": "A DOM element where the array of queued functions is attached."
},
{
"name": "queueName",
"type": "String",
"desc": "A string containing the name of the queue. Defaults to\n\t\t\t\t\t<code>\n\t\t\t\t\t\tfx\n\t\t\t\t\t</code>\n\t\t\t\t\t, the standard effects queue."
},
{
"name": "newQueue",
"type": "Array",
"desc": "An array of functions to replace the current queue contents."
}
],
"added": "1.3"
},
{
"arguments": [{
"name": "element",
"type": "Element",
"desc": "A DOM element on which to add a queued function."
},
{
"name": "queueName",
"type": "String",
"desc": "A string containing the name of the queue. Defaults to\n\t\t\t\t\t<code>\n\t\t\t\t\t\tfx\n\t\t\t\t\t</code>\n\t\t\t\t\t, the standard effects queue."
},
{
"name": "callback",
"type": "Function",
"desc": "The new function to add to the queue."
}
],
"added": "1.3"
}
],
"desc": "Manipulate the queue of functions to be executed on the matched element.",
"longdesc": "<p>\n\t\t\t\t<strong>\n\t\t\t\t\tNote:\n\t\t\t\t</strong>\n\t\t\t\tThis is a low-level method, you should probably use\n\t\t\t\t<code>\n\t\t\t\t\t<a href=\"/queue/\">\n\t\t\t\t\t\t.queue()\n\t\t\t\t\t</a>\n\t\t\t\t</code>\n\t\t\t\tinstead.\n\t\t\t</p>\n\t\t\t<p>\n\t\t\t\tEvery element can have one or more queues of functions attached to it by jQuery. In most applications, only one queue (called\n\t\t\t\t<code>\n\t\t\t\t\tfx\n\t\t\t\t</code>\n\t\t\t\t) is used. Queues allow a sequence of actions to be called on an element asynchronously, without halting program execution.\n\t\t\t</p>\n\t\t\t<p>\n\t\t\t\tThe\n\t\t\t\t<code>\n\t\t\t\t\tjQuery.queue()\n\t\t\t\t</code>\n\t\t\t\tmethod allows us to directly manipulate this queue of functions. Calling\n\t\t\t\t<code>\n\t\t\t\t\tjQuery.queue()\n\t\t\t\t</code>\n\t\t\t\twith a callback is particularly useful; it allows us to place a new function at the end of the queue.\n\t\t\t</p>\n\t\t\t<p>\n\t\t\t\tNote that when adding a function with\n\t\t\t\t<code>\n\t\t\t\t\tjQuery.queue()\n\t\t\t\t</code>\n\t\t\t\t, we should ensure that\n\t\t\t\t<code>\n\t\t\t\t\tjQuery.dequeue()\n\t\t\t\t</code>\n\t\t\t\tis eventually called so that the next function in line executes.\n\t\t\t</p>",
"examples": [{
"desc": "Queue a custom function.",
"code": "$( document.body ).click(function() {\n\t\t\t\tvar divs = $( \"div\" )\n\t\t\t\t.show( \"slow\" )\n\t\t\t\t.animate({ left: \"+=200\" }, 2000 );\n\t\t\t\tjQuery.queue( divs[ 0 ], \"fx\", function() {\n\t\t\t\t$( this ).addClass( \"newcolor\" );\n\t\t\t\tjQuery.dequeue( this );\n\t\t\t\t});\n\t\t\t\tdivs.animate({ left: \"-=200\" }, 500 );\n\t\t\t\tjQuery.queue( divs[ 0 ], \"fx\", function() {\n\t\t\t\t$( this ).removeClass( \"newcolor\" );\n\t\t\t\tjQuery.dequeue( this );\n\t\t\t\t});\n\t\t\t\tdivs.slideUp();\n\t\t\t\t});",
"html": "Click here...\n\t\t\t\t<div></div>",
"css": "div {\n\t\t\t\tmargin: 3px;\n\t\t\t\twidth: 40px;\n\t\t\t\theight: 40px;\n\t\t\t\tposition: absolute;\n\t\t\t\tleft: 0px;\n\t\t\t\ttop: 30px;\n\t\t\t\tbackground: green;\n\t\t\t\tdisplay: none;\n\t\t\t\t}\n\t\t\t\tdiv.newcolor {\n\t\t\t\tbackground: blue;\n\t\t\t\t}"
},
{
"desc": "Set a queue array to delete the queue.",
"code": "$( \"#start\" ).click(function() {\n\t\t\t\tvar divs = $( \"div\" )\n\t\t\t\t.show( \"slow\" )\n\t\t\t\t.animate({ left: \"+=200\" }, 5000 );\n\t\t\t\tjQuery.queue( divs[ 0 ], \"fx\", function() {\n\t\t\t\t$( this ).addClass( \"newcolor\" );\n\t\t\t\tjQuery.dequeue( this );\n\t\t\t\t});\n\t\t\t\tdivs.animate({ left: \"-=200\" }, 1500 );\n\t\t\t\tjQuery.queue( divs[ 0 ], \"fx\", function() {\n\t\t\t\t$( this ).removeClass( \"newcolor\" );\n\t\t\t\tjQuery.dequeue( this );\n\t\t\t\t});\n\t\t\t\tdivs.slideUp();\n\t\t\t\t});\n\t\t\t\t$( \"#stop\" ).click(function() {\n\t\t\t\tjQuery.queue( $( \"div\" )[ 0 ], \"fx\", [] );\n\t\t\t\t$( \"div\" ).stop();\n\t\t\t\t});",
"html": "<button id=\"start\">Start</button>\n\t\t\t\t<button id=\"stop\">Stop</button>\n\t\t\t\t<div></div>",
"css": "div {\n\t\t\t\tmargin: 3px;\n\t\t\t\twidth: 40px;\n\t\t\t\theight: 40px;\n\t\t\t\tposition: absolute;\n\t\t\t\tleft: 0px;\n\t\t\t\ttop: 30px;\n\t\t\t\tbackground: green;\n\t\t\t\tdisplay: none;\n\t\t\t\t}\n\t\t\t\tdiv.newcolor {\n\t\t\t\tbackground: blue;\n\t\t\t\t}"
}
],
"categories": [
"data",
"utilities",
"version/1.3"
]
}
]
},
{
"title": "jQuery.ready",
"type": "property",
"name": "jQuery.ready",
"return": "Thenable",
"signatures": [{
"arguments": [],
"added": "1.8"
}],
"desc": "A Promise-like object (or \"thenable\") that resolves when the document is ready.",
"longdesc": "<p>As of jQuery 3.0, use of this object is supported via <code><a href=\"/jQuery.when/\">jQuery.when</a></code> or the native <code>Promise.resolve()</code>. Code should not make assumptions about whether this object is a <code>jQuery.Deferred</code>, native Promise, or some other type of promise object.</p>\n <p>See also <code><a href=\"/ready/\">ready()</a></code>, which makes use of this.</p>",
"examples": [{
"desc": "Listen for document ready using <code><a href=\"/jQuery.when/\">jQuery.when</a></code>.",
"code": "$.when( $.ready ).then(function() {\n // Document is ready.\n});",
"html": "",
"css": ""
},
{
"desc": "Typical usage involving another promise, using <code><a href=\"/jQuery.when/\">jQuery.when</a></code>.",
"code": "$.when(\n $.getJSON( \"ajax/test.json\" ),\n $.ready\n).done(function( data ) {\n // Document is ready.\n // Value of test.json is passed as `data`.\n});",
"html": "",
"css": ""
}
],
"categories": [
"core",
"properties/global-jquery-object-properties",
"events/document-loading",
"version/1.8"
]
},
{
"title": "jQuery.readyException()",
"type": "method",
"name": "jQuery.readyException",
"return": "Selector",
"signatures": [{
"arguments": [{
"name": "error",
"type": "Error",
"desc": "An error thrown in the function wrapped in <code>jQuery()</code>."
}],
"added": "3.1"
}],
"desc": "Handles errors thrown synchronously in functions wrapped in <code>jQuery()</code>.",
"longdesc": "<p>This method is fired when an error is thrown synchronously in a function wrapped in <code>jQuery()</code> or <code>jQuery( document ).ready()</code>, or equivalent. By default it re-throws the error in a timeout so that it's logged in the console and passed to <code>window.onerror</code> instead of being swallowed. Overwrite this method if you want to handle such errors differently.</p>",
"examples": [{
"desc": "Pass the received error to <code>console.error</code>.",
"code": "jQuery.readyException = function( error ) {\n console.error( error );\n};",
"html": "",
"css": ""
}],
"categories": [
"core",
"version/3.1"
]
},
{
"title": "jQuery.removeData()",
"type": "method",
"name": "jQuery.removeData",
"return": "undefined",
"signatures": [{
"arguments": [{
"name": "element",
"type": "Element",
"desc": "A DOM element from which to remove data."
},
{
"name": "name",
"type": "String",
"optional": "true",
"desc": "A string naming the piece of data to remove."
}
],
"added": "1.2.3"
}],
"desc": "Remove a previously-stored piece of data.",
"longdesc": "<p><strong>Note:</strong> This is a low-level method, you should probably use <code><a href=\"/removeData/\">.removeData()</a></code> instead.</p>\n <p>The <code>jQuery.removeData()</code> method allows us to remove values that were previously set using <code><a href=\"/jQuery.data/\">jQuery.data()</a></code>. When called with the name of a key, <code>jQuery.removeData()</code> deletes that particular value; when called with no arguments, all values are removed.</p>",
"examples": [{
"desc": "Set a data store for 2 names then remove one of them.",
"code": "var div = $( \"div\" )[ 0 ];\n$( \"span\" ).eq( 0 ).text( \"\" + $( \"div\" ).data( \"test1\" ) );\njQuery.data( div, \"test1\", \"VALUE-1\" );\njQuery.data( div, \"test2\", \"VALUE-2\" );\n$( \"span\" ).eq( 1 ).text( \"\" + jQuery.data( div, \"test1\" ) );\njQuery.removeData( div, \"test1\" );\n$( \"span\" ).eq( 2 ).text( \"\" + jQuery.data( div, \"test1\" ) );\n$( \"span\" ).eq( 3 ).text( \"\" + jQuery.data( div, \"test2\" ) );",
"html": "<div>value1 before creation: <span></span></div>\n<div>value1 after creation: <span></span></div>\n<div>value1 after removal: <span></span></div>\n<div>value2 after removal: <span></span></div>",
"css": "div {\n margin: 2px;\n color: blue;\n }\n span {\n color: red;\n }"
}],
"categories": [
"data",
"utilities",
"version/1.2.3"
]
},
{
"title": "jQuery.speed",
"type": "method",
"name": "jQuery.speed",
"return": "PlainObject",
"signatures": [{
"arguments": [{
"name": "settings",
"type": "PlainObject",
"optional": "true",
"properties": [{
"name": "easing",
"type": "String",
"default": "swing",
"optional": "true",
"desc": "A string indicating which easing function to use for the transition.",
"arguments": []
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete.",
"arguments": []
}
]
},
{
"name": "duration",
"default": "400",
"optional": "true",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "duration",
"default": "400",
"optional": "true",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run."
},
{
"name": "easing",
"type": "String",
"default": "swing",
"optional": "true",
"desc": "A string indicating which easing function to use for the transition."
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete, called once per matched element."
}
],
"added": "1.1"
},
{
"arguments": [{
"name": "settings",
"type": "PlainObject",
"properties": [{
"name": "duration",
"default": "400",
"optional": "true",
"type": [
"Number",
"String"
],
"desc": "A string or number determining how long the animation will run.",
"arguments": []
},
{
"name": "easing",
"type": "String",
"default": "swing",
"optional": "true",
"desc": "A string indicating which easing function to use for the transition.",
"arguments": []
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A function to call once the animation is complete.",
"arguments": []
}
]
}],
"added": "1.1"
}
],
"desc": "Creates an object containing a set of properties ready to be used in the definition of custom animations.",
"longdesc": "<p>The <code>$.speed()</code> method provides a way to define properties, such as <code>duration</code>, <code>easing</code>, and <code>queue</code>, to use in a custom animation. By using it, you don't have to implement the logic that deals with default values and optional parameters.</p>\n <p>This method is meant for plugin developers who are creating new animation methods. Letting <code>$.speed()</code> do all the parameter hockey and normalization for you, rather than duplicating the logic yourself, makes your work simpler. An example of use can be found in the animated form of <code>.addClass()</code> of jQuery UI. </p>",
"examples": [],
"categories": [
"effects/custom-effects",
"version/1.0",
"version/1.1"
]
},
{
"title": "jQuery.sub()",
"type": "method",
"name": "jQuery.sub",
"return": "jQuery",
"deprecated": "1.7",
"removed": "1.9",
"signatures": [{
"arguments": [],
"added": "1.5"
}],
"desc": "Creates a new copy of jQuery whose properties and methods can be modified without affecting the original jQuery object.",
"longdesc": "<div class=\"warning\">\n <p>Note: This API has been removed in jQuery 1.9.</p>\n </div>\n <p>There are two specific use cases for which jQuery.sub() was created. The first was for providing a painless way of overriding jQuery methods without completely destroying the original methods and another was for helping to do encapsulation and basic namespacing for jQuery plugins.</p>\n <p>Note that jQuery.sub() doesn't attempt to do any sort of isolation - that's not its intention. All the methods on the sub'd version of jQuery will still point to the original jQuery (events bound and triggered will still be through the main jQuery, data will be bound to elements through the main jQuery, Ajax queries and events will run through the main jQuery, etc.).</p>\n <p>Note that if you're looking to use this for plugin development you should first <i>strongly</i> consider using something like the jQuery UI widget factory which manages both state and plugin sub-methods. <a href=\"http://blog.nemikor.com/2010/05/15/building-stateful-jquery-plugins/\">Some examples of using the jQuery UI widget factory</a> to build a plugin.</p>\n <p>The particular use cases of this method can be best described through some examples.</p>",
"examples": [{
"desc": "Adding a method to a jQuery sub so that it isn't exposed externally:",
"code": "(function(){\n var sub$ = jQuery.sub();\n sub$.fn.myCustomMethod = function() {\n return \"just for me\";\n };\n\n sub$( document ).ready(function() {\n sub$( \"body\" ).myCustomMethod() // \"just for me\"\n });\n})();\n\ntypeof jQuery( \"body\" ).myCustomMethod // undefined",
"html": "",
"css": ""
},
{
"desc": "Override some jQuery methods to provide new functionality.",
"code": "(function() {\n var myjQuery = jQuery.sub();\n\n myjQuery.fn.remove = function() {\n\n // New functionality: Trigger a remove event\n this.trigger( \"remove\" );\n\n // Be sure to call the original jQuery remove method\n return jQuery.fn.remove.apply( this, arguments );\n };\n\n myjQuery(function( $ ) {\n $( \".menu\" ).click(function() {\n $( this ).find( \".submenu\" ).remove();\n });\n\n // A new remove event is now triggered from this copy of jQuery\n $( document ).on( \"remove\", function( event ) {\n $( event.target ).parent().hide();\n });\n });\n})();\n\n// Regular jQuery doesn't trigger a remove event when removing an element\n// This functionality is only contained within the modified 'myjQuery'.",
"html": "",
"css": ""
},
{
"desc": "Create a plugin that returns plugin-specific methods.",
"code": "(function() {\n\n // Create a new copy of jQuery using sub()\n var plugin = jQuery.sub();\n\n // Extend that copy with the new plugin methods\n plugin.fn.extend({\n open: function() {\n return this.show();\n },\n close: function() {\n return this.hide();\n }\n });\n\n // Add our plugin to the original jQuery\n jQuery.fn.myplugin = function() {\n this.addClass( \"plugin\" );\n\n // Make sure our plugin returns our special plugin version of jQuery\n return plugin( this );\n };\n})();\n\n$( document ).ready(function() {\n\n // Call the plugin, open method now exists\n $( \"#main\" ).myplugin().open();\n\n // Note: Calling just $( \"#main\" ).open() won't work as open doesn't exist!\n});",
"html": "",
"css": ""
}
],
"categories": [
"core",
"version/1.5",
"deprecated/deprecated-1.7",
"removed"
]
},
{
"title": "jQuery.support",
"type": "property",
"name": "jQuery.support",
"return": "Object",
"deprecated": "1.9",
"signatures": [{
"arguments": [],
"added": "1.3"
}],
"desc": "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 <a href=\"https://modernizr.com\">Modernizr</a> instead of dependency on properties in <code>jQuery.support</code>.",
"examples": [],
"categories": [
"properties/global-jquery-object-properties",
"utilities",
"version/1.3",
"version/1.5.1",
"deprecated/deprecated-1.9"
]
},
{
"title": "jQuery.trim()",
"type": "method",
"name": "jQuery.trim",
"return": "String",
"signatures": [{
"arguments": [{
"name": "str",
"type": "String",
"desc": "The string to trim."
}],
"added": "1.0"
}],
"desc": "Remove the whitespace from the beginning and end of a string.",
"longdesc": "<p>The <code>$.trim()</code> function removes all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of the supplied string. If these whitespace characters occur in the middle of the string, they are preserved.</p>",
"examples": [{
"desc": "Remove the white spaces at the start and at the end of the string.",
"code": "var str = \" lots of spaces before and after \";\n$( \"#original\" ).html( \"Original String: '\" + str + \"'\" );\n$( \"#trimmed\" ).html( \"$.trim()'ed: '\" + $.trim(str) + \"'\" );",
"html": "<pre id=\"original\"></pre>\n<pre id=\"trimmed\"></pre>",
"css": ""
},
{
"desc": "Remove the white spaces at the start and at the end of the string.",
"code": "$.trim(\" hello, how are you? \");",
"html": "",
"css": ""
}
],
"categories": [
"utilities",
"version/1.0"
]
},
{
"title": "jQuery.type()",
"type": "method",
"name": "jQuery.type",
"return": "String",
"signatures": [{
"arguments": [{
"name": "obj",
"type": "Anything",
"desc": "Object to get the internal JavaScript [[Class]] of."
}],
"added": "1.4.3"
}],
"desc": "Determine the internal JavaScript [[Class]] of an object.",
"longdesc": "<p>A number of techniques are used to determine the exact return value for an object. The [[Class]] is determined as follows:</p>\n <ul>\n <li>If the object is undefined or null, then \"undefined\" or \"null\" is returned accordingly.\n <ul>\n <li>jQuery.type( undefined ) === \"undefined\"</li>\n <li>jQuery.type() === \"undefined\"</li>\n <li>jQuery.type( window.notDefined ) === \"undefined\"</li>\n <li>jQuery.type( null ) === \"null\"</li>\n </ul>\n </li>\n <li>If the argument is either a primitive value or an instance of a standard built-in ECMAScript object, the [[Class]] internal property is used to determine the type. (<a href=\"http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/\">More details about this technique.</a>)\n <ul>\n <li>jQuery.type( true ) === \"boolean\"</li>\n <li>jQuery.type( new Boolean() ) === \"boolean\"</li>\n <li>jQuery.type( 3 ) === \"number\"</li>\n <li>jQuery.type( new Number(3) ) === \"number\"</li>\n <li>jQuery.type( \"test\" ) === \"string\"</li>\n <li>jQuery.type( new String(\"test\") ) === \"string\"</li>\n <li>jQuery.type( function(){} ) === \"function\"</li>\n <li>jQuery.type( [] ) === \"array\"</li>\n <li>jQuery.type( new Array() ) === \"array\"</li>\n <li>jQuery.type( new Date() ) === \"date\"</li>\n <li>jQuery.type( new Error() ) === \"error\" // <strong>as of jQuery 1.9</strong></li>\n <li>jQuery.type( Symbol() ) === \"symbol\" // <strong>as of jQuery 1.9</strong></li>\n <li>jQuery.type( Object(Symbol()) ) === \"symbol\" // <strong>as of jQuery 1.12</strong></li>\n <li>jQuery.type( /test/ ) === \"regexp\"</li>\n </ul>\n </li>\n <li>Everything else returns \"object\" as its type.</li>\n </ul>",
"examples": [{
"desc": "Find out if the parameter is a RegExp.",
"code": "$( \"b\" ).append( \"\" + jQuery.type( /test/ ) );",
"html": "Is it a RegExp? <b></b>",
"css": ""
}],
"categories": [
"utilities",
"version/1.4.3"
]
},
{
"title": "jQuery.unique()",
"type": "method",
"name": "jQuery.unique",
"return": "Array",
"deprecated": "3.0",
"signatures": [{
"arguments": [{
"name": "array",
"type": "Array",
"desc": "The Array of DOM elements."
}],
"added": "1.1.3"
}],
"desc": "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.",
"longdesc": "<p><strong>As of jQuery 3.0, this method is deprecated and just an alias of <code><a href=\"/jQuery.uniqueSort/\">jQuery.uniqueSort()</a></code>. Please use that method instead.</strong></p>\n <p>The <code>$.unique()</code> function searches through an array of objects, sorting the array, and removing any duplicate nodes. A node is considered a duplicate if it is the <em>exact same</em> node as one already in the array; two different nodes with identical attributes are not considered to be duplicates. This function only works on plain JavaScript arrays of DOM elements, and is chiefly used internally by jQuery. You probably will never need to use it.</p>\n <p>As of jQuery 1.4 the results will always be returned in document order.</p>",
"examples": [{
"desc": "Removes any duplicate elements from the array of divs.",
"code": "// unique() must take a native array\nvar divs = $( \"div\" ).get();\n\n// Add 3 elements of class dup too (they are divs)\ndivs = divs.concat( $( \".dup\" ).get() );\n$( \"div\" ).eq( 1 ).text( \"Pre-unique there are \" + divs.length + \" elements.\" );\n\ndivs = jQuery.unique( divs );\n$( \"div\" ).eq( 2 ).text( \"Post-unique there are \" + divs.length + \" elements.\" )\n .css( \"color\", \"red\" );",
"html": "<div>There are 6 divs in this document.</div>\n<div></div>\n<div class=\"dup\"></div>\n<div class=\"dup\"></div>\n<div class=\"dup\"></div>\n<div></div>",
"css": "div {\n color: blue;\n }"
}],
"categories": [
"utilities",
"version/1.1.3",
"deprecated/deprecated-3.0"
]
},
{
"title": "jQuery.uniqueSort()",
"type": "method",
"name": "jQuery.uniqueSort",
"return": "Array",
"signatures": [{
"arguments": [{
"name": "array",
"type": "Array",
"desc": "The Array of DOM elements."
}],
"added": "1.12-2.2"
}],
"desc": "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.",
"longdesc": "<p>The <code>$.uniqueSort()</code> function searches through an array of objects, sorting the array, and removing any duplicate nodes. A node is considered a duplicate if it is the <em>exact same</em> node as one already in the array; two different nodes with identical attributes are not considered to be duplicates. This function only works on plain JavaScript arrays of DOM elements, and is chiefly used internally by jQuery. You probably will never need to use it.</p>\n <p>Prior to jQuery 3.0, this method was called <code><a href=\"/jQuery.unique/\">jQuery.unique()</a></code>.</p>\n <p>As of jQuery 1.4 the results will always be returned in document order.</p>",
"examples": [{
"desc": "Removes any duplicate elements from the array of divs.",
"code": "// unique() must take a native array\nvar divs = $( \"div\" ).get();\n\n// Add 3 elements of class dup too (they are divs)\ndivs = divs.concat( $( \".dup\" ).get() );\n$( \"div\" ).eq( 1 ).text( \"Pre-unique there are \" + divs.length + \" elements.\" );\n\ndivs = jQuery.uniqueSort( divs );\n$( \"div\" ).eq( 2 ).text( \"Post-unique there are \" + divs.length + \" elements.\" )\n .css( \"color\", \"red\" );",
"html": "<div>There are 6 divs in this document.</div>\n<div></div>\n<div class=\"dup\"></div>\n<div class=\"dup\"></div>\n<div class=\"dup\"></div>\n<div></div>",
"css": "div {\n color: blue;\n }"
}],
"categories": [
"utilities",
"version/1.12-2.2"
]
},
{
"title": "jQuery.when()",
"type": "method",
"name": "jQuery.when",
"return": "Promise",
"signatures": [{
"arguments": [{
"name": "deferreds",
"type": [
"Deferred",
"Promise",
"Thenable"
],
"desc": "Zero or more Thenable objects."
}],
"added": "1.5"
}],
"desc": "Provides a way to execute callback functions based on zero or more Thenable objects, usually <a href=\"/category/deferred-object/\">Deferred</a> objects that represent asynchronous events.",
"longdesc": "<p>If no arguments are passed to <code>jQuery.when()</code>, it will return a resolved Promise.</p>\n <p>If a single Deferred is passed to <code>jQuery.when()</code>, its Promise object (a subset of the Deferred methods) is returned by the method. Additional methods of the Promise object can be called to attach callbacks, such as <a href=\"/deferred.then/\"><code>deferred.then</code></a>. When the Deferred is resolved or rejected, usually by the code that created the Deferred originally, the appropriate callbacks will be called. For example, the jqXHR object returned by <code>jQuery.ajax()</code> is a Promise-compatible object and can be used this way:</p>\n <pre><code>\n$.when( $.ajax( \"test.aspx\" ) ).then(function( data, textStatus, jqXHR ) {\n alert( jqXHR.status ); // Alerts 200\n});\n </code></pre>\n <p>If a single argument is passed to <code>jQuery.when()</code> and it is not a Deferred or a Promise, it will be treated as a resolved Deferred and any doneCallbacks attached will be executed immediately. The doneCallbacks are passed the original argument. In this case any failCallbacks you might set are never called since the Deferred is never rejected. For example:</p>\n <pre><code>\n$.when( { testing: 123 } ).done(function( x ) {\n alert( x.testing ); // Alerts \"123\"\n});\n </code></pre>\n <p>If you don't pass it any arguments at all, <code>jQuery.when()</code> will return a resolved promise.</p>\n <pre><code>\n$.when().then(function( x ) {\n alert( \"I fired immediately\" );\n});\n </code></pre>\n <p>In the case where multiple Deferred objects are passed to <code>jQuery.when()</code>, the method returns the Promise from a new \"master\" Deferred object that tracks the aggregate state of all the Deferreds it has been passed. The method will resolve its master Deferred as soon as all the Deferreds resolve, or reject the master Deferred as soon as one of the Deferreds is rejected. If the master Deferred is resolved, the doneCallbacks for the master Deferred are executed. The arguments passed to the doneCallbacks provide the resolved values for each of the Deferreds, and matches the order the Deferreds were passed to <code>jQuery.when()</code>. For example:</p>\n <pre><code>\nvar d1 = $.Deferred();\nvar d2 = $.Deferred();\n\n$.when( d1, d2 ).done(function ( v1, v2 ) {\n console.log( v1 ); // \"Fish\"\n console.log( v2 ); // \"Pizza\"\n});\n\nd1.resolve( \"Fish\" );\nd2.resolve( \"Pizza\" );\n </code></pre>\n <p>In the event a Deferred was resolved with no value, the corresponding doneCallback argument will be undefined. If a Deferred resolved to a single value, the corresponding argument will hold that value. In the case where a Deferred resolved to multiple values, the corresponding argument will be an array of those values. For example:</p>\n <pre><code>\nvar d1 = $.Deferred();\nvar d2 = $.Deferred();\nvar d3 = $.Deferred();\n\n$.when( d1, d2, d3 ).done(function ( v1, v2, v3 ) {\n console.log( v1 ); // v1 is undefined\n console.log( v2 ); // v2 is \"abc\"\n console.log( v3 ); // v3 is an array [ 1, 2, 3, 4, 5 ]\n});\n\nd1.resolve();\nd2.resolve( \"abc\" );\nd3.resolve( 1, 2, 3, 4, 5 );\n </code></pre>\n <p>In the multiple-Deferreds case where one of the Deferreds is rejected, <code>jQuery.when()</code> immediately fires the failCallbacks for its master Deferred. Note that some of the Deferreds may still be unresolved at that point. The arguments passed to the failCallbacks match the signature of the failCallback for the Deferred that was rejected. If you need to perform additional processing for this case, such as canceling any unfinished Ajax requests, you can keep references to the underlying jqXHR objects in a closure and inspect/cancel them in the failCallback.</p>",
"examples": [{
"desc": "Execute a function after two Ajax requests are successful. (See the jQuery.ajax() documentation for a complete description of success and error cases for an ajax request).",
"code": "$.when( $.ajax( \"/page1.php\" ), $.ajax( \"/page2.php\" ) ).done(function( a1, a2 ) {\n // a1 and a2 are arguments resolved for the page1 and page2 ajax requests, respectively.\n // Each argument is an array with the following structure: [ data, statusText, jqXHR ]\n var data = a1[ 0 ] + a2[ 0 ]; // a1[ 0 ] = \"Whip\", a2[ 0 ] = \" It\"\n if ( /Whip It/.test( data ) ) {\n alert( \"We got what we came for!\" );\n }\n});",
"html": "",
"css": ""
},
{
"desc": "Execute the function <code>myFunc</code> when both ajax requests are successful, or <code>myFailure</code> if either one has an error.",
"code": "$.when( $.ajax( \"/page1.php\" ), $.ajax( \"/page2.php\" ) )\n .then( myFunc, myFailure );",
"html": "",
"css": ""
}
],
"categories": [
"core",
"deferred-object",
"version/1.5"
]
},
{
"entries": [{
"title": "jQuery()",
"type": "method",
"name": "jQuery",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "selector",
"type": "Selector",
"desc": "A string containing a selector expression"
},
{
"name": "context",
"optional": "true",
"type": [
"Element",
"jQuery"
],
"desc": "A DOM Element, Document, or jQuery to use as context"
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "element",
"type": "Element",
"desc": "A DOM element to wrap in a jQuery object."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "elementArray",
"type": "Array",
"desc": "An array containing a set of DOM elements to wrap in a jQuery object."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "object",
"type": "PlainObject",
"desc": "A plain object to wrap in a jQuery object."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "selection",
"type": "jQuery",
"desc": "An existing jQuery object to clone."
}],
"added": "1.0"
},
{
"arguments": [],
"added": "1.4"
}
],
"desc": "Accepts a string containing a CSS selector which is then used to match a set of elements.",
"longdesc": "<p>In the first formulation listed above, <code>jQuery()</code> — which can also be written as <code>$()</code> — searches through the DOM for any elements that match the provided selector and creates a new jQuery object that references these elements:</p>\n <pre><code>$( \"div.foo\" );</code></pre>\n <p>If no elements match the provided selector, the new jQuery object is \"empty\"; that is, it contains no elements and has <code><a href=\"/length/\">.length</a></code> property of 0.</p>\n <h4 id=\"selector-context\">Selector Context</h4>\n <p>By default, selectors perform their searches within the DOM starting at the document root. However, an alternate context can be given for the search by using the optional second parameter to the <code>$()</code> function. For example, to do a search within an event handler, the search can be restricted like so:</p>\n <pre><code>\n$( \"div.foo\" ).click(function() {\n $( \"span\", this ).addClass( \"bar\" );\n});\n </code></pre>\n <p>When the search for the span selector is restricted to the context of <code>this</code>, only spans within the clicked element will get the additional class.</p>\n <p>Internally, selector context is implemented with the <code>.find()</code> method, so <code>$( \"span\", this )</code> is equivalent to <code>$( this ).find( \"span\" )</code>.</p>\n\n <h4 id=\"using-dom-elements\">Using DOM elements</h4>\n <p>The second and third formulations of this function create a jQuery object using one or more DOM elements that were already selected in some other way. A jQuery object is created from the array elements in the order they appeared in the array; unlike most other multi-element jQuery operations, the elements are not sorted in DOM order. Elements will be copied from the array as-is and won't be unwrapped if they're already jQuery collections.</p>\n <p>Please note that although you can pass text nodes and comment nodes into a jQuery collection this way, most operations don't support them. The few that do will have an explicit note on their API documentation page.</p>\n <p>A common use of single-DOM-element construction is to call jQuery methods on an element that has been passed to a callback function through the keyword <code>this</code>:</p>\n <pre><code>\n$( \"div.foo\" ).click(function() {\n $( this ).slideUp();\n});\n </code></pre>\n <p>This example causes elements to be hidden with a sliding animation when clicked. Because the handler receives the clicked item in the <code>this</code> keyword as a bare DOM element, the element must be passed to the <code>$()</code> function before applying jQuery methods to it.</p>\n <p>XML data returned from an Ajax call can be passed to the <code>$()</code> function so individual elements of the XML structure can be retrieved using <code>.find()</code> and other DOM traversal methods.</p>\n <pre><code>\n$.post( \"url.xml\", function( data ) {\n var $child = $( data ).find( \"child\" );\n});\n </code></pre>\n\n <h4 id=\"cloning-jquery-objects\">Cloning jQuery Objects</h4>\n <p>When a jQuery object is passed to the <code>$()</code> function, a clone of the object is created. This new jQuery object references the same DOM elements as the initial one.</p>\n\n <h4 id=\"returning-empty-set\">Returning an Empty Set</h4>\n <p>Calling the <code>jQuery()</code> method with <em>no arguments</em> returns an empty jQuery set (with a <code><a href=\"/length/\">.length</a></code> property of 0). Similarly, if an argument of <code>null</code>, <code>undefined</code>, an empty array (<code>[]</code>), or an empty string (<code>\"\"</code>) is passed, the set contains no elements.</p>\n <h4 id=\"working-with-plain-objects\">Working With Plain Objects</h4>\n <p>At present, the only operations supported on plain JavaScript objects wrapped in jQuery are: <code>.data()</code>,<code>.prop()</code>,<code>.on()</code>, <code>.off()</code>, <code>.trigger()</code> and <code>.triggerHandler()</code>. The use of <code>.data()</code> (or any method requiring <code>.data()</code>) on a plain object will result in a new property on the object called jQuery{randomNumber} (eg. jQuery123456789).</p>\n <pre><code>\n// Define a plain object\nvar foo = { foo: \"bar\", hello: \"world\" };\n\n// Pass it to the jQuery function\nvar $foo = $( foo );\n\n// Test accessing property values\nvar test1 = $foo.prop( \"foo\" ); // bar\n\n// Test setting property values\n$foo.prop( \"foo\", \"foobar\" );\nvar test2 = $foo.prop( \"foo\" ); // foobar\n\n// Test using .data() as summarized above\n$foo.data( \"keyName\", \"someValue\" );\nconsole.log( $foo ); // will now contain a jQuery{randomNumber} property\n\n// Test binding an event name and triggering\n$foo.on( \"eventName\", function () {\n console.log( \"eventName was called\" );\n});\n\n$foo.trigger( \"eventName\" ); // Logs \"eventName was called\"\n </code></pre>\n <p>Should <code>.trigger( \"eventName\" )</code> be used, it will search for an \"eventName\" property on the object and attempt to execute it after any attached jQuery handlers are executed. It does not check whether the property is a function or not. To avoid this behavior, <code>.triggerHandler( \"eventName\" )</code> should be used instead.</p>\n <pre><code>\n$foo.triggerHandler( \"eventName\" ); // Also logs \"eventName was called\"\n </code></pre>",
"examples": [{
"desc": "Find all p elements that are children of a div element and apply a border to them.",
"code": "$( \"div > p\" ).css( \"border\", \"1px solid gray\" );",
"html": "<p>one</p>\n<div><p>two</p></div>\n<p>three</p>",
"css": ""
},
{
"desc": "Find all inputs of type radio within the first form in the document.",
"code": "$( \"input:radio\", document.forms[ 0 ] );",
"html": "",
"css": ""
},
{
"desc": "Find all div elements within an XML document from an Ajax response.",
"code": "$( \"div\", xml.responseXML );",
"html": "",
"css": ""
},
{
"desc": "Set the background color of the page to black.",
"code": "$( document.body ).css( \"background\", \"black\" );",
"html": "",
"css": ""
},
{
"desc": "Hide all the input elements within a form.",
"code": "$( myForm.elements ).hide();",
"html": "",
"css": ""
}
],
"categories": [
"core",
"version/1.0",
"version/1.4"
]
},
{
"title": "",
"type": "method",
"name": "jQuery",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "html",
"type": "htmlString",
"desc": "A string of HTML to create on the fly. Note that this parses HTML, <strong>not</strong> XML."
},
{
"name": "ownerDocument",
"optional": "true",
"type": "document",
"desc": "A document in which the new elements will be created."
}
],
"added": "1.0"
},
{
"arguments": [{
"name": "html",
"type": "htmlString",
"desc": "A string defining a single, standalone, HTML element (e.g. &lt;div/&gt; or &lt;div&gt;&lt;/div&gt;)."
},
{
"name": "attributes",
"type": "PlainObject",
"desc": "An object of attributes, events, and methods to call on the newly-created element."
}
],
"added": "1.4"
}
],
"desc": "Creates DOM elements on the fly from the provided string of raw HTML.",
"longdesc": "<h4 id=\"creating-new-elements\">Creating New Elements</h4>\n <p>If a string is passed as the parameter to <code>$()</code>, jQuery examines the string to see if it looks like HTML (i.e., it starts with <code>&lt;tag ... &gt;</code>). If not, the string is interpreted as a selector expression, as explained above. But if the string appears to be an HTML snippet, jQuery attempts to create new DOM elements as described by the HTML. Then a jQuery object is created and returned that refers to these elements. You can perform any of the usual jQuery methods on this object:</p>\n <pre><code>$( \"&lt;p id='test'&gt;My &lt;em&gt;new&lt;/em&gt; text&lt;/p&gt;\" ).appendTo( \"body\" );</code></pre>\n <p>For explicit parsing of a string to HTML, use the <a href=\"/jQuery.parseHTML/\">$.parseHTML()</a> method.</p>\n <p>By default, elements are created with an <code>.ownerDocument</code> matching the document into which the jQuery library was loaded. Elements being injected into a different document should be created using that document, e.g., <code>$(\"&lt;p&gt;hello iframe&lt;/p&gt;\", $(\"#myiframe\").prop(\"contentWindow\").document)</code>.</p>\n <p>If the HTML is more complex than a single tag without attributes, as it is in the above example, the actual creation of the elements is handled by the browser's <code>.innerHTML</code> mechanism. In most cases, jQuery creates a new <code>&lt;div&gt;</code> element and sets the <code>innerHTML</code> property of the element to the HTML snippet that was passed in. When the parameter has a single tag (with optional closing tag or quick-closing) — <code>$( \"&lt;img /&gt;\" )</code> or <code>$( \"&lt;img&gt;\" )</code>, <code>$( \"&lt;a&gt;&lt;/a&gt;\" )</code> or <code>$( \"&lt;a&gt;\" )</code> — jQuery creates the element using the native JavaScript <code>.createElement()</code> function.</p>\n <p>When passing in complex HTML, some browsers may not generate a DOM that exactly replicates the HTML source provided. As mentioned, jQuery uses the browser's <code>.innerHTML</code> property to parse the passed HTML and insert it into the current document. During this process, some browsers filter out certain elements such as <code>&lt;html&gt;</code>, <code>&lt;title&gt;</code>, or <code>&lt;head&gt;</code> elements. As a result, the elements inserted may not be representative of the original string passed.</p>\n <p>Filtering isn't, however, limited to these tags. For example, Internet Explorer prior to version 8 will also convert all <code>href</code> properties on links to absolute URLs, and Internet Explorer prior to version 9 will not correctly handle HTML5 elements without the addition of a separate <a href=\"https://code.google.com/p/html5shiv/\">compatibility layer</a>.</p>\n <p>To ensure cross-platform compatibility, the snippet must be well-formed. Tags that can contain other elements should be paired with a closing tag:</p>\n <pre><code>$( \"&lt;a href='https://jquery.com'&gt;&lt;/a&gt;\" );</code></pre>\n <p>Tags that cannot contain elements may be quick-closed or not:</p>\n <pre><code>\n$( \"&lt;img&gt;\" );\n$( \"&lt;input&gt;\" );\n </code></pre>\n <p>When passing HTML to <code>jQuery()</code>, note that text nodes are not treated as DOM elements. With the exception of a few methods (such as <code>.content()</code>), they are generally ignored or removed. E.g:</p>\n <pre><code>\nvar el = $( \"&lt;br&gt;2&lt;br&gt;3\" ); // returns [&lt;br&gt;, \"2\", &lt;br&gt;]\nel = $( \"&lt;br&gt;2&lt;br&gt;3 &gt;\" ); // returns [&lt;br&gt;, \"2\", &lt;br&gt;, \"3 &amp;gt;\"]\n </code></pre>\n <p>This behavior is expected. <strong>As of jQuery 1.9.0</strong> (and unless using the <a href=\"https://github.com/jquery/jquery-migrate/#readme\">jQuery Migrate plugin</a>), <code>jQuery()</code> requires the HTML string to start with a <code>&lt;</code> (i.e text nodes cannot appear at the front of the HTML string).</p>\n <p><strong>As of jQuery 1.4</strong>, the second argument to <code>jQuery()</code> can accept a plain object consisting of a superset of the properties that can be passed to the <a href=\"/attr/\">.attr()</a> method.</p>\n <p><strong>Important:</strong> If the second argument is passed, the HTML string in the first argument must represent a simple element with no attributes. <strong>As of jQuery 1.4</strong>, any <a href=\"/category/events/\">event type</a> can be passed in, and the following jQuery methods can be called: <a href=\"/val/\">val</a>, <a href=\"/css/\">css</a>, <a href=\"/html/\">html</a>, <a href=\"/text/\">text</a>, <a href=\"/data/\">data</a>, <a href=\"/width/\">width</a>, <a href=\"/height/\">height</a>, or <a href=\"/offset/\">offset</a>.</p>\n <p><strong>As of jQuery 1.8</strong>, any jQuery instance method (a method of <code>jQuery.fn</code>) can be used as a property of the object passed to the second parameter:</p>\n <pre><code>\n$( \"<div/>\", {\n \"class\": \"my-div\",\n on: {\n touchstart: function( event ) {\n // Do something\n }\n }\n}).appendTo( \"body\" );\n </code></pre>\n <p>The name <code>\"class\"</code> must be quoted in the object since it is a JavaScript reserved word, and <code>\"className\"</code> cannot be used since it refers to the DOM property, not the attribute. </p>\n <p>While the second argument is convenient, its flexibility can lead to unintended consequences (e.g. <code>$( \"&lt;input&gt;\", {size: \"4\"} )</code> calling the <code>.size()</code> method instead of setting the size attribute). The previous code block could thus be written instead as:</p>\n<pre><code>\n$( \"<div/>\" )\n .addClass( \"my-div\" )\n .on({\n touchstart: function( event ) {\n // Do something\n }\n })\n .appendTo( \"body\" );\n </code></pre>",
"examples": [{
"desc": "Create a div element (and all of its contents) dynamically and append it to the body element. Internally, an element is created and its innerHTML property set to the given markup.",
"code": "$( \"<div><p>Hello</p></div>\" ).appendTo( \"body\" )",
"html": "",
"css": ""
},
{
"desc": "Create some DOM elements.",
"code": "$( \"<div/>\", {\n \"class\": \"test\",\n text: \"Click me!\",\n click: function() {\n $( this ).toggleClass( \"test\" );\n }\n})\n .appendTo( \"body\" );",
"html": "",
"css": ""
}
],
"categories": [
"core",
"version/1.0",
"version/1.4"
]
},
{
"title": "",
"type": "method",
"name": "jQuery",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "callback",
"type": "Function",
"desc": "The function to execute when the DOM is ready."
}],
"added": "1.0"
}],
"desc": "Binds a function to be executed when the DOM has finished loading.",
"longdesc": "<p>This function behaves just like <code>$( document ).ready()</code>, in that it should be used to wrap other <code>$()</code> operations on your page that depend on the DOM being ready. While this function is, technically, chainable, there really isn't much use for chaining against it.</p>",
"examples": [{
"desc": "Execute the function when the DOM is ready to be used.",
"code": "$(function() {\n // Document is ready\n});",
"html": "",
"css": ""
},
{
"desc": "Use both the shortcut for $(document).ready() and the argument to write failsafe jQuery code using the $ alias, without relying on the global alias.",
"code": "jQuery(function( $ ) {\n // Your code using failsafe $ alias here...\n});",
"html": "",
"css": ""
}
],
"categories": [
"core",
"version/1.0",
"version/1.4"
]
}
]
},
{
"title": ".jquery",
"type": "property",
"name": "jquery",
"return": "String",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "A string containing the jQuery version number.",
"longdesc": "<p>The <code>.jquery</code> property is assigned to the jQuery prototype, commonly referred to by its alias <code>$.fn</code>. It is a string containing the version number of <code>jQuery</code>, such as \"1.5.0\" or \"1.4.4\".</p>",
"examples": [{
"desc": "Determine if an object is a jQuery object",
"code": "var a = { what: \"A regular JS object\" },\n b = $( \"body\" );\n\nif ( a.jquery ) { // Falsy, since it's undefined\n alert( \"a is a jQuery object!\" );\n}\n\nif ( b.jquery ) { // Truthy, since it's a string\n alert( \"b is a jQuery object!\" );\n}",
"html": "",
"css": ""
},
{
"desc": "Get the current version of jQuery running on the page",
"code": "alert( \"You are running jQuery version: \" + $.fn.jquery );",
"html": "",
"css": ""
}
],
"categories": [
"internals",
"properties/jquery-object-instance-properties"
]
},
{
"title": ".keydown()",
"type": "method",
"name": "keydown",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"keydown\" JavaScript event, or trigger that event on an element.",
"longdesc": "<p>This method is a shortcut for <code>.on( \"keydown\", handler )</code> in the first and second variations, and <code>.trigger( \"keydown\" )</code> in the third.</p>\n <p>The <code>keydown</code> event is sent to an element when the user presses a key on the keyboard. If the key is kept pressed, the event is sent every time the operating system repeats the key. It can be attached to any element, but the event is only sent to the element that has the focus. Focusable elements can vary between browsers, but form elements can always get focus so are reasonable candidates for this event type.</p>\n <p>For example, consider the HTML:</p>\n <pre><code>\n&lt;form&gt;\n &lt;input id=\"target\" type=\"text\" value=\"Hello there\"&gt;\n&lt;/form&gt;\n&lt;div id=\"other\"&gt;\n Trigger the handler\n&lt;/div&gt;\n </code></pre>\n <p>The event handler can be bound to the input field:</p>\n <pre><code>\n$( \"#target\" ).keydown(function() {\n alert( \"Handler for .keydown() called.\" );\n});\n </code></pre>\n <p>Now when the insertion point is inside the field, pressing a key displays the alert:</p>\n <p>\n <samp>Handler for .keydown() called.</samp>\n </p>\n <p>To trigger the event manually, apply <code>.keydown()</code> without an argument:</p>\n <pre><code>\n$( \"#other\" ).click(function() {\n $( \"#target\" ).keydown();\n});\n </code></pre>\n <p>After this code executes, clicks on <samp>Trigger the handler</samp> will also alert the message.</p>\n <p>If key presses anywhere need to be caught (for example, to implement global shortcut keys on a page), it is useful to attach this behavior to the <code>document</code> object. Because of event bubbling, all key presses will make their way up the DOM to the <code>document</code> object unless explicitly stopped.</p>\n <p>To determine which key was pressed, examine the <a href=\"/category/events/event-object/\">event object</a> that is passed to the handler function. While browsers use differing properties to store this information, jQuery normalizes the <code>.which</code> property so you can reliably use it to retrieve the key code. This code corresponds to a key on the keyboard, including codes for special keys such as arrows. For catching actual text entry, <code>.keypress()</code> may be a better choice.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.keydown()</code> method is just a shorthand for <code>.on( \"keydown\", handler )</code>, detaching is possible using <code>.off( \"keydown\" )</code>."
}],
"examples": [{
"desc": "Show the event object for the keydown handler when a key is pressed in the input.",
"code": "var xTriggered = 0;\n$( \"#target\" ).keydown(function( event ) {\n if ( event.which == 13 ) {\n event.preventDefault();\n }\n xTriggered++;\n var msg = \"Handler for .keydown() called \" + xTriggered + \" time(s).\";\n $.print( msg, \"html\" );\n $.print( event );\n});\n\n$( \"#other\" ).click(function() {\n $( \"#target\" ).keydown();\n});",
"html": "<form>\n <fieldset>\n <label for=\"target\">Type Something:</label>\n <input id=\"target\" type=\"text\">\n </fieldset>\n</form>\n<button id=\"other\">\n Trigger the handler\n</button>\n<script type=\"text/javascript\" src=\"/resources/events.js\"></script>",
"css": "fieldset {\n margin-bottom: 1em;\n }\n input {\n display: block;\n margin-bottom: .25em;\n }\n #print-output {\n width: 100%;\n }\n .print-output-line {\n white-space: pre;\n padding: 5px;\n font-family: monaco, monospace;\n font-size: .7em;\n }"
}],
"categories": [
"events/keyboard-events",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ".keypress()",
"type": "method",
"name": "keypress",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"keypress\" JavaScript event, or trigger that event on an element.",
"longdesc": "<p><strong>Note:</strong> as the <code>keypress</code> event isn't covered by any official specification, the actual behavior encountered when using it may differ across browsers, browser versions, and platforms.</p>\n <p>This method is a shortcut for <code>.on( \"keypress\", handler )</code> in the first two variations, and <code>.trigger( \"keypress\" )</code> in the third.</p>\n <p>The <code>keypress</code> event is sent to an element when the browser registers keyboard input. This is similar to the <code>keydown</code> event, except that modifier and non-printing keys such as <kbd>Shift</kbd>, <kbd>Esc</kbd>, and <kbd>delete</kbd> trigger <code>keydown</code> events but not <code>keypress</code> events. Other differences between the two events may arise depending on platform and browser.</p>\n <p>A <code>keypress</code> event handler can be attached to any element, but the event is only sent to the element that has the focus. Focusable elements can vary between browsers, but form controls can always get focus so are reasonable candidates for this event type.</p>\n <p>For example, consider the HTML:</p>\n <pre><code>\n&lt;form&gt;\n &lt;fieldset&gt;\n &lt;input id=\"target\" type=\"text\" value=\"Hello there\"&gt;\n &lt;/fieldset&gt;\n&lt;/form&gt;\n&lt;div id=\"other\"&gt;\n Trigger the handler\n&lt;/div&gt;\n </code></pre>\n <p>The event handler can be bound to the input field:</p>\n <pre><code>\n$( \"#target\" ).keypress(function() {\n console.log( \"Handler for .keypress() called.\" );\n});\n </code></pre>\n <p>Now when the insertion point is inside the field, pressing a key displays the log:</p>\n <p>\n <samp>Handler for .keypress() called.</samp>\n </p>\n <p>To trigger the event manually, apply <code>.keypress()</code> without an argument:</p>\n <pre><code>\n$( \"#other\" ).click(function() {\n $( \"#target\" ).keypress();\n});\n </code></pre>\n <p>After this code executes, clicks on the <samp>Trigger the handler</samp> div will also log the message.</p>\n <p>If key presses anywhere need to be caught (for example, to implement global shortcut keys on a page), it is useful to attach this behavior to the <code>document</code> object. Because of event bubbling, all key presses will make their way up the DOM to the <code>document</code> object unless explicitly stopped.</p>\n <p>To determine which character was entered, examine the <code>event</code> object that is passed to the handler function. While browsers use differing properties to store this information, jQuery normalizes the <code>.which</code> property so you can reliably use it to retrieve the character code.</p>\n <p>Note that <code>keydown</code> and <code>keyup</code> provide a code indicating which key is pressed, while <code>keypress</code> indicates which character was entered. For example, a lowercase \"a\" will be reported as 65 by <code>keydown</code> and <code>keyup</code>, but as 97 by <code>keypress</code>. An uppercase \"A\" is reported as 65 by all events. Because of this distinction, when catching special keystrokes such as arrow keys, <code>.keydown()</code> or <code>.keyup()</code> is a better choice.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.keypress()</code> method is just a shorthand for <code>.on( \"keypress\", handler )</code>, detaching is possible using <code>.off( \"keypress\" )</code>."
}],
"examples": [{
"desc": "Show the event object when a key is pressed in the input. Note: This demo relies on a simple $.print() plugin (https://api.jquery.com/resources/events.js) for the event object's output.",
"code": "var xTriggered = 0;\n$( \"#target\" ).keypress(function( event ) {\n if ( event.which == 13 ) {\n event.preventDefault();\n }\n xTriggered++;\n var msg = \"Handler for .keypress() called \" + xTriggered + \" time(s).\";\n $.print( msg, \"html\" );\n $.print( event );\n});\n\n$( \"#other\" ).click(function() {\n $( \"#target\" ).keypress();\n});",
"html": "<form>\n <fieldset>\n <label for=\"target\">Type Something:</label>\n <input id=\"target\" type=\"text\">\n </fieldset>\n</form>\n<button id=\"other\">\n Trigger the handler\n</button>\n<script src=\"/resources/events.js\"></script>",
"css": "fieldset {\n margin-bottom: 1em;\n }\n input {\n display: block;\n margin-bottom: .25em;\n }\n #print-output {\n width: 100%;\n }\n .print-output-line {\n white-space: pre;\n padding: 5px;\n font-family: monaco, monospace;\n font-size: .7em;\n }"
}],
"categories": [
"events/keyboard-events",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ".keyup()",
"type": "method",
"name": "keyup",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"keyup\" JavaScript event, or trigger that event on an element.",
"longdesc": "<p>This method is a shortcut for <code>.on( \"keyup\", handler )</code> in the first two variations, and <code>.trigger( \"keyup\" )</code> in the third.</p>\n <p>The <code>keyup</code> event is sent to an element when the user releases a key on the keyboard. It can be attached to any element, but the event is only sent to the element that has the focus. Focusable elements can vary between browsers, but form elements can always get focus so are reasonable candidates for this event type.</p>\n <p>For example, consider the HTML:</p>\n <pre><code>\n&lt;form&gt;\n &lt;input id=\"target\" type=\"text\" value=\"Hello there\"&gt;\n&lt;/form&gt;\n&lt;div id=\"other\"&gt;\n Trigger the handler\n&lt;/div&gt;\n </code></pre>\n <p>The event handler can be bound to the input field:</p>\n <pre><code>\n$( \"#target\" ).keyup(function() {\n alert( \"Handler for .keyup() called.\" );\n});\n </code></pre>\n <p>Now when the insertion point is inside the field and a key is pressed and released, the alert is displayed:</p>\n <p>\n <samp>Handler for .keyup() called.</samp>\n </p>\n <p>To trigger the event manually, apply <code>.keyup()</code> without arguments:</p>\n <pre><code>\n$( \"#other\" ).click(function() {\n $( \"#target\" ).keyup();\n});\n </code></pre>\n <p>After this code executes, clicks on <samp>Trigger the handler</samp> will also alert the message.</p>\n <p>If key presses anywhere need to be caught (for example, to implement global shortcut keys on a page), it is useful to attach this behavior to the <code>document</code> object. Because of event bubbling, all key presses will make their way up the DOM to the <code>document</code> object unless explicitly stopped.</p>\n <p>To determine which key was pressed, examine the event object that is passed to the handler function. While browsers use differing properties to store this information, jQuery normalizes the <code>.which</code> property so you can reliably use it to retrieve the key code. This code corresponds to a key on the keyboard, including codes for special keys such as arrows. For catching actual text entry, <code>.keypress()</code> may be a better choice.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.keyup()</code> method is just a shorthand for <code>.on( \"keyup\", handler )</code>, detaching is possible using <code>.off( \"keyup\" )</code>."
}],
"examples": [{
"desc": "Show the event object for the keyup handler (using a simple $.print plugin) when a key is released in the input.",
"code": "var xTriggered = 0;\n$( \"#target\" ).keyup(function( event ) {\n xTriggered++;\n var msg = \"Handler for .keyup() called \" + xTriggered + \" time(s).\";\n $.print( msg, \"html\" );\n $.print( event );\n}).keydown(function( event ) {\n if ( event.which == 13 ) {\n event.preventDefault();\n }\n});\n\n$( \"#other\").click(function() {\n $( \"#target\" ).keyup();\n});",
"html": "<form>\n <fieldset>\n <label for=\"target\">Type Something:</label>\n <input id=\"target\" type=\"text\">\n </fieldset>\n</form>\n<button id=\"other\">\n Trigger the handler\n</button>\n<script type=\"text/javascript\" src=\"/resources/events.js\"></script>",
"css": "fieldset {\n margin-bottom: 1em;\n }\n input {\n display: block;\n margin-bottom: .25em;\n }\n #print-output {\n width: 100%;\n }\n .print-output-line {\n white-space: pre;\n padding: 5px;\n font-family: monaco, monospace;\n font-size: .7em;\n }"
}],
"categories": [
"events/keyboard-events",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ":lang() Selector",
"type": "selector",
"name": "lang",
"return": "",
"signatures": [{
"arguments": [{
"name": "language",
"type": "String",
"desc": "A language code."
}],
"added": "1.9"
}],
"desc": "Selects all elements of the specified language.",
"longdesc": "<p>The <code>:lang()</code> selector matches elements that have a language value equal to the supplied language code or that start with the supplied language code immediately followed by \"-\". For example, the selector <code>$(\"div:lang(en)\")</code>will match <code>&lt;div lang=\"en\"&gt;</code> and <code>&lt;div lang=\"en-us\"&gt;</code> (and any of their descendant <code>&lt;div&gt;</code>s), but not <code>&lt;div lang=\"fr\"&gt;</code></p>\n <p>For HTML elements, the language value is determined by the <code>lang</code> attribute and possibly information from <code>meta</code> elements or HTTP headers.</p>\n <p>Further discussion of this usage can be found in the <a href=\"https://www.w3.org/TR/css3-selectors/#lang-pseudo\">W3C CSS specification</a>.</p>",
"examples": [{
"desc": "Color div elements according to their language.",
"code": "$( \"div:lang(en-us)\" ).addClass( \"usa\" );\n$( \"div:lang(es-es)\" ).addClass( \"spain\" );",
"html": "<h3>USA</h3>\n<div lang=\"en-us\">red\n <div>white\n <div>and blue</div>\n </div>\n</div>\n<h3>España</h3>\n<div lang=\"es-es\">rojo\n <div>amarillo\n <div>y rojo</div>\n </div>\n</div>",
"css": "body {\n background-color: #ccc;\n }\n h3 {\n margin: .25em 0;\n }\n div {\n line-height: 1.5em\n }\n .usa {\n background-color: #f00;\n color: #fff;\n }\n .usa .usa {\n background-color: #fff;\n color: #000;\n }\n .usa .usa .usa {\n background-color: #00f;\n color: #fff;\n }\n .spain {\n background-color: #f00;\n color: #ff0;\n }\n .spain .spain {\n background-color: #ff0;\n color: #f00;\n line-height: 3em;\n }\n .spain .spain .spain {\n background-color: #f00;\n color: #ff0;\n line-height: 1.5em;\n }"
}],
"categories": [
"selectors/basic-filter-selectors",
"version/1.9"
]
},
{
"title": ":last-child Selector",
"type": "selector",
"name": "last-child",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.1.4"
}],
"desc": "Selects all elements that are the last child of their parent.",
"longdesc": "<p>While <a href=\"/last/\"><code>.last()</code></a> matches only a single element, <code>:last-child</code> can match more than one: one for each parent.</p>",
"examples": [{
"desc": "Find the last span in each matched div and add some css plus a hover state.",
"code": "$( \"div span:last-child\" )\n .css({ color:\"red\", fontSize:\"80%\" })\n .hover(function() {\n $( this ).addClass( \"solast\" );\n }, function() {\n $( this ).removeClass( \"solast\" );\n });",
"html": "<div>\n <span>John,</span>\n <span>Karl,</span>\n <span>Brandon,</span>\n <span>Sam</span>\n</div>\n<div>\n <span>Glen,</span>\n <span>Tane,</span>\n <span>Ralph,</span>\n <span>David</span>\n</div>",
"css": "span.solast {\n text-decoration: line-through;\n }"
}],
"categories": [
"selectors/child-filter-selectors",
"version/1.1.4"
]
},
{
"title": ":last-of-type Selector",
"type": "selector",
"name": "last-of-type",
"return": "",
"signatures": [{
"arguments": [],
"added": "1.9"
}],
"desc": "Selects all elements that are the last among siblings of the same element name.",
"longdesc": "<p>The <code>:last-of-type</code> selector matches elements that have no other element with the same parent and the same element name coming after it in the document tree.</p>",
"examples": [{
"desc": "Find the last span in each matched div and add some css plus a hover state.",
"code": "$( \"span:last-of-type\" )\n .css({ color:\"red\", fontSize:\"80%\" })\n .hover(function() {\n $( this ).addClass( \"solast\" );\n }, function() {\n $( this ).removeClass( \"solast\" );\n });",
"html": "<div>\n <span>Corey,</span>\n <span>Yehuda,</span>\n <span>Adam,</span>\n <span>Todd</span>\n</div>\n<div>\n <span>Jörn,</span>\n <span>Scott,</span>\n <span>Timo,</span>\n <b>Nobody</b>\n</div>",
"css": "span.solast {\n text-decoration: line-through;\n }"
}],
"categories": [
"selectors/child-filter-selectors",
"version/1.9"
]
},
{
"title": ":last Selector",
"type": "selector",
"name": "last",
"return": "",
"deprecated": "3.4",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "Selects the last matched element.",
"longdesc": "<p><strong>As of jQuery 3.4</strong>, the <code>:last</code> pseudo-class is deprecated. Remove it from your selectors and filter the results later using <a href=\"/last/\"><code>.last()</code></a>.</p>\n <p>Note that <code>:last</code> selects a single element by filtering the current jQuery collection and matching the last element within it.</p>",
"note": [{
"type": "additional",
"text": "Because <code>:last</code> is a jQuery extension and not part of the CSS specification, queries using <code>:last</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>undefined</code> instead."
}],
"examples": [{
"desc": "Finds the last table row.",
"code": "$( \"tr\" ).last().css({ backgroundColor: \"yellow\", fontWeight: \"bolder\" });",
"html": "<table>\n <tr><td>First Row</td></tr>\n <tr><td>Middle Row</td></tr>\n <tr><td>Last Row</td></tr>\n</table>",
"css": ""
}],
"categories": [
"selectors/basic-filter-selectors",
"selectors/jquery-selector-extensions",
"version/1.0",
"deprecated/deprecated-3.4"
]
},
{
"title": ".last()",
"type": "method",
"name": "last",
"return": "jQuery",
"signatures": [{
"arguments": [],
"added": "1.4"
}],
"desc": "Reduce the set of matched elements to the final one in the set.",
"longdesc": "<p>Given a jQuery object that represents a set of DOM elements, the <code>.last()</code> method constructs a new jQuery object from the last element in that set.</p>\n <p>Consider a page with a simple list on it:</p>\n <pre><code>\n&lt;ul&gt;\n &lt;li&gt;list item 1&lt;/li&gt;\n &lt;li&gt;list item 2&lt;/li&gt;\n &lt;li&gt;list item 3&lt;/li&gt;\n &lt;li&gt;list item 4&lt;/li&gt;\n &lt;li&gt;list item 5&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>We can apply this method to the set of list items:</p>\n <pre><code>\n$( \"li\" ).last().css( \"background-color\", \"red\" );\n </code></pre>\n <p>The result of this call is a red background for the final item.</p>",
"examples": [{
"desc": "Highlight the last span in a paragraph.",
"code": "$( \"p span\" ).last().addClass( \"highlight\" );",
"html": "<p><span>Look:</span> <span>This is some text in a paragraph.</span> <span>This is a note about it.</span></p>",
"css": ".highlight {\n background-color: yellow;\n }"
}],
"categories": [
"traversing/filtering",
"version/1.4"
]
},
{
"title": ".length",
"type": "property",
"name": "length",
"return": "Integer",
"signatures": [{
"arguments": [],
"added": "1.0"
}],
"desc": "The number of elements in the jQuery object.",
"longdesc": "<p>The number of elements currently matched. The .<a href=\"/size/\">size()</a> method will return the same value.</p>",
"examples": [{
"desc": "Count the divs. Click to add more.",
"code": "$( document.body )\n .click(function() {\n $( document.body ).append( $( \"<div>\" ) );\n var n = $( \"div\" ).length;\n $( \"span\" ).text( \"There are \" + n + \" divs.\" +\n \"Click to add more.\");\n })\n // Trigger the click to start\n .trigger( \"click\" );",
"html": "<span></span>\n <div></div>",
"css": "body {\n cursor: pointer;\n }\n div {\n width: 50px;\n height: 30px;\n margin: 5px;\n float: left;\n background: green;\n }\n span {\n color: red;\n }"
}],
"categories": [
"properties/jquery-object-instance-properties",
"version/1.0"
]
},
{
"title": ".live()",
"type": "method",
"name": "live",
"return": "jQuery",
"deprecated": "1.7",
"removed": "1.9",
"signatures": [{
"arguments": [{
"name": "events",
"type": "String",
"desc": "A string containing a JavaScript event type, such as \"click\" or \"keydown.\" As of jQuery 1.4 the string can contain multiple, space-separated event types or custom event names."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute at the time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.3"
},
{
"arguments": [{
"name": "events",
"type": "String",
"desc": "A string containing a JavaScript event type, such as \"click\" or \"keydown.\" As of jQuery 1.4 the string can contain multiple, space-separated event types or custom event names."
},
{
"name": "data",
"type": "PlainObject",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute at the time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4"
},
{
"arguments": [{
"name": "events",
"type": "PlainObject",
"desc": "A plain object of one or more JavaScript event types and functions to execute for them."
}],
"added": "1.4.3"
}
],
"desc": "Attach an event handler for all elements which match the current selector, now and in the future.",
"longdesc": "<div class=\"warning\">\n <p>Note: This API has been removed in jQuery 1.9; please use <a href=\"/on/\"><code>on()</code></a> instead.</p>\n </div>\n <p>This method provides a means to attach delegated event handlers to the <code>document</code> element of a page, which simplifies the use of event handlers when content is dynamically added to a page. See the discussion of direct versus delegated events in the <a href=\"/on/\"><code>.on()</code></a> method for more information. </p>\n <p>Rewriting the <code>.live()</code> method in terms of its successors is straightforward; these are templates for equivalent calls for all three event attachment methods:</p>\n <pre><code>\n$( selector ).live( events, data, handler ); // jQuery 1.3+\n$( document ).delegate( selector, events, data, handler ); // jQuery 1.4.3+\n$( document ).on( events, selector, data, handler ); // jQuery 1.7+\n </code></pre>\n <p>The <code>events</code> argument can either be a space-separated list of event type names and optional namespaces, or an object of event name strings and handlers. The <code>data</code> argument is optional and can be omitted. For example, the following three method calls are functionally equivalent (but see below for more effective and performant ways to attach delegated event handlers):</p>\n <pre><code>\n$( \"a.offsite\" ).live( \"click\", function() {\n alert( \"Goodbye!\" ); // jQuery 1.3+\n});\n$( document ).delegate( \"a.offsite\", \"click\", function() {\n alert( \"Goodbye!\" ); // jQuery 1.4.3+\n});\n$( document ).on( \"click\", \"a.offsite\", function() {\n alert( \"Goodbye!\" ); // jQuery 1.7+\n});\n </code></pre>\n <p>Use of the <code>.live()</code> method is no longer recommended since later versions of jQuery offer better methods that do not have its drawbacks. In particular, the following issues arise with the use of <code>.live()</code>:</p>\n <ul>\n <li>jQuery attempts to retrieve the elements specified by the selector before calling the <code>.live()</code> method, which may be time-consuming on large documents.</li>\n <li>Chaining methods is not supported. For example, <code>$( \"a\" ).find( \".offsite, .external\" ).live( ... ); </code> is <em>not</em> valid and does not work as expected.</li>\n <li>Since all <code>.live()</code> events are attached at the <code>document</code> element, events take the longest and slowest possible path before they are handled.</li>\n <li>On mobile iOS (iPhone, iPad and iPod Touch) the <code>click</code> event does not bubble to the document body for most elements and cannot be used with <code>.live()</code> without applying one of the following workarounds:\n <ol>\n <li>Use natively clickable elements such as <code>a</code> or <code>button</code>, as both of these do bubble to <code>document</code>.</li>\n <li>Use <code>.on()</code> or <code>.delegate()</code> attached to an element below the level of <code>document.body</code>, since mobile iOS does bubble within the body.</li>\n <li>Apply the CSS style <code>cursor:pointer</code> to the element that needs to bubble clicks (or a parent including <code>document.documentElement</code>). Note however, this will disable copy\\paste on the element and cause it to be highlighted when touched.</li>\n </ol>\n </li>\n <li>Calling <a href=\"/event.stopPropagation/\"><code>event.stopPropagation()</code></a> in the event handler is ineffective in stopping event handlers attached lower in the document; the event has already propagated to <code>document</code>.</li>\n <li>The <code>.live()</code> method interacts with other event methods in ways that can be surprising, e.g., <code>$( document ).off( \"click\" )</code> removes all click handlers attached by any call to <code>.live()</code>!</li>\n </ul>\n <p>For pages still using <code>.live()</code>, this list of version-specific differences may be helpful:</p>\n <ul>\n <li>Before jQuery 1.7, to stop further handlers from executing after one bound using <code>.live()</code>, the handler must return <code>false</code>. Calling <code>.stopPropagation()</code> will not accomplish this.</li>\n <li>As of <b>jQuery 1.4</b> the <code>.live()</code> method supports custom events as well as <em>all JavaScript events that bubble</em>. It also supports certain events that don't bubble, including <code>change</code>, <code>submit</code>, <code>focus</code> and <code>blur</code>.</li>\n <li>In <b>jQuery 1.3.x</b> only the following JavaScript events could be bound: <code>click</code>, <code>dblclick</code>, <code>keydown</code>, <code>keypress</code>, <code>keyup</code>, <code>mousedown</code>, <code>mousemove</code>, <code>mouseout</code>, <code>mouseover</code>, and <code>mouseup</code>.</li>\n </ul>",
"examples": [{
"desc": "Cancel a default action and prevent it from bubbling up by returning false.",
"code": "$( \"a\" ).live( \"click\", function() {\n return false;\n});",
"html": "",
"css": ""
},
{
"desc": "Cancel only the default action by using the preventDefault method.",
"code": "$( \"a\" ).live( \"click\", function( event ) {\n event.preventDefault();\n});",
"html": "",
"css": ""
},
{
"desc": "Bind custom events with .live().",
"code": "$( \"p\" ).live( \"myCustomEvent\", function( event, myName, myValue ) {\n $( this ).text( \"Hi there!\" );\n $( \"span\" )\n .stop()\n .css( \"opacity\", 1 )\n .text( \"myName = \" + myName )\n .fadeIn( 30 )\n .fadeOut( 1000 );\n });\n$( \"button\" ).click(function() {\n $( \"p\" ).trigger( \"myCustomEvent\" );\n});",
"html": "",
"css": ""
},
{
"desc": "Use an object to bind multiple live event handlers. Note that .live() calls the click, mouseover, and mouseout event handlers for all paragraphs--even new ones.",
"code": "$( \"p\" ).live({\n click: function() {\n $( this ).after( \"<p>Another paragraph!</p>\" );\n },\n mouseover: function() {\n $( this ).addClass( \"over\" );\n },\n mouseout: function() {\n $( this ).removeClass( \"over\" );\n }\n});",
"html": "",
"css": ""
}
],
"categories": [
"events/event-handler-attachment",
"version/1.3",
"deprecated/deprecated-1.7",
"removed"
]
},
{
"title": ".load()",
"type": "method",
"name": "load",
"return": "jQuery",
"deprecated": "1.8",
"removed": "3.0",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute when the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
}
],
"desc": "Bind an event handler to the \"load\" JavaScript event.",
"longdesc": "<div class=\"warning\">\n <p>Note: This API has been removed in jQuery 3.0; please use <code>.on( \"load\", handler )</code> instead of <code>.load( handler )</code> and <code>.trigger( \"load\" )</code> instead of <code>.load()</code>.</p>\n </div>\n <p>This method is a shortcut for <code>.on( \"load\", handler )</code>.</p>\n <p>The <code>load</code> event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the <code>window</code> object.</p>\n <p>For example, consider a page with a simple image:</p>\n <pre><code>\n&lt;img src=\"book.png\" alt=\"Book\" id=\"book\"&gt;\n </code></pre>\n <p>The event handler can be bound to the image:</p>\n <pre><code>\n$( \"#book\" ).load(function() {\n // Handler for .load() called.\n});\n </code></pre>\n <p>As soon as the image has been loaded, the handler is called.</p>\n <p>In general, it is not necessary to wait for all images to be fully loaded. If code can be executed earlier, it is usually best to place it in a handler sent to the <code>.ready()</code> method.\n </p>\n <div class=\"warning\">\n <p>The Ajax module also has a method named <code><a href=\"/load/\">.load()</a></code>. Which one is fired depends on the set of arguments passed.</p>\n </div>\n <div class=\"warning\">\n <p>\n <b>Caveats of the <code>load</code> event when used with images</b>\n <p>A common challenge developers attempt to solve using the <code>.load()</code> shortcut is to execute a function when an image (or collection of images) have completely loaded. There are several known caveats with this that should be noted. These are:</p>\n <ul>\n <li>It doesn't work consistently nor reliably cross-browser</li>\n <li>It doesn't fire correctly in WebKit if the image src is set to the same src as before</li>\n <li>It doesn't correctly bubble up the DOM tree</li>\n <li>Can cease to fire for images that already live in the browser's cache</li>\n </ul>\n </p>\n </div>\n <div class=\"warning\">\n <p><strong>Note:</strong> The <code>.live()</code> and <code>.delegate()</code> methods cannot be used to detect the <code>load</code> event of an iframe. The load event does not correctly bubble up the parent document and the event.target isn't set by Firefox, IE9 or Chrome, which is required to do event delegation.</p>\n </div>",
"examples": [{
"desc": "Run a function when the page is fully loaded including graphics.",
"code": "$( window ).load(function() {\n // Run code\n});",
"html": "",
"css": ""
},
{
"desc": "Add the class bigImg to all images with height greater than 100 upon each image load.",
"code": "$( \"img.userIcon\" ).load(function() {\n if ( $( this ).height() > 100) {\n $( this ).addClass( \"bigImg\" );\n }\n});",
"html": "",
"css": ""
}
],
"categories": [
"events/document-loading",
"version/1.0",
"version/1.4.3",
"deprecated/deprecated-1.8",
"removed"
]
},
{
"title": ".load()",
"type": "method",
"name": "load",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "url",
"type": "String",
"desc": "A string containing the URL to which the request is sent."
},
{
"name": "data",
"optional": "true",
"type": [
"PlainObject",
"String"
],
"desc": "A plain object or string that is sent to the server with the request."
},
{
"name": "complete",
"type": "Function",
"optional": "true",
"desc": "A callback function that is executed when the request completes.",
"arguments": [{
"name": "responseText",
"type": "String"
},
{
"name": "textStatus",
"type": "String"
},
{
"name": "jqXHR",
"type": "jqXHR"
}
]
}
],
"added": "1.0"
}],
"desc": "Load data from the server and place the returned HTML into the matched elements.",
"longdesc": "<div class=\"warning\">\n <p>Note: Prior to jQuery 3.0, the event handling suite also had a method named <code><a href=\"/load-event/\">.load()</a></code>. Older versions of jQuery determined which method to fire based on the set of arguments passed to it.</p>\n </div>\n <p>This method is the simplest way to fetch data from the server. It is roughly equivalent to <code>$.get(url, data, success)</code> except that it is a method rather than global function and it has an implicit callback function. When a successful response is detected (i.e. when <code>textStatus</code> is \"success\" or \"notmodified\"), <code>.load()</code> sets the HTML contents of the matched elements to the returned data. This means that most uses of the method can be quite simple:</p>\n <pre><code>\n$( \"#result\" ).load( \"ajax/test.html\" );\n </code></pre>\n <p>If no element is matched by the selector — in this case, if the document does not contain an element with id=\"result\" — the Ajax request will <em>not</em> be sent.</p>\n <h4 id=\"callback-function\">Callback Function</h4>\n <p>If a \"complete\" callback is provided, it is executed after post-processing and HTML insertion has been performed. The callback is fired once for each element in the jQuery collection, and <code>this</code> is set to each DOM element in turn.</p>\n <pre><code>\n$( \"#result\" ).load( \"ajax/test.html\", function() {\n alert( \"Load was performed.\" );\n});\n </code></pre>\n <p>In the two examples above, if the current document does not contain an element with an ID of \"result,\" the <code>.load()</code> method is not executed.</p>\n <h4 id=\"request-method\">Request Method</h4>\n <p>The POST method is used if data is provided as an object; otherwise, GET is assumed.</p>\n <h4 id=\"loading-page-fragments\">Loading Page Fragments</h4>\n <p>The <code>.load()</code> method, unlike <code><a href=\"/jQuery.get/\">$.get()</a></code>, allows us to specify a portion of the remote document to be inserted. This is achieved with a special syntax for the <code>url</code> parameter. If one or more space characters are included in the string, the portion of the string following the first space is assumed to be a jQuery selector that determines the content to be loaded. </p>\n <p>We could modify the example above to use only part of the document that is fetched:</p>\n <pre><code>\n$( \"#result\" ).load( \"ajax/test.html #container\" );\n </code></pre>\n <p>When this method executes, it retrieves the content of <code>ajax/test.html</code>, but then jQuery parses the returned document to find the element with an ID of <code>container</code>. This element, along with its contents, is inserted into the element with an ID of <code>result</code>, and the rest of the retrieved document is discarded.</p>\n <p>jQuery uses the browser's <code>.innerHTML</code> property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as <code>&lt;html&gt;</code>, <code>&lt;title&gt;</code>, or <code>&lt;head&gt;</code> elements. As a result, the elements retrieved by <code>.load()</code> may not be exactly the same as if the document were retrieved directly by the browser.</p>\n <h4 id=\"script-execution\">Script Execution</h4>\n <p> When calling <code>.load()</code> using a URL without a suffixed selector expression, the content is passed to <code>.html()</code> prior to scripts being removed. This executes the script blocks before they are discarded. If <code>.load()</code> is called with a selector expression appended to the URL, however, the scripts are stripped out prior to the DOM being updated, and thus are <em>not</em> executed. An example of both cases can be seen below:</p>\n <p>Here, any JavaScript loaded into <code>#a</code> as a part of the document will successfully execute.</p>\n <pre><code>\n$( \"#a\" ).load( \"article.html\" );\n </code></pre>\n <p>However, in the following case, script blocks in the document being loaded into <code>#b</code> are stripped out and not executed:</p>\n <pre><code>\n$( \"#b\" ).load( \"article.html #target\" );\n </code></pre>",
"note": [{
"type": "additional",
"text": "Script and JSONP requests are not subject to the same origin policy restrictions."
}],
"examples": [{
"desc": "Load another page's list items into an ordered list.",
"code": "$( \"#new-projects\" ).load( \"/resources/load.html #projects li\" );",
"html": "<b>Projects:</b>\n<ol id=\"new-projects\"></ol>",
"css": "body {\n font-size: 12px;\n font-family: Arial;\n }"
},
{
"desc": "Display a notice if the Ajax request encounters an error.",
"code": "$( \"#success\" ).load( \"/not-here.php\", function( response, status, xhr ) {\n if ( status == \"error\" ) {\n var msg = \"Sorry but there was an error: \";\n $( \"#error\" ).html( msg + xhr.status + \" \" + xhr.statusText );\n }\n});",
"html": "<b>Successful Response (should be blank):</b>\n<div id=\"success\"></div>\n<b>Error Response:</b>\n<div id=\"error\"></div>",
"css": "body {\n font-size: 12px;\n font-family: Arial;\n }"
},
{
"desc": "Load the feeds.html file into the div with the ID of feeds.",
"code": "$( \"#feeds\" ).load( \"feeds.html\" );",
"html": "",
"css": ""
},
{
"desc": "pass arrays of data to the server.",
"code": "$( \"#objectID\" ).load( \"test.php\", { \"choices[]\": [ \"Jon\", \"Susan\" ] } );",
"html": "",
"css": ""
},
{
"desc": "Same as above, but will POST the additional parameters to the server and a callback that is executed when the server is finished responding.",
"code": "$( \"#feeds\" ).load( \"feeds.php\", { limit: 25 }, function() {\n alert( \"The last 25 entries in the feed have been loaded\" );\n});",
"html": "",
"css": ""
}
],
"categories": [
"ajax/shorthand-methods",
"version/1.0"
]
},
{
"title": ":lt() Selector",
"type": "selector",
"name": "lt",
"return": "",
"deprecated": "3.4",
"signatures": [{
"arguments": [{
"name": "index",
"type": "Number",
"desc": "Zero-based index."
}],
"added": "1.0"
},
{
"arguments": [{
"name": "indexFromEnd",
"type": "Integer",
"desc": "Zero-based index, counting backwards from the last element."
}],
"added": "1.8"
}
],
"desc": "Select all elements at an index less than <code>index</code> within the matched set.",
"longdesc": "<p><strong>As of jQuery 3.4</strong>, the <code>:lt</code> pseudo-class is deprecated. Remove it from your selectors and filter the results later using <a href=\"/slice/\"><code>.slice()</code></a>. For example, <code>:lt(3)</code> can be replaced with a call to <code>.slice( 0, 3 )</code>.</p>\n <p>\n <strong>index-related selectors</strong>\n </p>\n <p>The index-related selectors (including this \"less than\" selector) filter the set of elements that have matched the expressions that precede them. They narrow the set down based on the order of the elements within this matched set. For example, if elements are first selected with a class selector (<code>.myclass</code>) and four elements are returned, these elements are given indices 0 through 3 for the purposes of these selectors.</p>\n <p>Note that since JavaScript arrays use <em>0-based indexing</em>, these selectors reflect that fact. This is why <code>$( \".myclass:lt(1)\" )</code> selects the first element in the document with the class <code>myclass</code>, rather than selecting no elements. In contrast, <code>:nth-child(n)</code> uses <em>1-based indexing</em> to conform to the CSS specification.</p>\n <p>Prior to jQuery 1.8, the <code>:lt(index)</code> selector did <em>not</em> accept a negative value for <code>index</code></p>",
"note": [{
"type": "additional",
"text": "Because <code>:lt()</code> is a jQuery extension and not part of the CSS specification, queries using <code>:lt()</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. For better performance in modern browsers, use <code>$(\"your-pure-css-selector\").slice(0, index)</code> instead."
}],
"examples": [{
"desc": "Give TDs less than the one with the 4th index (TD#4) a yellow background and TDs less than the one with -2nd index a red text color.",
"code": "$( \"td:lt(4)\" ).css( \"backgroundColor\", \"yellow\" );\n$( \"td:lt(-2)\" ).css( \"color\", \"red\" );",
"html": "<table border=\"1\">\n <tr><td>TD #0</td><td>TD #1</td><td>TD #2</td></tr>\n <tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr>\n <tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr>\n</table>",
"css": ""
}],
"categories": [
"selectors/basic-filter-selectors",
"selectors/jquery-selector-extensions",
"version/1.0",
"deprecated/deprecated-3.4"
]
},
{
"title": ".map()",
"type": "method",
"name": "map",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "callback",
"type": "Function",
"desc": "A function object that will be invoked for each element in the current set.",
"arguments": [{
"name": "index",
"type": "Integer"
},
{
"name": "domElement",
"type": "Element"
}
]
}],
"added": "1.2"
}],
"desc": "Pass each element in the current matched set through a function, producing a new jQuery object containing the return values.",
"longdesc": "<p>If you wish to process a plain array or object, use the <a href=\"/jQuery.map/\">jQuery.map()</a> instead. </p>\n <p>As the return value is a jQuery object, which contains an array, it's very common to call <code>.get()</code> on the result to work with a basic array.</p>\n <p>The <code>.map()</code> method is particularly useful for getting or setting the value of a collection of elements. Consider a form with a set of checkboxes in it:</p>\n <pre><code>\n&lt;form method=\"post\" action=\"\"&gt;\n &lt;fieldset&gt;\n &lt;div&gt;\n &lt;label for=\"two\"&gt;2&lt;/label&gt;\n &lt;input type=\"checkbox\" value=\"2\" id=\"two\" name=\"number[]\"&gt;\n &lt;/div&gt;\n &lt;div&gt;\n &lt;label for=\"four\"&gt;4&lt;/label&gt;\n &lt;input type=\"checkbox\" value=\"4\" id=\"four\" name=\"number[]\"&gt;\n &lt;/div&gt;\n &lt;div&gt;\n &lt;label for=\"six\"&gt;6&lt;/label&gt;\n &lt;input type=\"checkbox\" value=\"6\" id=\"six\" name=\"number[]\"&gt;\n &lt;/div&gt;\n &lt;div&gt;\n &lt;label for=\"eight\"&gt;8&lt;/label&gt;\n &lt;input type=\"checkbox\" value=\"8\" id=\"eight\" name=\"number[]\"&gt;\n &lt;/div&gt;\n &lt;/fieldset&gt;\n&lt;/form&gt;\n </code></pre>\n <p>To get a comma-separated list of checkbox <code>ID</code>s:</p>\n <pre><code>\n$( \":checkbox\" )\n .map(function() {\n return this.id;\n })\n .get()\n .join();\n </code></pre>\n <p>The result of this call is the string, <code>\"two,four,six,eight\"</code>.</p>\n <p>Within the callback function, <code>this</code> refers to the current DOM element for each iteration. The function can return an individual data item or an array of data items to be inserted into the resulting set. If an array is returned, the elements inside the array are inserted into the set. If the function returns <code>null</code> or <code>undefined</code>, no element will be inserted.</p>",
"examples": [{
"desc": "Build a list of all the values within a form.",
"code": "$( \"p\" )\n .append( $( \"input\" ).map(function() {\n return $( this ).val();\n })\n .get()\n .join( \", \" ) );",
"html": "<p><b>Values: </b></p>\n<form>\n <input type=\"text\" name=\"name\" value=\"John\">\n <input type=\"text\" name=\"password\" value=\"password\">\n <input type=\"text\" name=\"url\" value=\"https://johnresig.com/\">\n</form>",
"css": "p {\n color: red;\n }"
},
{
"desc": "A contrived example to show some functionality.",
"code": "var mappedItems = $( \"li\" ).map(function( index ) {\n var replacement = $( \"<li>\" ).text( $( this ).text() ).get( 0 );\n if ( index === 0 ) {\n\n // Make the first item all caps\n $( replacement ).text( $( replacement ).text().toUpperCase() );\n } else if ( index === 1 || index === 3 ) {\n\n // Delete the second and fourth items\n replacement = null;\n } else if ( index === 2 ) {\n\n // Make two of the third item and add some text\n replacement = [ replacement, $( \"<li>\" ).get( 0 ) ];\n $( replacement[ 0 ] ).append( \"<b> - A</b>\" );\n $( replacement[ 1 ] ).append( \"Extra <b> - B</b>\" );\n }\n\n // Replacement will be a dom element, null,\n // or an array of dom elements\n return replacement;\n});\n$( \"#results\" ).append( mappedItems );",
"html": "<ul>\n <li>First</li>\n <li>Second</li>\n <li>Third</li>\n <li>Fourth</li>\n <li>Fifth</li>\n</ul>\n<ul id=\"results\">\n</ul>",
"css": "body {\n font-size: 16px;\n }\n ul {\n float: left;\n margin: 0 30px;\n color: blue;\n }\n #results {\n color: red;\n }"
},
{
"desc": "Equalize the heights of the divs.",
"code": "$.fn.equalizeHeights = function() {\n var maxHeight = this.map(function( i, e ) {\n return $( e ).height();\n }).get();\n return this.height( Math.max.apply( this, maxHeight ) );\n};\n\n$( \"input\" ).click(function() {\n $( \"div\" ).equalizeHeights();\n});",
"html": "<input type=\"button\" value=\"equalize div heights\">\n<div style=\"background: red; height: 40px; \"></div>\n<div style=\"background: green; height: 70px;\"></div>\n<div style=\"background: blue; height: 50px; \"></div>",
"css": "div {\n width: 40px;\n float: left;\n }\n input {\n clear: left;\n }"
}
],
"categories": [
"traversing/filtering",
"version/1.2"
]
},
{
"title": ".mousedown()",
"type": "method",
"name": "mousedown",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"mousedown\" JavaScript event, or trigger that event on an element.",
"longdesc": "<p>This method is a shortcut for <code>.on( \"mousedown\", handler)</code> in the first variation, and <code>.trigger( \"mousedown\" )</code> in the second.</p>\n <p>The <code>mousedown</code> event is sent to an element when the mouse pointer is over the element, and the mouse button is pressed. Any HTML element can receive this event.</p>\n <p>For example, consider the HTML:</p>\n <pre><code>&lt;div id=\"target\"&gt;\n Click here\n&lt;/div&gt;\n&lt;div id=\"other\"&gt;\n Trigger the handler\n&lt;/div&gt;\n </code></pre>\n <figure>\n <img src=\"/resources/0042_05_01.png\" alt=\"\"/>\n <figcaption>Figure 1 - Illustration of the rendered HTML</figcaption>\n </figure>\n <p>The event handler can be bound to any <code>&lt;div&gt;</code>:</p>\n <pre><code>\n$( \"#target\" ).mousedown(function() {\n alert( \"Handler for .mousedown() called.\" );\n});\n </code></pre>\n <p>Now if we click on this element, the alert is displayed:</p>\n <p>\n <samp>Handler for .mousedown() called.</samp>\n </p>\n <p>We can also trigger the event when a different element is clicked:</p>\n <pre><code>\n$( \"#other\" ).click(function() {\n $( \"#target\" ).mousedown();\n});\n </code></pre>\n <p>After this code executes, clicks on <samp>Trigger the handler</samp> will also alert the message.</p>\n <p>The <code>mousedown</code> event is sent when any mouse button is clicked. To act only on specific buttons, we can use the event object's <code>which</code> property. Not all browsers support this property (Internet Explorer uses button instead), but jQuery normalizes the property so that it is safe to use in any browser. The value of <code>which</code> will be 1 for the left button, 2 for the middle button, or 3 for the right button.</p>\n <p>This event is primarily useful for ensuring that the primary button was used to begin a drag operation; if ignored, strange results can occur when the user attempts to use a context menu. While the middle and right buttons can be detected with these properties, this is not reliable. In Opera and Safari, for example, right mouse button clicks are not detectable by default.</p>\n <p>If the user clicks on an element, drags away from it, and releases the button, this is still counted as a <code>mousedown</code> event. This sequence of actions is treated as a \"canceling\" of the button press in most user interfaces, so it is usually better to use the <code>click</code> event unless we know that the <code>mousedown</code> event is preferable for a particular situation.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.mousedown()</code> method is just a shorthand for <code>.on( \"mousedown\", handler )</code>, detaching is possible using <code>.off( \"mousedown\" )</code>."
}],
"examples": [{
"desc": "Show texts when mouseup and mousedown event triggering.",
"code": "$( \"p\" )\n .mouseup(function() {\n $( this ).append( \"<span style='color:#f00;'>Mouse up.</span>\" );\n })\n .mousedown(function() {\n $( this ).append( \"<span style='color:#00f;'>Mouse down.</span>\" );\n });",
"html": "<p>Press mouse and release here.</p>",
"css": ""
}],
"categories": [
"events/mouse-events",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ".mouseenter()",
"type": "method",
"name": "mouseenter",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element.",
"longdesc": "<p>This method is a shortcut for <code>.on( \"mouseenter\", handler )</code> in the first two variations, and <code>.trigger( \"mouseenter\" )</code> in the third.</p>\n <p>The <code>mouseenter</code> JavaScript event is proprietary to Internet Explorer. Because of the event's general utility, jQuery simulates this event so that it can be used regardless of browser. This event is sent to an element when the mouse pointer enters the element. Any HTML element can receive this event.</p>\n <p>For example, consider the HTML:</p>\n <pre><code>\n&lt;div id=\"outer\"&gt;\n Outer\n &lt;div id=\"inner\"&gt;\n Inner\n &lt;/div&gt;\n&lt;/div&gt;\n&lt;div id=\"other\"&gt;\n Trigger the handler\n&lt;/div&gt;\n&lt;div id=\"log\"&gt;&lt;/div&gt;</code></pre>\n <figure>\n <img src=\"/resources/0042_05_08.png\" alt=\"\"/>\n <figcaption>Figure 1 - Illustration of the rendered HTML</figcaption>\n </figure>\n <p>The event handler can be bound to any element:</p>\n <pre><code>\n$( \"#outer\" ).mouseenter(function() {\n $( \"#log\" ).append( \"&lt;div&gt;Handler for .mouseenter() called.&lt;/div&gt;\" );\n});\n </code></pre>\n <p>Now when the mouse pointer moves over the <samp>Outer</samp> <code>&lt;div&gt;</code>, the message is appended to <code>&lt;div id=\"log\"&gt;</code>. You can also trigger the event when another element is clicked:</p>\n <pre><code>\n$( \"#other\" ).click(function() {\n $( \"#outer\" ).mouseenter();\n});\n </code></pre>\n <p>After this code executes, clicks on <samp>Trigger the handler</samp> will also append the message.</p>\n <p>The <code>mouseenter</code> event differs from <code>mouseover</code> in the way it handles event bubbling. If <code>mouseover</code> were used in this example, then when the mouse pointer moved over the <samp>Inner</samp> element, the handler would be triggered. This is usually undesirable behavior. The <code>mouseenter</code> event, on the other hand, only triggers its handler when the mouse enters the element it is bound to, not a descendant. So in this example, the handler is triggered when the mouse enters the <samp>Outer</samp> element, but not the <samp>Inner</samp> element.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.mouseenter()</code> method is just a shorthand for <code>.on( \"mouseenter\", handler )</code>, detaching is possible using <code>.off( \"mouseenter\" )</code>."
}],
"examples": [{
"desc": "Show texts when mouseenter and mouseout event triggering.\n <code>mouseover</code> fires when the pointer moves into the child element as well, while <code>mouseenter</code> fires only when the pointer moves into the bound element.",
"code": "var i = 0;\n$( \"div.overout\" )\n .mouseover(function() {\n $( \"p\", this ).first().text( \"mouse over\" );\n $( \"p\", this ).last().text( ++i );\n })\n .mouseout(function() {\n $( \"p\", this ).first().text( \"mouse out\" );\n });\n\nvar n = 0;\n$( \"div.enterleave\" )\n .mouseenter(function() {\n $( \"p\", this ).first().text( \"mouse enter\" );\n $( \"p\", this ).last().text( ++n );\n })\n .mouseleave(function() {\n $( \"p\", this ).first().text( \"mouse leave\" );\n });",
"html": "<div class=\"out overout\">\n <p>move your mouse</p>\n <div class=\"in overout\"><p>move your mouse</p><p>0</p></div>\n <p>0</p>\n</div>\n\n<div class=\"out enterleave\">\n <p>move your mouse</p>\n <div class=\"in enterleave\"><p>move your mouse</p><p>0</p></div>\n <p>0</p>\n</div>",
"css": "div.out {\n width: 40%;\n height: 120px;\n margin: 0 15px;\n background-color: #d6edfc;\n float: left;\n }\n div.in {\n width: 60%;\n height: 60%;\n background-color: #fc0;\n margin: 10px auto;\n }\n p {\n line-height: 1em;\n margin: 0;\n padding: 0;\n }"
}],
"categories": [
"events/mouse-events",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ".mouseleave()",
"type": "method",
"name": "mouseleave",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element.",
"longdesc": "<p>This method is a shortcut for <code>.on('mouseleave', handler)</code> in the first two variations, and <code>.trigger('mouseleave')</code> in the third.</p>\n <p>The <code>mouseleave</code> JavaScript event is proprietary to Internet Explorer. Because of the event's general utility, jQuery simulates this event so that it can be used regardless of browser. This event is sent to an element when the mouse pointer leaves the element. Any HTML element can receive this event.</p>\n <p>For example, consider the HTML:</p>\n <pre><code>\n&lt;div id=\"outer\"&gt;\n Outer\n &lt;div id=\"inner\"&gt;\n Inner\n &lt;/div&gt;\n&lt;/div&gt;\n&lt;div id=\"other\"&gt;\n Trigger the handler\n&lt;/div&gt;\n&lt;div id=\"log\"&gt;&lt;/div&gt;</code></pre>\n <figure>\n <img src=\"/resources/0042_05_09.png\" alt=\"\"/>\n <figcaption>Figure 1 - Illustration of the rendered HTML</figcaption>\n </figure>\n <p>The event handler can be bound to any element:</p>\n <pre><code>\n$( \"#outer\" ).mouseleave(function() {\n $( \"#log\" ).append( \"&lt;div&gt;Handler for .mouseleave() called.&lt;/div&gt;\" );\n});\n </code></pre>\n <p>Now when the mouse pointer moves out of the <samp>Outer</samp> <code>&lt;div&gt;</code>, the message is appended to <code>&lt;div id=\"log\"&gt;</code>. You can also trigger the event when another element is clicked:</p>\n <pre><code>\n$( \"#other\" ).click(function() {\n $( \"#outer\" ).mouseleave();\n});\n </code></pre>\n <p>After this code executes, clicks on <samp>Trigger the handler</samp> will also append the message.</p>\n <p>The <code>mouseleave</code> event differs from <code>mouseout</code> in the way it handles event bubbling. If <code>mouseout</code> were used in this example, then when the mouse pointer moved out of the <samp>Inner</samp> element, the handler would be triggered. This is usually undesirable behavior. The <code>mouseleave</code> event, on the other hand, only triggers its handler when the mouse leaves the element it is bound to, not a descendant. So in this example, the handler is triggered when the mouse leaves the <samp>Outer</samp> element, but not the <samp>Inner</samp> element.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.mouseleave()</code> method is just a shorthand for <code>.on( \"mouseleave\", handler )</code>, detaching is possible using <code>.off( \"mouseleave\" )</code>."
}],
"examples": [{
"desc": "Show number of times mouseout and mouseleave events are triggered. <code>mouseout</code> fires when the pointer moves out of child element as well, while <code>mouseleave</code> fires only when the pointer moves out of the bound element.",
"code": "var i = 0;\n$( \"div.overout\" )\n .mouseover(function() {\n $( \"p\", this ).first().text( \"mouse over\" );\n })\n .mouseout(function() {\n $( \"p\", this ).first().text( \"mouse out\" );\n $( \"p\", this ).last().text( ++i );\n });\n\nvar n = 0;\n$( \"div.enterleave\" )\n .mouseenter(function() {\n $( \"p\", this ).first().text( \"mouse enter\" );\n })\n .mouseleave(function() {\n $( \"p\", this ).first().text( \"mouse leave\" );\n $( \"p\", this ).last().text( ++n );\n });",
"html": "<div class=\"out overout\">\n <p>move your mouse</p>\n <div class=\"in overout\"><p>move your mouse</p><p>0</p></div>\n <p>0</p>\n</div>\n<div class=\"out enterleave\">\n <p>move your mouse</p>\n <div class=\"in enterleave\"><p>move your mouse</p><p>0</p></div>\n <p>0</p>\n</div>",
"css": "div.out {\n width: 40%;\n height: 120px;\n margin: 0 15px;\n background-color: #d6edfc;\n float: left;\n }\n div.in {\n width: 60%;\n height: 60%;\n background-color: #fc0;\n margin: 10px auto;\n }\n p {\n line-height: 1em;\n margin: 0;\n padding: 0;\n }"
}],
"categories": [
"events/mouse-events",
"version/1.0",
"version/1.4.3"
]
},
{
"title": ".mousemove()",
"type": "method",
"name": "mousemove",
"return": "jQuery",
"signatures": [{
"arguments": [{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}],
"added": "1.0"
},
{
"arguments": [{
"name": "eventData",
"type": "Anything",
"optional": "true",
"desc": "An object containing data that will be passed to the event handler."
},
{
"name": "handler",
"type": "Function",
"desc": "A function to execute each time the event is triggered.",
"arguments": [{
"name": "eventObject",
"type": "Event"
}]
}
],
"added": "1.4.3"
},
{
"arguments": [],
"added": "1.0"
}
],
"desc": "Bind an event handler to the \"mousemove\" JavaScript event, or trigger that event on an element.",
"longdesc": "<p>This method is a shortcut for <code>.on( \"mousemove\", handler )</code> in the first two variations, and <code>.trigger( \"mousemove\" )</code> in the third.</p>\n <p>The <code>mousemove</code> event is sent to an element when the mouse pointer moves inside the element. Any HTML element can receive this event.</p>\n <p>For example, consider the HTML:</p>\n <pre><code>\n&lt;div id=\"target\"&gt;\n Move here\n&lt;/div&gt;\n&lt;div id=\"other\"&gt;\n Trigger the handler\n&lt;/div&gt;\n&lt;div id=\"log\"&gt;&lt;/div&gt;\n </code></pre>\n <p>The event handler can be bound to the target:</p>\n <pre><code>\n$( \"#target\" ).mousemove(function( event ) {\n var msg = \"Handler for .mousemove() called at \";\n msg += event.pageX + \", \" + event.pageY;\n $( \"#log\" ).append( \"&lt;div&gt;\" + msg + \"&lt;/div&gt;\" );\n});\n </code></pre>\n <p>Now when the mouse pointer moves within the target button, the messages are appended to &lt;div id=\"log\"&gt;:</p>\n <p>\n <samp>Handler for .mousemove() called at (399, 48)</samp>\n <br/>\n <samp>Handler for .mousemove() called at (398, 46)</samp>\n <br/>\n <samp>Handler for .mousemove() called at (397, 44)</samp>\n <br/>\n <samp>Handler for .mousemove() called at (396, 42)</samp>\n <br/>\n </p>\n <p>To trigger the event manually, apply <code>.mousemove()</code> without an argument:</p>\n <pre><code>\n$( \"#other\" ).click(function() {\n $( \"#target\" ).mousemove();\n});\n </code></pre>\n <p>After this code executes, clicks on the Trigger button will also append the message:</p>\n <p>\n <samp>Handler for .mousemove() called at (undefined, undefined)</samp>\n </p>\n <p>When tracking mouse movement, you usually need to know the actual position of the mouse pointer. The event object that is passed to the handler contains some information about the mouse coordinates. Properties such as <code>.clientX</code>, <code>.offsetX</code>, and <code>.pageX</code> are available, but support for them differs between browsers. Fortunately, jQuery normalizes the <code>.pageX</code> and <code>.pageY</code> properties so that they can be used in all browsers. These properties provide the X and Y coordinates of the mouse pointer relative to the top-left corner of the document, as illustrated in the example output above.</p>\n <p>Keep in mind that the <code>mousemove</code> event is triggered whenever the mouse pointer moves, even for a pixel. This means that hundreds of events can be generated over a very small amount of time. If the handler has to do any significant processing, or if multiple handlers for the event exist, this can be a serious performance drain on the browser. It is important, therefore, to optimize <code>mousemove </code>handlers as much as possible, and to unbind them as soon as they are no longer needed.</p>\n <p>A common pattern is to bind the <code>mousemove</code> handler from within a <code>mousedown</code> hander, and to unbind it from a corresponding <code>mouseup</code> handler. If implementing this sequence of events, remember that the <code>mouseup</code> event might be sent to a different HTML element than the <code>mousemove</code> event was. To account for this, the <code>mouseup</code> handler should typically be bound to an element high up in the DOM tree, such as <code>&lt;body&gt;</code>.</p>",
"note": [{
"type": "additional",
"text": "As the <code>.mousemove()</code> method is just a shorthand for <code>.on( \"mousemove\", handler )</code>, detaching is possible using <code>.off( \"mousemove\" )</code>."
}],
"examples": [{
"desc": "Show the mouse coordinates when the mouse is moved over the yellow div. Coordinates are relative to the window, which in this case is the iframe.",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment