Jquery Documentation
Total Page:16
File Type:pdf, Size:1020Kb
JQuery Documentation Table of Contents Core jQuery.holdReady jQuery.when jQuery.sub jQuery.noConflict jQuery jQuery jQuery Selectors focus selected checked disabled enabled file button reset image submit checkbox radio password text input only-child last-child first-child nth-child attributeContainsPrefix attributeContainsWord attributeMultiple attributeContains attributeEndsWith attributeStartsWith attributeNotEqual attributeEquals attributeHas visible hidden parent has empty contains animated header lt gt eq odd even not last first next siblings next adjacent child descendant multiple all class element id Traversing has parentsUntil prevUntil nextUntil each first last slice end andSelf siblings prevAll prev parents parent offsetParent nextAll next find contents closest closest children add not map is eq filter Attributes removeProp prop prop val val html html toggleClass removeClass hasClass removeAttr attr attr addClass CSS jQuery.cssHooks outerWidth outerHeight innerWidth innerHeight width width height height scrollLeft scrollLeft scrollTop scrollTop position offset offset css css toggleClass: See Attributes - toggleClass removeClass: See Attributes - removeClass hasClass: See Attributes - hasClass addClass: See Attributes - addClass Manipulation removeProp: See Attributes - removeProp prop: See Attributes - prop prop: See Attributes - prop outerWidth: See CSS - outerWidth outerHeight: See CSS - outerHeight innerWidth: See CSS - innerWidth innerHeight: See CSS - innerHeight width: See CSS - width width: See CSS - width height: See CSS - height height: See CSS - height scrollLeft: See CSS - scrollLeft scrollLeft: See CSS - scrollLeft scrollTop: See CSS - scrollTop scrollTop: See CSS - scrollTop position: See CSS - position offset: See CSS - offset offset: See CSS - offset css: See CSS - css css: See CSS - css unwrap detach clone remove empty replaceAll replaceWith wrapInner wrapAll wrap insertBefore before insertAfter after prependTo prepend appendTo append val: See Attributes - val val: See Attributes - val text text html: See Attributes - html html: See Attributes - html toggleClass: See Attributes - toggleClass removeClass: See Attributes - removeClass hasClass: See Attributes - hasClass removeAttr: See Attributes - removeAttr attr: See Attributes - attr attr: See Attributes - attr addClass: See Attributes - addClass Data jQuery.hasData jQuery.removeData jQuery.data jQuery.data jQuery.dequeue jQuery.queue jQuery.queue clearQueue removeData data data dequeue queue queue Forms submit select change blur focus serializeArray serialize jQuery.param val: See Attributes - val val: See Attributes - val Events toggle event.namespace undelegate delegate jQuery.proxy focusout focusin event.isImmediatePropagationStopped event.stopImmediatePropagation event.isPropagationStopped event.stopPropagation event.isDefaultPrevented event.preventDefault event.timeStamp event.result event.which event.pageY event.pageX event.currentTarget event.relatedTarget event.data event.target event.type keydown scroll resize keyup keypress submit: See Forms - submit select: See Forms - select change: See Forms - change blur: See Forms - blur focus: See Forms - focus mousemove hover hover mouseleave mouseenter mouseout mouseover dblclick click mouseup mousedown error unload load ready die die live triggerHandler trigger one unbind bind Deferred Object deferred.pipe deferred.always promise deferred.promise jQuery.when: See Core - jQuery.when deferred.resolveWith deferred.rejectWith deferred.fail deferred.done deferred.then deferred.reject deferred.isRejected deferred.isResolved deferred.resolve Effects fadeToggle jQuery.fx.interval delay jQuery.fx.off clearQueue: See Data - clearQueue dequeue: See Data - dequeue queue: See Data - queue queue: See Data - queue stop animate fadeTo fadeOut fadeIn slideToggle slideUp slideDown toggle hide show Ajax jQuery.ajaxPrefilter ajaxComplete serializeArray: See Forms - serializeArray serialize: See Forms - serialize jQuery.ajaxSetup ajaxSuccess ajaxStop ajaxStart ajaxSend ajaxError jQuery.post jQuery.getScript jQuery.getJSON jQuery.get load jQuery.ajax jQuery.param: See Forms - jQuery.param Miscellaneous each: See Traversing - each toArray index removeData: See Data - removeData data: See Data - data data: See Data - data get size jQuery.noConflict: See Core - jQuery.noConflict jQuery.param: See Forms - jQuery.param Dimensions outerWidth: See CSS - outerWidth outerHeight: See CSS - outerHeight innerWidth: See CSS - innerWidth innerHeight: See CSS - innerHeight width: See CSS - width width: See CSS - width height: See CSS - height height: See CSS - height Offset offsetParent: See Traversing - offsetParent scrollLeft: See CSS - scrollLeft scrollLeft: See CSS - scrollLeft scrollTop: See CSS - scrollTop scrollTop: See CSS - scrollTop position: See CSS - position offset: See CSS - offset offset: See CSS - offset Utilities jQuery.now jQuery.parseXML jQuery.type jQuery.isWindow jQuery.parseJSON jQuery.proxy: See Events - jQuery.proxy jQuery.contains jQuery.noop jQuery.globalEval jQuery.isXMLDoc jQuery.removeData: See Data - jQuery.removeData jQuery.data: See Data - jQuery.data jQuery.data: See Data - jQuery.data jQuery.dequeue: See Data - jQuery.dequeue jQuery.queue: See Data - jQuery.queue jQuery.queue: See Data - jQuery.queue clearQueue: See Data - clearQueue jQuery.isEmptyObject jQuery.isPlainObject dequeue: See Data - dequeue queue: See Data - queue queue: See Data - queue jQuery.browser jQuery.browser.version jQuery.trim jQuery.isFunction jQuery.isArray jQuery.unique jQuery.merge jQuery.inArray jQuery.map jQuery.makeArray jQuery.grep jQuery.extend jQuery.each jQuery.boxModel jQuery.support Plugin Authoring Core jQuery.holdReady Holds or releases the execution of jQuery's ready event. jQuery.holdReady(hold):undefined Added in version 1.6 hold:Boolean Indicates whether the ready hold is being requested or released The $.holdReady() method allows the caller to delay jQuery's ready event. This advanced feature 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 <head> immediately after the jQuery script tag. Calling this method after the ready event has already fired will have no effect. To delay the ready event, first call $.holdReady(true). When the ready event should be released to execute, call $.holdReady(false). Note that multiple holds can be put on the ready event, one for each $.holdReady(true) call. The ready event will not actually fire until all holds have been released with a corresponding $.holdReady(false) and the normal document ready conditions are met. (See ready for more information.) Example 1: Delay the ready event until a custom plugin has loaded. Javascript $.holdReady(true); $.getScript("myplugin.js", function() { $.holdReady(false); }); jQuery.when Provides a way to execute callback functions based on one or more objects, usually Deferred objects that represent asynchronous events. jQuery.when(deferreds):Promise Added in version 1.5 deferreds:Deferred One or more Deferred objects, or plain JavaScript objects. If a single Deferred is passed to 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 Deferred and can be used this way: $.when( $.ajax("test.aspx") ).then(function(ajaxArgs){ alert(ajaxArgs[1]); /* ajaxArgs is [ "success", statusText, jqXHR ] */ }); If a single argument is passed to 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: $.when( { testing: 123 } ).done( function(x){ alert(x.testing); } /* alerts "123" */ ); In the case where multiple Deferred objects are passed to 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, it is passed the resolved values of all the Deferreds that were passed to jQuery.when. For example, when the Deferreds are jQuery.ajax() requests, the arguments will be the jqXHR objects for the requests, in the order they were given in the argument list. In the multiple-Deferreds case where one of the Deferreds is rejected, jQuery.when immediately fires the failCallbacks for its master Deferred. Note that some of the Deferreds may still be unresolved at that point. 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. Example 1: 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). Javascript $.when($.ajax("/page1.php"),