From 71d8a0894a9e62f86d8e3d294a65be6fcb6e2205 Mon Sep 17 00:00:00 2001
From: Arthur Verschaeve The Note: Removing an inline Note: Removing an inline As a CSS selector, the child combinator is supported by all modern web browsers including Safari, Firefox, Opera, Chrome, and Internet Explorer 7 and above, but notably not by Internet Explorer versions 6 and below. However, in jQuery, this selector (along with all others) works across all supported browsers, including IE6. The child combinator (E > F) can be thought of as a more specific form of the descendant combinator (E F) in that it selects only first-level descendants. An alternative construct to the success callback option, the An alternative construct to the success callback option, refer to Deprecation Notice: The Deprecation Notice: The The The The The The The The As of jQuery 3.0, this method is deprecated and just an alias of The As of jQuery 1.4 the results will always be returned in document order. The Prior to jQuery 3.0, this method was called As of jQuery 1.4 the results will always be returned in document order. In jQuery 1.4.3 setting an element's data object with Prior to jQuery 1.4.3 (starting in jQuery 1.4) the jQuery 3 changes the behavior of this method to align it to the Dataset API specifications. Specifically, jQuery 3 transforms every two-character sequence of "-" (U+002D) followed by a lowercase ASCII letter by the uppercase version of the letter as per definition of [the algorithm of the Dataset API](http://www.w3.org/TR/html5/dom.html#dom-dataset). Writing a statement like Due to the way browsers interact with plugins and external code, the jQuery 3 changes the behavior of this method to align it to the Dataset API specifications. Specifically, jQuery 3 transforms every two-character sequence of "-" (U+002D) followed by a lowercase ASCII letter by the uppercase version of the letter as per definition of [the algorithm of the Dataset API](http://www.w3.org/TR/html5/dom.html#dom-dataset). Writing a statement like 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. During animations to show an element, the element is considered to be visible at the start of the animation. How jQuery 3 slightly modifies the meaning of All During animations that hide an element, the element is considered visible until the end of the animation. During animations to show an element, the element is considered visible at the start at the animation. How jQuery 3 slightly modifies the meaning of The As of jQuery 3.0 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. Before jQuery version 3.0, the As of jQuery 3.0 this behavior is changed to improve the support for XML documents, including SVG. Starting from this version, the More than one class may be added at a time, separated by a space, to the set of matched elements, like so: If a class name is included as a parameter, then only that class will be removed from the set of matched elements. If no class names are specified in the parameter, all classes will be removed. Before jQuery version 3.0, the As of jQuery 3.0 this behavior is changed to improve the support for XML documents, including SVG. Starting from this version, the More than one class may be removed at a time, separated by a space, from the set of matched elements, like so: This method takes one or more class names as its parameter. In the first version, if an element in the matched set of elements already has the class, then it is removed; if an element does not have the class, then it is added. For example, we can apply This method takes one or more class names as its parameter. In the first version, if an element in the matched set of elements already has the class, then it is removed; if an element does not have the class, then it is added. For example, we can apply The first time we apply The first time we apply The second time we apply Applying The second version of The second time we apply Applying The second version of is equivalent to: is equivalent to: As of jQuery 1.4, if no arguments are passed to As of jQuery 1.4, if no arguments are passed to This example will toggle the The JSON standard does not permit "control characters" such as a tab or newline. An example like Where the browser provides a native implementation of Prior to jQuery 1.9, As of jQuery 3.0, By default, the As of 3.0 the default behavior is changed. If the Most jQuery APIs that accept HTML strings will run scripts that are included in the HTML. If a single Deferred is passed to If no arguments are provided, If a single argument is provided and it is a Promise or has a If a single argument is passed to If any other single argument is provided, If you don't pass it any arguments at all, In the case where multiple Deferred objects are passed to If more than one argument is provided, 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: If more than one argument is provided and one of the arguments is rejected, In the multiple-Deferreds case where one of the Deferreds is rejected, Regardless of provided arguments, methods of the returned Promise object can be called to attach callbacks, such as .removeAttr()
method uses the JavaScript removeAttribute()
function, but it has the advantage of being able to be called directly on a jQuery object and it accounts for different attribute naming across browsers.onclick
event handler using .removeAttr()
doesn't achieve the desired effect in Internet Explorer 6, 7, or 8. To avoid potential problems, use .prop()
instead:onclick
event handler using .removeAttr()
doesn't achieve the desired effect in Internet Explorer 8, 9 and 11. To avoid potential problems, use .prop()
instead:
$element.prop( "onclick", null );
console.log( "onclick property: ", $element[ 0 ].onclick );
From 7ac9ef58309526069247b730aefd5f634af480c7 Mon Sep 17 00:00:00 2001
From: Arthur Verschaeve
true
by default). If you need synchronous requests, set this option to false
. Cross-domain requests and dataType: "jsonp"
requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: false
with jqXHR ($.Deferred
) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done()
or the deprecated jqXHR.success()
.true
by default). If you need synchronous requests, set this option to false
. Cross-domain requests and dataType: "jsonp"
requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: false
with jqXHR ($.Deferred
) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done()
.
.done()
method replaces the deprecated jqXHR.success()
method. Refer to deferred.done()
for implementation details.deferred.done()
for implementation details.jqXHR.success()
, jqXHR.error()
, and jqXHR.complete()
callbacks are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done()
, jqXHR.fail()
, and jqXHR.always()
instead.jqXHR.success()
, jqXHR.error()
, and jqXHR.complete()
callbacks are removed as of jQuery 3.0. You can use jqXHR.done()
, jqXHR.fail()
, and jqXHR.always()
instead.
// Assign handlers immediately after making the request,
diff --git a/entries/jQuery.get.xml b/entries/jQuery.get.xml
index 51b50c64..6e17c416 100644
--- a/entries/jQuery.get.xml
+++ b/entries/jQuery.get.xml
@@ -75,7 +75,7 @@ jqxhr.always(function() {
});
Deprecation Notice
- jqXHR.success()
, jqXHR.error()
, and jqXHR.complete()
callback methods introduced in jQuery 1.5 are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done()
, jqXHR.fail()
, and jqXHR.always()
instead.jqXHR.success()
, jqXHR.error()
, and jqXHR.complete()
callback methods are removed as of jQuery 3.0. You can use jqXHR.done()
, jqXHR.fail()
, and jqXHR.always()
instead.Deprecation Notice
- jqXHR.success()
, jqXHR.error()
, and jqXHR.complete()
callback methods introduced in jQuery 1.5 are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done()
, jqXHR.fail()
, and jqXHR.always()
instead.jqXHR.success()
, jqXHR.error()
, and jqXHR.complete()
callback methods are removed as of jQuery 3.0. You can use jqXHR.done()
, jqXHR.fail()
, and jqXHR.always()
instead.Deprecation Notice
- jqXHR.success()
, jqXHR.error()
, and jqXHR.complete()
callback methods introduced in jQuery 1.5 are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done()
, jqXHR.fail()
, and jqXHR.always()
instead.jqXHR.success()
, jqXHR.error()
, and jqXHR.complete()
callback methods are removed as of jQuery 3.0. You can use jqXHR.done()
, jqXHR.fail()
, and jqXHR.always()
instead..unwrap()
method removes the element's parent. This is effectively the inverse of the .wrap()
method. The matched elements (and their siblings, if any) replace their parents within the DOM structure.jQuery.uniqueSort()
. Please use that method instead.$.unique()
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 exact same 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.$.uniqueSort()
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 exact same 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.jQuery.unique()
.
+
this
refers to the current element in the set.this
refers to the first element in the set. Prior to jQuery 3.0, the callback was incorrectly called for every element in the set and received the index position of the element in the set as an argument..data(obj)
extends the data previously stored with that element..data()
method completely replaced all data, instead of just extending the data object. If you are using third-party plugins it may not be advisable to completely replace the element's data object, since plugins may have also set data.$( "body" ).data( { "my-name": "aValue" } ).data();
will return { myName: "aValue" }
..data()
method cannot be used on <object>
(unless it's a Flash plugin), <applet>
or <embed>
elements.$( "body" ).data( { "my-name": "aValue" } ).data();
will return { myName: "aValue" }
.
HTML5 data-* Attributes
From d0e7282d4c0e9c02263ebcb15ecd419a25113941 Mon Sep 17 00:00:00 2001
From: Aurelio De Rosa :hidden
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 $( elem ).css( "visibility", "hidden" ).is( ":hidden" ) == false
). The release notes outline the changes in more detail.:hidden
(and therefore of :visible
). Starting with this version, elements will be considered :hidden
if they don't have any layout boxes. For example, br
elements and inline elements with no content will not be selected by the :hidden
selector.option
elements are considered hidden, regardless of their selected
state.:visible
is calculated was changed in jQuery 1.3.2. The release notes outline the changes in more detail.:visible
(and therefore of :hidden
). Starting with this version, elements will be considered :visible
if they have any layout boxes, including those of zero width and/or height. For example, br
elements and inline elements with no content will be selected by the :visible
selector.$.isNumeric()
method checks whether its argument represents a numeric value. If so, it returns true
. Otherwise it returns false
. The argument can be of any type.$.isNumeric()
returns true
only if the argument is of type number
, or if it's of type string
and it can be coerced into finite numbers. In all other cases, it returns false
..addClass()
method manipulated the className
property of the selected elements, not the class
attribute. 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).class
attribute is used instead. So, .addClass()
can be used on XML or SVG documents.
$( "p" ).addClass( "myClass yourClass" );
diff --git a/entries/removeClass.xml b/entries/removeClass.xml
index 8bb11196..6a85ea72 100644
--- a/entries/removeClass.xml
+++ b/entries/removeClass.xml
@@ -19,6 +19,8 @@
.removeClass()
method manipulated the className
property of the selected elements, not the class
attribute. Once the property was changed, it was the browser that updated the attribute accordingly. This means that when the class
attribute was updated and the last class name was removed, the browser might have set the attribute's value to an empty string instead of removing the attribute completely. An implication of this behavior was that this method only worked for documents with HTML DOM semantics (e.g., not pure XML documents).class
attribute is used instead. So, .removeClass()
can be used on XML or SVG documents.
$( "p" ).removeClass( "myClass yourClass" )
From 0e81757e88af8cb820cf294513d0004c63068629 Mon Sep 17 00:00:00 2001
From: Aurelio De Rosa
.toggleClass()
to a simple <div>
:
+
.toggleClass()
to a simple <div>
:
-
<div class="tumble">Some text.</div>
-
$( "div.tumble" ).toggleClass( "bounce" )
, we get the following:
+
+
$( "div.tumble" ).toggleClass( "bounce" )
, we get the following:
-
<div class="tumble bounce">Some text.</div>
-
$( "div.tumble" ).toggleClass( "bounce" )
, the <div>
class is returned to the single tumble
value:
- <div class="tumble">Some text.</div>
.toggleClass( "bounce spin" )
to the same <div>
alternates between <div class="tumble bounce spin">
and <div class="tumble">
..toggleClass()
uses the second parameter for determining whether the class should be added or removed. If this parameter's value is true
, then the class is added; if false
, the class is removed. In essence, the statement:
+
+
$( "div.tumble" ).toggleClass( "bounce" )
, the <div>
class is returned to the single tumble
value:
+ <div class="tumble">Some text.</div>
.toggleClass( "bounce spin" )
to the same <div>
alternates between <div class="tumble bounce spin">
and <div class="tumble">
..toggleClass()
uses the second parameter for determining whether the class should be added or removed. If this parameter's value is true
, then the class is added; if false
, the class is removed. In essence, the statement:
-
$( "#foo" ).toggleClass( className, addOrRemove );
-
+
+
-
if ( addOrRemove ) {
$( "#foo" ).addClass( className );
} else {
$( "#foo" ).removeClass( className );
}
-
.toggleClass()
, all class names on the element the first time .toggleClass()
is called will be toggled. Also as of jQuery 1.4, the class name to be toggled can be determined by passing in a function.
+
+
.toggleClass()
, all class names on the element the first time .toggleClass()
is called will be toggled. Also as of jQuery 1.4, the class name to be toggled can be determined by passing in a function.
-
$( "div.foo" ).toggleClass(function() {
if ( $( this ).parent().is( ".bar" ) ) {
return "happy";
@@ -69,17 +64,17 @@ $( "div.foo" ).toggleClass(function() {
return "sad";
}
});
-
happy
class for <div class="foo">
elements if their parent element has a class of bar
; otherwise, it will toggle the sad
class.
-
-
-
$.parseJSON( '{ "testing":"1\t2\n3" }' )
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 "1\\t2\\n3"
yields expected results. This problem is often seen when injecting JSON into a JavaScript file from a server-side language such as PHP.JSON.parse
, jQuery uses it to parse the string. For details on the JSON format, see http://json.org/.$.parseJSON
returned null
instead of throwing an error if it was passed an empty string, null
, or undefined
, even though those are not valid JSON.$.parseJSON
is deprecated. To parse JSON objects, use the native JSON.parse
method instead.jQuery.parseHTML
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 jQuery.trim
.context
is the current document
if not specified or given as null
or undefined
. If the HTML was to be used in another document such as an iframe, that frame's document could be used.context
is not specified or given as null
or undefined
, a new document
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 jQuery.parseHTML
as they usually pass in the current document
. Therefore, a statement like $( "#log" ).append( $( htmlString ) )
is still subject to the injection of malicious code.Security Considerations
jQuery.parseHTML
does not run script in the parsed HTML unless keepScripts
is explicitly true
. However, it is still possible in most environments to execute script indirectly, for example via the <img onerror>
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 any script content when keepScripts
is unspecified or false
.Promise.all
-like fulfillment aggregation.jQuery.when()
, 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 deferred.then
. 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 jQuery.ajax()
is a Promise-compatible object and can be used this way:jQuery.when()
will return a resolved Promise.
+
+$.when().then(function( x ) {
+ alert( "I fired immediately" );
+});
+
then
method, jQuery.when()
will return a Promise that will resolve or reject identically to the argument.
-
$.when( $.ajax( "test.aspx" ) ).then(function( data, textStatus, jqXHR ) {
alert( jqXHR.status ); // Alerts 200
});
jQuery.when()
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:jQuery.when()
will return a Promise that is resolved to it.
-
$.when( { testing: 123 } ).done(function( x ) {
alert( x.testing ); // Alerts "123"
});
jQuery.when()
will return a resolved promise.
-
-$.when().then(function( x ) {
- alert( "I fired immediately" );
-});
-
jQuery.when()
, 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 jQuery.when()
. For example:jQuery.when()
will return the Promise from a new "master" Deferred object that tracks their aggregate state (upgrading each to a Deferred object as in the single-argument case where necessary). The master Deferred will resolve as soon as all subordinates resolve, or reject as soon as one is rejected. If the master Deferred is resolved, the resolution context and values of each subordinate are preserved in its resolution context (an array of all the resolution contexts) and resolution values (the resolution values of each subordinate appear as a single value, with multi-valued resolutions theirselves becoming arrays), each preserving the order in which the subordinate was provided to jQuery.when()
. For example:
-
var d1 = $.Deferred();
var d2 = $.Deferred();
+var d3 = $.Deferred();
-$.when( d1, d2 ).done(function ( v1, v2 ) {
- console.log( v1 ); // "Fish"
- console.log( v2 ); // "Pizza"
+$.when( d1, d2 ).done(function ( v1, v2, v3 ) {
+ console.log( v1 ); // "Fish"
+ console.log( v2 ); // ["Pizza", "Pie"]
+ console.log( v3 ); // undefined
+ console.log( this ); // [{ where: "Ocean" }, undefined, undefined]
});
-d1.resolve( "Fish" );
-d2.resolve( "Pizza" );
+d1.resolveWith( { where: "Ocean" }, [ "Fish" ] );
+d2.resolve( "Pizza", "Pie" );
+d3.resolve();
jQuery.when()
immediately rejects with corresponding context and values. Note that some of the subordinates may still be unresolved at that point. For example:
-
var d1 = $.Deferred();
var d2 = $.Deferred();
var d3 = $.Deferred();
-$.when( d1, d2, d3 ).done(function ( v1, v2, v3 ) {
- console.log( v1 ); // v1 is undefined
- console.log( v2 ); // v2 is "abc"
- console.log( v3 ); // v3 is an array [ 1, 2, 3, 4, 5 ]
+$.when( d1, d2 ).fail(function ( rejection ) {
+ console.log( rejection ); // "Pie"
+ console.log( this ); // { type: "Pizza" }
});
-d1.resolve();
-d2.resolve( "abc" );
-d3.resolve( 1, 2, 3, 4, 5 );
+d1.resolve( "Fish" );
+d2.rejectWith( { type: "Pizza" }, [ "Pie" ] );
+d3.resolve();
jQuery.when()
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.deferred.then
. When the Deferred is resolved or rejected, usually by the code that created the Deferred originally, the appropriate callbacks will be called.