From b3a98ac0ccfa7a91b58adbf688f70930bb702ad5 Mon Sep 17 00:00:00 2001
From: Karl Swedberg An element in the DOM can also be selected and inserted after another element: If an element selected this way is inserted elsewhere, it will be moved rather than cloned: If an element selected this way is inserted into a single location elsewhere in the DOM, it will be moved rather than cloned: You can also select an element on the page and insert it into another: If an element selected this way is inserted elsewhere, it will be moved into the target (not cloned): 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): We can also select an element on the page and insert it into another: If an element selected this way is inserted elsewhere, it will be moved into the target (not cloned): 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): You can also select an element on the page and insert it before another: If an element selected this way is inserted elsewhere, it will be moved before the target (not cloned): 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): We can also select an element on the page and insert it after another: If an element selected this way is inserted elsewhere, it will be moved after the target (not cloned): 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): We can also select an element on the page and insert it before another: If an element selected this way is inserted elsewhere, it will be moved before the target (not cloned): 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): You can also select an element on the page and insert it into another: If a single element selected this way is inserted elsewhere, it will be moved into the target (not cloned): If a single element selected this way is inserted into a single location elsewhere in the DOM, it will be moved into the target (not cloned): We can also select an element on the page and insert it into another: If an element selected this way is inserted elsewhere, it will be moved into the target (not cloned): 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): After First Paragraph Second Paragraph The index-related selectors ( Note that since JavaScript arrays use 0-based indexing, these selectors reflect that fact. This is why Unlike the Prior to jQuery 1.8, the Whenever an Ajax request completes, jQuery triggers the To observe this method in action, we can set up a basic Ajax load request: To observe this method in action, set up a basic Ajax load request: We can attach our event handler to any element: Attach the event handler to the document: Now, we can make an Ajax request using any jQuery method: Now, make an Ajax request using any jQuery method: When the user clicks the element with class Note: Because All Note: You can get the returned ajax contents by looking at Note: Because All Note: You can get the returned ajax contents by looking at Attach the event handler to any element: Attach the event handler to the document: Now, make an Ajax request using any jQuery method: When the user clicks the button and the Ajax request fails, because the requested file is missing, the log message is displayed. Note: Because All Note: Because All Whenever an Ajax request is about to be sent, jQuery triggers the To observe this method in action, we can set up a basic Ajax load request: To observe this method in action, set up a basic Ajax load request: We can attach our event handler to any element: Attach the event handler to the document: Now, we can make an Ajax request using any jQuery method: Now, make an Ajax request using any jQuery method: When the user clicks the element with class Note: Because All Note: Because All 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 To observe this method in action, we can set up a basic Ajax load request: To observe this method in action, set up a basic Ajax load request: We can attach our event handler to any element: Attach the event handler to any element: Now, we can make an Ajax request using any jQuery method: Now, make an Ajax request using any jQuery method: When the user clicks the element with class Note: Because Note: Because Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the To observe this method in action, we can set up a basic Ajax load request: To observe this method in action, set up a basic Ajax load request: We can attach our event handler to any element: Attach the event handler to the document: Now, we can make an Ajax request using any jQuery method: Now, make an Ajax request using any jQuery method: When the user clicks the element with class Because Because Whenever an Ajax request completes successfully, jQuery triggers the To observe this method in action, we can set up a basic Ajax load request: To observe this method in action, set up a basic Ajax load request: We can attach our event handler to any element: Attach the event handler to any element: Now, we can make an Ajax request using any jQuery method: Now, make an Ajax request using any jQuery method: When the user clicks the element with class Note: Because All Note: You can get the returned ajax contents by looking at Note: Because All Note: You can get the returned ajax contents by looking at When we supply two or more objects to If only one argument is supplied to Keep in mind that the target object (first argument) will be modified, and will also be returned from When two or more objects are supplied to If only one argument is supplied to Keep in mind that the target object (first argument) will be modified, and will also be returned from The merge performed by The merge performed by Warning: Passing Undefined properties are not copied. However, properties inherited from the object's prototype will be copied over. Properties that are an object constructed via On a For needs that fall outside of this behavior, write a custom extend method instead. If a single argument is passed to If a single argument is passed to If no argument is passed to the If If a selector string is passed as an argument, If a selector string is passed as an argument, The complementary operation to The matched elements will be hidden immediately, with no animation. This is roughly equivalent to calling When a duration is provided, When a duration, a plain object, or a "complete" function is provided, Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings Note that As of jQuery 1.4.3, 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 Note: If using !important in your styles, such as
When a duration is provided, When a duration, a plain object, or a "complete" function is provided, Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings As of jQuery 1.4.3, 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 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 With no parameters, the The matched elements will be revealed or hidden immediately, with no animation, by changing the CSS When a duration is provided, When a duration, a plain object, or a single "complete" function is provided, Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings As of jQuery 1.4.3, 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 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 Whenever an Ajax request completes, jQuery triggers the To observe this method in action, set up a basic Ajax load request: Whenever an Ajax request completes with an error, jQuery triggers the To observe this method in action, set up a basic Ajax load request. Whenever an Ajax request is about to be sent, jQuery triggers the To observe this method in action, set up a basic Ajax load request: 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 To observe this method in action, set up a basic Ajax load request: Whenever an Ajax request completes successfully, jQuery triggers the To observe this method in action, set up a basic Ajax load request: Ajax requests produce a number of different events that you can subscribe to. Here's a full list of the events and in what order they are broadcast. There are two types of events: These are callbacks that you can subscribe to within the Ajax request object, like so: These events are broadcast to all elements in the DOM, triggering any handlers which may be listening. You can listen for these events like so: Global events can be disabled for a particular Ajax request by passing in the global option, like so: This is the full list of Ajax events that are broadcast, and in the order in which they are broadcast. The indented events are broadcast for each and every Ajax request (unless a global option has been set). The ajaxStart and ajaxStop events are events that relate to all Ajax requests together.
+ 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 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 As of jQuery 1.6, any number of additional arguments may supplied to If a number is zero, it defaults to false:
In this case, To keep the examples short, the invert-operator is used to show a boolean context:
+ To keep the examples short, the invert ("not") operator and double-negation are used to show a boolean context:
On to the actual types.
An empty string defaults to false:
If a number is zero, it defaults to false:
A boolean in JavaScript can be either true or false:
Everything in JavaScript is an object, though some are more objective (haha). The easiest way to create an object is the object literal:
@@ -281,6 +285,7 @@ An object, no matter if it has properties or not, never defaults to false:
All objects have a prototype property. Whenever the interpreter looks for a property, it also checks the prototype. jQuery uses that extensively to add methods to jQuery instances.
@@ -369,6 +374,7 @@ An array, no matter if it has elements or not, never defaults to false:
In the jQuery API you'll often find the notation of Array<Type>:
From 0f0498233071b3ad4b210639a1937640ce24bbf4 Mon Sep 17 00:00:00 2001
From: Corey Frang The name Note: Internet Explorer will not allow you to create an Unsupported in IE: Supported workaround:
- $('.container').after($('h2'));<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
@@ -95,4 +95,4 @@ $('p').first().after($newdiv1, [newdiv2, existingdiv1]);
- $('.container').append($('h2'));
<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
@@ -100,4 +100,4 @@ $('body').append($newdiv1, [newdiv2, existingdiv1]);
+
+
- $('h2').appendTo($('.container'));
<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
@@ -55,4 +55,4 @@
- $('.container').before($('h2'));<h2>Greetings</h2>
<div class="container">
<div class="inner">Hello</div>
@@ -80,4 +80,4 @@ $('p').first().before($newdiv1, [newdiv2, existingdiv1]);
- $('h2').insertAfter($('.container'));<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
@@ -44,4 +44,4 @@
- $('h2').insertBefore($('.container'));<h2>Greetings</h2>
<div class="container">
<div class="inner">Hello</div>
@@ -44,4 +44,4 @@
- $('.container').prepend($('h2'));<div class="container">
<h2>Greetings</h2>
<div class="inner">Hello</div>
@@ -84,4 +84,4 @@ $('body').prepend($newdiv1, [newdiv2, existingdiv1]);
- $('h2').prependTo($('.container'));
+ <div class="container">
<h2>Greetings</h2>
<div class="inner">Hello</div>
@@ -50,4 +50,4 @@
divs, and all the paragraphs inside of them, and give them both class names. Notice the div doesn't have the yellow background color since it didn't use .andSelf().
andSelf()
]]>
+ n within the matched set.:eq(), :lt(), :gt(), :even, :odd) 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 (.myclass) and four elements are returned, these elements are given indices 0 through 3 for the purposes of these selectors.$('.myclass:eq(1)') selects the second element in the document with the class myclass, rather than the first. In contrast, :nth-child(n) uses 1-based indexing to conform to the CSS specification..eq(index) method, the :eq(index) selector does not accept a negative value for index. For example, while $('li').eq(-1) selects the last li element, $('li:eq(-1)') selects nothing.:eq(index) selector did not accept a negative value for index (though the .eq(index) method did).:eq() is designed to select a single element while :nth-child() or :eq() within a looping construct such as .each() can select multiple elements.
+
+
Register a handler to be called when Ajax requests complete. This is an AjaxEvent.
ajaxComplete event. Any and all handlers that have been registered with the .ajaxComplete() method are executed at this time.
- <div class="trigger">Trigger</div>
<div class="result"></div>
<div class="log"></div>
$('.log').ajaxComplete(function() {
- $(this).text('Triggered ajaxComplete handler.');
+
- $(document).ajaxComplete(function() {
+ $( ".log" ).text( "Triggered ajaxComplete handler." );
});
$('.trigger').click(function() {
- $('.result').load('ajax/test.html');
+ $( ".trigger" ).click(function() {
+ $( ".result" ).load( "ajax/test.html" );
});trigger and the Ajax request completes, the log message is displayed..ajaxComplete() is implemented as a method of jQuery object instances, we can use the this keyword as we do here to refer to the selected elements within the callback function.ajaxComplete handlers are invoked, regardless of what Ajax request was completed. If we must differentiate between the requests, we can use the parameters passed to the handler. Each time an ajaxComplete handler is executed, it is passed the event object, the XMLHttpRequest object, and the settings object that was used in the creation of the request. For example, we can restrict our callback to only handling events dealing with a particular URL:xhr.responseXML or xhr.responseHTML for xml and html respectively.$('.log').ajaxComplete(function(e, xhr, settings) {
- if (settings.url == 'ajax/test.html') {
- $(this).text('Triggered ajaxComplete handler. The result is ' +
- xhr.responseHTML);
+ .ajaxComplete() is implemented as a method of jQuery object instances, you can use the this keyword to refer to the selected elements within the callback function. As of jQuery 1.8, however, the .ajaxComplete() method should only be attached to document.ajaxComplete 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 ajaxComplete handler is executed, it is passed the event object, the XMLHttpRequest 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:
+ $(document).ajaxComplete(function(event, xhr, settings) {
+ if ( settings.url === "ajax/test.html" ) {
+ $( ".log" ).text( "Triggered ajaxComplete handler. The result is " +
+ xhr.responseHTML );
}
});xhr.responseXML or xhr.responseHTML for xml and html respectively.
- <button class="trigger">Trigger</button>
<div class="result"></div>
<div class="log"></div>$("div.log").ajaxError(function() {
- $(this).text( "Triggered ajaxError handler." );
+ $(document).ajaxError(function() {
+ $( "div.log" ).text( "Triggered ajaxError handler." );
});$("button.trigger").click(function() {
- $("div.result").load( "ajax/missing.html" );
+ $( "button.trigger" ).click(function() {
+ $( "div.result" ).load( "ajax/missing.html" );
});.ajaxError() is implemented as a method of jQuery object instances, you can use the this keyword within the callback function to refer to the selected elements.ajaxError handlers are invoked, regardless of what Ajax request was completed. To differentiate between the requests, you can use the parameters passed to the handler. Each time an ajaxError handler is executed, it is passed the event object, the jqXHR object (prior to jQuery 1.5, the XHR object), and the settings object that was used in the creation of the request. If the request failed because JavaScript raised an exception, the exception object is passed to the handler as a fourth parameter. For example, to restrict the error callback to only handling events dealing with a particular URL:$( "div.log" ).ajaxError(function(e, jqxhr, settings, exception) {
+ .ajaxError() is implemented as a method of jQuery object instances, you can use the this keyword within the callback function to refer to the selected elements. As of jQuery 1.8, however, the .ajaxError() method should only be attached to document.ajaxError 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 ajaxError handler is executed, it is passed the event object, the jqXHR object (prior to jQuery 1.5, the XHR object), and the settings object that was used in the creation of the request. If the request failed because JavaScript raised an exception, the exception object is passed to the handler as a fourth parameter. For example, to restrict the error callback to only handling events dealing with a particular URL:$( document ).ajaxError(function(event, jqxhr, settings, exception) {
if ( settings.url == "ajax/missing.html" ) {
- $(this).text( "Triggered ajaxError handler." );
+ $( "div.log" ).text( "Triggered ajaxError handler." );
}
});
ajaxSend event. Any and all handlers that have been registered with the .ajaxSend() method are executed at this time.
- <div class="trigger">Trigger</div>
<div class="result"></div>
<div class="log"></div>$('.log').ajaxSend(function() {
- $(this).text('Triggered ajaxSend handler.');
+
- $(document).ajaxSend(function() {
+ $( ".log" ).text( "Triggered ajaxSend handler." );
});$('.trigger').click(function() {
- $('.result').load('ajax/test.html');
+ $( ".trigger" ).click(function() {
+ $( ".result" ).load( "ajax/test.html" );
});trigger and the Ajax request is about to begin, the log message is displayed..ajaxSend() is implemented as a method of jQuery instances, we can use the this keyword as we do here to refer to the selected elements within the callback function.ajaxSend handlers are invoked, regardless of what Ajax request is to be sent. If we must differentiate between the requests, we can use the parameters passed to the handler. Each time an ajaxSend handler is executed, it is passed the event object, the jqXHR object (in version 1.4, XMLHttpRequestobject), and the settings object that was used in the creation of the Ajax request. For example, we can restrict our callback to only handling events dealing with a particular URL:$('.log').ajaxSend(function(e, jqxhr, settings) {
- if (settings.url == 'ajax/test.html') {
- $(this).text('Triggered ajaxSend handler.');
+ .ajaxSend() is implemented as a method of jQuery instances, you can use the this keyword to refer to the selected elements within the callback function. As of jQuery 1.8, however, the .ajaxSend() method should only be attached to document.ajaxSend 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 ajaxSend handler is executed, it is passed the event object, the jqXHR object (in version 1.4, XMLHttpRequestobject), and the settings object 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:$(document).ajaxSend(function(event, jqxhr, settings) {
+ if ( settings.url == "ajax/test.html" ) {
+ $( ".log" ).text( "Triggered ajaxSend handler." );
}
});
ajaxStart event. Any and all handlers that have been registered with the .ajaxStart() method are executed at this time.
- <div class="trigger">Trigger</div>
<div class="result"></div>
<div class="log"></div>$('.log').ajaxStart(function() {
- $(this).text('Triggered ajaxStart handler.');
+
- $(document).ajaxStart(function() {
+ $( ".log" ).text( "Triggered ajaxStart handler." );
});$('.trigger').click(function() {
- $('.result').load('ajax/test.html');
+ $( ".trigger" ).click(function() {
+ $( ".result" ).load("ajax/test.html");
});trigger and the Ajax request is sent, the log message is displayed..ajaxStart() is implemented as a method of jQuery object instances, we can use the this keyword as we do here to refer to the selected elements within the callback function..ajaxStart() is implemented as a method of jQuery object instances, you can use the this keyword to refer to the selected elements within the callback function. As of jQuery 1.8, however, the .ajaxStart() method should only be attached to document.
ajaxStop event. Any and all handlers that have been registered with the .ajaxStop() method are executed at this time. The ajaxStop event is also triggered if the last outstanding Ajax request is cancelled by returning false within the beforeSend callback function.
- <div class="trigger">Trigger</div>
<div class="result"></div>
<div class="log"></div>$('.log').ajaxStop(function() {
- $(this).text('Triggered ajaxStop handler.');
+
- $( ".log" ).ajaxStop(function() {
+ $(this).text( "Triggered ajaxStop handler." );
});$('.trigger').click(function() {
- $('.result').load('ajax/test.html');
+ $( ".trigger" ).click(function() {
+ $( ".result" ).load( "ajax/test.html" );
});trigger and the Ajax request completes, the log message is displayed..ajaxStop() is implemented as a method of jQuery object instances, we can use the this keyword as we do here to refer to the selected elements within the callback function..ajaxStop() is implemented as a method of jQuery object instances, you can use the this keyword to refer to the selected elements within the callback function. As of jQuery 1.8, however, the .ajaxStop() method should only be attached to document.
ajaxSuccess event. Any and all handlers that have been registered with the .ajaxSuccess() method are executed at this time.
- <div class="trigger">Trigger</div>
<div class="result"></div>
<div class="log"></div>$('.log').ajaxSuccess(function() {
- $(this).text('Triggered ajaxSuccess handler.');
+
- $(document).ajaxSuccess(function() {
+ $( ".log" ).text( "Triggered ajaxSuccess handler." );
});$('.trigger').click(function() {
- $('.result').load('ajax/test.html');
+ $( ".trigger" ).on("click", function() {
+ $( ".result" ).load( "ajax/test.html" );
});trigger and the Ajax request completes successfully, the log message is displayed..ajaxSuccess() is implemented as a method of jQuery object instances, we can use the this keyword as we do here to refer to the selected elements within the callback function.ajaxSuccess handlers are invoked, regardless of what Ajax request was completed. If we must differentiate between the requests, we can use the parameters passed to the handler. Each time an ajaxSuccess handler is executed, it is passed the event object, the XMLHttpRequest object, and the settings object that was used in the creation of the request. For example, we can restrict our callback to only handling events dealing with a particular URL:xhr.responseXML or xhr.responseText for xml and html respectively.$('.log').ajaxSuccess(function(e, xhr, settings) {
- if (settings.url == 'ajax/test.html') {
- $(this).text('Triggered ajaxSuccess handler. The ajax response was:'
- + xhr.responseText );
+ .ajaxSuccess() is implemented as a method of jQuery object instances, use the this keyword to refer to the selected elements within the callback function. As of jQuery 1.8, however, the .ajaxSuccess() method should only be attached to document.ajaxSuccess 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 ajaxSuccess handler is executed, it is passed the event object, the XMLHttpRequest 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:
+ $(document).ajaxSuccess(function(event, xhr, settings) {
+ if ( settings.url == "ajax/test.html" ) {
+ $( ".log" ).text( "Triggered ajaxSuccess handler. The ajax response was: " +
+ xhr.responseText );
}
});xhr.responseXML or xhr.responseText for xml and html respectively.
$.extend(), properties from all of the objects are added to the target object.$.extend(), this means the target argument was omitted. In this case, the jQuery object itself is assumed to be the target. By doing this, we can add new functions to the jQuery namespace. This can be useful for plugin authors wishing to add new methods to JQuery.$.extend(). If, however, we want to preserve both of the original objects, we can do so by passing an empty object as the target:$.extend(), properties from all of the objects are added to the target object.$.extend(), 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.$.extend(). If, however, you want to preserve both of the original objects, you can do so by passing an empty object as the target:
- var object = $.extend({}, object1, object2);$.extend() 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 object. The values are not merged. This can be seen in the example below by examining the value of banana. However, by passing true for the first function argument, objects will be recursively merged. (Passing false for the first argument is not supported.)$.extend() 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 object. The values are not merged. This can be seen in the example below by examining the value of banana. However, by passing true for the first function argument, objects will be recursively merged.false for the first argument is not supported.new MyCustomObject(args), 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.deep extend, Object and Array are extended, but object wrappers on primitive types such as String, Boolean, and Number are not.
- $.when( $.ajax("test.aspx") ).then(function(data, textStatus, jqXHR){
alert( jqXHR.status ); // alerts 200
});jQuery.when and it is not a Deferred, 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 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:
From 375c308e690ed24805f829db46985db7b69fe362 Mon Sep 17 00:00:00 2001
From: Dave Methvin $.when( { testing: 123 } ).done(
function(x) { alert(x.testing); } /* alerts "123" */
);Return Values
.index() method, the return value is an integer indicating the position of the first element within the jQuery object relative to its sibling elements..index() is called on a collection of elements and a DOM element or jQuery object is passed in, .index() returns an integer indicating the position of the passed element relative to the original collection..index() returns an integer indicating the position of the original element relative to the elements matched by the selector. If the element is not found, .index() will return -1..index() 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, .index() will return -1.Detail
.get(), which accepts an index and returns a DOM node, .index() can take a DOM node and returns an index. Suppose we have a simple unordered list on the page:
From 69ed47a2ee6c58690480f0d1bd0a36d75215f2a1 Mon Sep 17 00:00:00 2001
From: Karl Swedberg
$('.target').hide();
.css('display', 'none'), except that the value of the display property is saved in jQuery's data cache so that display can later be restored to its initial value. If an element has a display value of inline, then is hidden and shown, it will once again be displayed inline..hide() becomes an animation method. The .hide() method animates the width, height, and opacity of the matched elements simultaneously. When these properties reach 0, the display style property is set to none to ensure that the element no longer affects the layout of the page..hide() becomes an animation method. The .hide() method animates the width, height, and opacity of the matched elements simultaneously. When these properties reach 0, the display style property is set to none to ensure that the element no longer affects the layout of the page.'fast' and 'slow' can be supplied to indicate durations of 200 and 600 milliseconds, respectively..hide() is fired immediately and will override the animation queue if no duration or a duration of 0 is specified.swing, and one that progresses at a constant pace, called linear. More easing functions are available with the use of plug-ins, most notably the jQuery UI suite.display: none !important,
it is necessary to override the style using .css('display', 'block !important') should you wish for .show() to function correctly..show() becomes an animation method. The .show() method animates the width, height, and opacity of the matched elements simultaneously..show() becomes an animation method. The .show() method animates the width, height, and opacity of the matched elements simultaneously.'fast' and 'slow' can be supplied to indicate durations of 200 and 600 milliseconds, respectively.swing, and one that progresses at a constant pace, called linear. More easing functions are available with the use of plug-ins, most notably the jQuery UI suite.this 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..toggle() method simply toggles the visibility of elements:$('.target').toggle();display property. If the element is initially displayed, it will be hidden; if hidden, it will be shown. The display property is saved and restored as needed. If an element has a display value of inline, then is hidden and shown, it will once again be displayed inline..toggle() becomes an animation method. The .toggle() method animates the width, height, and opacity of the matched elements simultaneously. When these properties reach 0 after a hiding animation, the display style property is set to none to ensure that the element no longer affects the layout of the page..toggle() becomes an animation method. The .toggle() method animates the width, height, and opacity of the matched elements simultaneously. When these properties reach 0 after a hiding animation, the display style property is set to none to ensure that the element no longer affects the layout of the page.'fast' and 'slow' can be supplied to indicate durations of 200 and 600 milliseconds, respectively.swing, and one that progresses at a constant pace, called linear. More easing functions are available with the use of plug-ins, most notably the jQuery UI suite.this 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.ajaxComplete event. Any and all handlers that have been registered with the .ajaxComplete() method are executed at this time.ajaxError event. Any and all handlers that have been registered with the .ajaxError() method are executed at this time.ajaxSend event. Any and all handlers that have been registered with the .ajaxSend() method are executed at this time.ajaxStart event. Any and all handlers that have been registered with the .ajaxStart() method are executed at this time.ajaxSuccess event. Any and all handlers that have been registered with the .ajaxSuccess() method are executed at this time.false in the beforeSend function will cancel the request. As of jQuery 1.5, the beforeSend option will be called regardless of the type of request.false in the beforeSend function will cancel the request. As of jQuery 1.5, the beforeSend option will be called regardless of the type of request.false, it will force requested pages not to be cached by the browser. Note: Setting cache 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.success and error 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 ("success", "notmodified", "error", "timeout", "abort", or "parsererror"). As of jQuery 1.5, the complete setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.success and error 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 ("success", "notmodified", "error", "timeout", "abort", or "parsererror"). As of jQuery 1.5, the complete setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: This handler is not called for cross-domain script and JSONP requests. This is an Ajax Event. null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: This handler is not called for cross-domain script and JSONP requests. This is an Ajax Event. true. Set to false to prevent the global handlers like ajaxStart or ajaxStop from being triggered. This can be used to control various Ajax Events.true. Set to false to prevent the global handlers like ajaxStart or ajaxStop from being triggered. This can be used to control various Ajax Events.beforeSend function is called; therefore, any values in the headers setting can be overwritten from within the beforeSend function.dataType parameter; a string describing the status; and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object. As of jQuery 1.5, the success setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.dataType parameter; a string describing the status; and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object. As of jQuery 1.5, the success setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.$.ajax 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. In jQuery 1.4.x and below, the XMLHttpRequest object will be in an invalid state if the request times out; accessing any object members may throw an exception. In Firefox 3.0+ only, script and JSONP requests cannot be cancelled by a timeout; the script will run even if it arrives after the timeout period.Local Events
+
+ $.ajax({
+ beforeSend: function(){
+ // Handle the beforeSend event
+ },
+ complete: function(){
+ // Handle the complete event
+ }
+ // ......
+ });
+Global Events
+ $("#loading").bind("ajaxSend", function(){
+ $(this).show();
+ }).bind("ajaxComplete", function(){
+ $(this).hide();
+ });
+
+
+ $.ajax({
+ url: "test.html",
+ global: false,
+ // ...
+ });
+Events
+
+
From 2c02411b808260ab4a6e00ca4115a9a39df9ab8e Mon Sep 17 00:00:00 2001
From: Karl Swedberg
This event is broadcast if an Ajax request is started and no other Ajax requests are currently running.
+
+
+
This event, which is triggered before an Ajax request is started, allows you to modify the XMLHttpRequest object (setting additional headers, if need be.)
This global event is also triggered before the request is run.
This event is only called if the request was successful (no errors from the server, no errors with the data).
This event is also only called if the request was successful.
This event is only called if an error occurred with the request (you can never have both an error and a success callback with a request).
This global event behaves the same as the local error event.
This event is called regardless of if the request was successful, or not. You will always receive a complete callback, even for synchronous requests.
This event behaves the same as the complete event and will be triggered every time an Ajax request finishes.
This global event is triggered if there are no more Ajax requests being processed.context object).this) of the function should be set.function argument.context object).name argument.jQuery.proxy() it will still unbind the correct function if passed the original.jQuery.proxy() 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., "click.myproxy1") rather than specifying the proxied function during unbinding.
$.proxy(), and they will be passed to the function whose context will be changed.
" );
$("#test").unbind("click", this.test);
}
@@ -54,22 +80,26 @@ var you = {
}
};
-// execute you.test() in the context of the `you` object
-// no matter where it is called
-// i.e. the `this` keyword will refer to `you`
+/* execute you.test() in the context of the `you` object */
+/* no matter where it is called */
+/* i.e. the `this` keyword will refer to `you` */
var youClick = $.proxy( you.test, you );
-// attach click handlers to #test
+/* attach click handlers to #test */
$("#test")
- // this === "zombie"; handler unbound after first click
- .click( $.proxy( me.test, me ) )
- // this === "person"
- .click( youClick )
- // this === "zombie"
- .click( $.proxy( you.test, me ) )
- // this === "
+ Boolean Default
From 71eaf6bf4b39f2dfa3c23667784c770dad28d81b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rn=20Zaefferer?= !0 // true
+!!0 // false (Double negation: Since "not 0" is true, negating that makes it false)
!1 // false
!-1 // false
"x defaulted to false" is printed.
!x // true
+
+var x = "";
+!x // true
+!!x // false (Double negation: Since "not (empty string)" is true, negating that makes it false)
Boolean Default
!"" // true
+!!"" // false
!"hello" // false
!"true" // false
!new Boolean( false ) // false
@@ -144,7 +148,7 @@ Boolean Default
@@ -217,8 +221,8 @@ !0 // true
-!!0 // false (Double negation: Since "not 0" is true, negating that makes it false)
+!!0 // false
!1 // false
!-1 // false
Float
Boolean
if ( true ) console.log( "always!" )
-if ( false ) console.log( "never!" )
+if ( true ) console.log( "always!" );
+if ( false ) console.log( "never!" );
Object
Boolean default
!{} // false
+!!{} // true
Prototype
Boolean Default
![] // false
+!![] // true
Array<Type> Notation
"class" must be quoted in the map since it is a JavaScript reserved word, and "className" cannot be used since it is not the correct attribute name. input or button element and change its type; you must specify the type using "<input type="checkbox" />", for example. A demonstration of this can be seen below:
-
-$( "<input />", {
- type: "text",
- name: "test"
-}).appendTo( "body" );
-
-$( "<input type="text" />" ).attr({
- name: "test"
-}).appendTo( "body" );
-Some text but not Some text.
Attribute values in selector expressions must follow the rules for W3C CSS selectors, in general that means anything other than a simple identifier should be surrounded by quotation marks.
+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.
+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, $("a[rel='nofollow']"), will select <a href="example.html" rel="nofollow">Some text</a> but not <a href="example.html" rel="nofollow foe">Some text</a>.
Attribute values in selector expressions must follow the rules for W3C CSS selectors; in general, that means anything other than a valid identifier should be surrounded by quotation marks.
$('a[rel="nofollow self"]')$("a[rel='nofollow self']")$("a[rel=\"nofollow self\"]")The variation you choose is generally a matter of style or convenience.
+Note: In jQuery 1.3 [@attr] 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.
As described in the discussion for .end(), jQuery objects maintain aninternal stack that keeps track of changes to the matched set of elements. When one of the DOM traversal methods is called, the new set of elements is pushed onto the stack. If the previous set of elements is desired as well, .andSelf() can help.
As described in the discussion for .end(), jQuery objects maintain an internal stack that keeps track of changes to the matched set of elements. When one of the DOM traversal methods is called, the new set of elements is pushed onto the stack. If the previous set of elements is desired as well, .andSelf() can help.
Consider a page with a simple list on it:
<ul>
@@ -24,10 +24,14 @@
First, the initial selector locates item 3, initializing the stack with the set containing just this item. The call to .nextAll() then pushes the set of items 4 and 5 onto the stack. Finally, the .andSelf() invocation merges these two sets together, creating a jQuery object that points to all three items in document order: {[<li.third-item>,<li>,<li> ]}.
divs, and all the paragraphs inside of them, and give them both class names. Notice the div doesn't have the yellow background color since it didn't use .andSelf()..andSelf() 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 .find("p"). In the second example, .andSelf() adds the previous set of elements on the stack — in this case $("div.after-andself") — to the current set, selecting both the div and its enclosed paragraphs.
As described in the discussion for .end(), 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, .addBack() can help.
Consider a page with a simple list on it:
+
+<ul>
+ <li>list item 1</li>
+ <li>list item 2</li>
+ <li class="third-item">list item 3</li>
+ <li>list item 4</li>
+ <li>list item 5</li>
+</ul>
+
+ The result of the following code is a red background behind items 3, 4 and 5:
+$('li.third-item').nextAll().addBack()
+ .css('background-color', 'red');
+
+ First, the initial selector locates item 3, initializing the stack with the set containing just this item. The call to .nextAll() then pushes the set of items 4 and 5 onto the stack. Finally, the .addBack() invocation merges these two sets together, creating a jQuery object that points to all three items in document order: {[<li.third-item>,<li>,<li> ]}.
.addBack() 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 .find("p"). In the second example, .addBack() adds the previous set of elements on the stack — in this case $("div.after-addback") — to the current set, selecting both the div and its enclosed paragraphs.
+ Note: This function has been deprecated and is now an alias for .addBack(), which should be used with jQuery 1.8 and later.
As described in the discussion for .end(), jQuery objects maintain an internal stack that keeps track of changes to the matched set of elements. When one of the DOM traversal methods is called, the new set of elements is pushed onto the stack. If the previous set of elements is desired as well, .andSelf() can help.
Consider a page with a simple list on it:
From 8237b684d1a0e2370296edb6511751bfcffa92fb Mon Sep 17 00:00:00 2001
From: Karl Swedberg
Date: Sat, 15 Dec 2012 14:30:56 -0500
Subject: [PATCH 024/998] Change "map" to "object" or "plain object" as
appropriate. Closes #181
---
entries/animate.xml | 12 ++++++------
entries/attr.xml | 4 ++--
entries/bind.xml | 10 +++++-----
entries/blur.xml | 4 ++--
entries/change.xml | 4 ++--
entries/click.xml | 4 ++--
entries/css.xml | 4 ++--
entries/dblclick.xml | 4 ++--
entries/delegate.xml | 6 +++---
entries/die.xml | 2 +-
entries/error.xml | 4 ++--
entries/event.data.xml | 2 +-
entries/focus.xml | 4 ++--
entries/focusin.xml | 4 ++--
entries/focusout.xml | 4 ++--
entries/jQuery.ajax.xml | 20 ++++++++++----------
entries/jQuery.ajaxTransport.xml | 6 +++---
entries/jQuery.browser.xml | 2 +-
entries/jQuery.each.xml | 16 ++++++++--------
entries/jQuery.get.xml | 6 +++---
entries/jQuery.getJSON.xml | 6 +++---
entries/jQuery.map.xml | 2 +-
entries/jQuery.noConflict.xml | 2 +-
entries/jQuery.post.xml | 6 +++---
entries/jQuery.xml | 6 +++---
entries/keydown.xml | 4 ++--
entries/keypress.xml | 4 ++--
entries/keyup.xml | 4 ++--
entries/live.xml | 8 ++++----
entries/load-event.xml | 4 ++--
entries/load.xml | 6 +++---
entries/mousedown.xml | 4 ++--
entries/mouseenter.xml | 4 ++--
entries/mouseleave.xml | 4 ++--
entries/mousemove.xml | 4 ++--
entries/mouseout.xml | 4 ++--
entries/mouseover.xml | 4 ++--
entries/mouseup.xml | 4 ++--
entries/off.xml | 4 ++--
entries/on.xml | 10 +++++-----
entries/one.xml | 6 +++---
entries/prop.xml | 2 +-
entries/resize.xml | 4 ++--
entries/scroll.xml | 4 ++--
entries/select.xml | 4 ++--
entries/submit.xml | 4 ++--
entries/undelegate.xml | 4 ++--
entries/unload.xml | 4 ++--
48 files changed, 124 insertions(+), 124 deletions(-)
diff --git a/entries/animate.xml b/entries/animate.xml
index 9c161392..e67347ff 100644
--- a/entries/animate.xml
+++ b/entries/animate.xml
@@ -5,7 +5,7 @@
1.0
- A map of CSS properties that the animation will move toward.
+ An object of CSS properties and values that the animation will move toward.
@@ -14,13 +14,13 @@
1.0
- A map of CSS properties that the animation will move toward.
+ An object of CSS properties and values that the animation will move toward.
- The .animate() method allows us to create animation effects on any numeric CSS property. The only required parameter is a map of CSS properties. This map is similar to the one that can be sent to the .css() method, except that the range of properties is more restrictive.
+ The .animate() 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 .css() method, except that the range of properties is more restrictive.
Animation Properties and Values
All animated properties should be animated to a single numeric value, except as noted below; most properties that are non-numeric cannot be animated using basic jQuery functionality (For example, width, height, or left can be animated but background-color cannot be, unless the jQuery.Color() plugin is used). Property values are treated as a number of pixels unless otherwise specified. The units em and % can be specified where applicable.
In addition to style properties, some non-style properties such as scrollTop and scrollLeft, as well as custom properties, can be animated.
@@ -100,7 +100,7 @@
$(this).after('<div>Animation complete.</div>');
});
});
- In the second version of .animate(), the options map can include the specialEasing property, which is itself a map of CSS properties and their corresponding easing functions. For example, to simultaneously animate the width using the linear easing function and the height using the easeOutBounce easing function:
In the second version of .animate(), the options object can include the specialEasing property, which is itself an object of CSS properties and their corresponding easing functions. For example, to simultaneously animate the width using the linear easing function and the height using the easeOutBounce easing function:
$('#clickme').click(function() {
$('#book').animate({
width: 'toggle',
@@ -290,7 +290,7 @@ div {
}, { duration: "slow", easing: "easein" });]]>
1: 97
- If a map is used as the collection, the callback is passed a key-value pair each time:
- var map = {
- 'flammable': 'inflammable',
- 'duh': 'no duh'
+ If an object is used as the collection, the callback is passed a key-value pair each time:
+ var obj = {
+ "flammable": "inflammable",
+ "duh": "no duh"
};
-$.each(map, function(key, value) {
- alert(key + ': ' + value);
+$.each( obj, function( key, value ) {
+ alert( key + ": " + value );
});
Once again, this produces two messages:
@@ -79,4 +79,4 @@ $.each(map, function(key, value) {
Data that is sent to the server is appended to the URL as a query string. If the value of the data parameter is an object (map), it is converted to a string and url-encoded before it is appended to the URL.
Data that is sent to the server is appended to the URL as a query string. If the value of the data parameter is a plain object, it is converted to a string and url-encoded before it is appended to the URL.
Most implementations will specify a success handler:
$.getJSON('ajax/test.json', function(data) {
var items = [];
@@ -107,4 +107,4 @@ $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?
-
\ No newline at end of file
+
diff --git a/entries/jQuery.map.xml b/entries/jQuery.map.xml
index cd8d35b9..9f83e9ee 100644
--- a/entries/jQuery.map.xml
+++ b/entries/jQuery.map.xml
@@ -113,7 +113,7 @@ var dimensions = { width: 10, height: 15, length: 20 },
- Maps the original array to a new one; each element is squared.
+ Map the original array to a new one; each element is squared.
If necessary, you can free up the jQuery name as well by passing true 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 jQuery variable and may not operate correctly in this situation.
- Maps the original object that was referenced by $ back to $.
+ Map the original object that was referenced by $ back to $.