2 * jQuery - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
18 * @test ok( Array.prototype.push, "Array.push()" );
19 * @test ok( Function.prototype.apply, "Function.apply()" );
20 * @test ok( document.getElementById, "getElementById" );
21 * @test ok( document.getElementsByTagName, "getElementsByTagName" );
22 * @test ok( RegExp, "RegExp" );
23 * @test ok( jQuery, "jQuery" );
24 * @test ok( $, "$()" );
30 function jQuery(a,c) {
32 // Shortcut for document ready (because $(document).each() is silly)
33 if ( a && a.constructor == Function && jQuery.fn.ready )
34 return jQuery(document).ready(a);
36 // Make sure that a selection was provided
37 a = a || jQuery.context || document;
39 // Watch for when a jQuery object is passed as the selector
41 return jQuery( jQuery.merge( a, [] ) );
43 // Watch for when a jQuery object is passed at the context
45 return jQuery( c ).find(a);
47 // If the context is global, return a new object
49 return new jQuery(a,c);
51 // Handle HTML strings
52 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
53 if ( m ) a = jQuery.clean( [ m[1] ] );
55 // Watch for when an array is passed in
56 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
57 // Assume that it is an array of DOM Elements
58 jQuery.merge( a, [] ) :
60 // Find the matching elements and save them for later
61 jQuery.find( a, c ) );
63 // See if an extra function was provided
64 var fn = arguments[ arguments.length - 1 ];
66 // If so, execute it in context
67 if ( fn && fn.constructor == Function )
71 // Map over the $ in case of overwrite
72 if ( typeof $ != "undefined" )
76 * This function accepts a string containing a CSS selector,
77 * basic XPath, or raw HTML, which is then used to match a set of elements.
78 * The HTML string is different from the traditional selectors in that
79 * it creates the DOM elements representing that HTML string, on the fly,
80 * to be (assumedly) inserted into the document later.
82 * The core functionality of jQuery centers around this function.
83 * Everything in jQuery is based upon this, or uses this in some way.
84 * The most basic use of this function is to pass in an expression
85 * (usually consisting of CSS or XPath), which then finds all matching
86 * elements and remembers them for later use.
88 * By default, $() looks for DOM elements within the context of the
89 * current HTML document.
91 * @example $("div > p")
92 * @desc This finds all p elements that are children of a div element.
93 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
94 * @result [ <p>two</p> ]
96 * @example $("<div><p>Hello</p></div>").appendTo("#body")
97 * @desc Creates a div element (and all of its contents) dynamically, and appends it to the element with the ID of body.
100 * @param String expr An expression to search with, or a string of HTML to create on the fly.
106 * This function accepts a string containing a CSS selector, or
107 * basic XPath, which is then used to match a set of elements with the
108 * context of the specified DOM element, or document
110 * @example $("div", xml.responseXML)
111 * @desc This finds all div elements within the specified XML document.
114 * @param String expr An expression to search with.
115 * @param DOMElement context A DOM Element, or Document, representing the base context.
121 * Wrap jQuery functionality around a specific DOM Element.
122 * This function also accepts XML Documents and Window objects
123 * as valid arguments (even though they are not DOM Elements).
125 * @example $(document).find("div > p")
126 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
127 * @result [ <p>two</p> ]
129 * @example $(document).ready( loaded );
130 * @desc Executes the "loaded" function when the DOM is ready to
134 * @param DOMElement elem A DOM element to be encapsulated by a jQuery object.
140 * Wrap jQuery functionality around a set of DOM Elements.
142 * @example $( myForm.elements ).hide()
143 * @desc Hides all the input elements within a form
146 * @param Array<DOMElement> elems An array of DOM elements to be encapsulated by a jQuery object.
152 * A shorthand for $(document).ready(), allowing you to bind a function
153 * to be executed when the DOM document has finished loading.
155 * @example $( loaded )
156 * @desc Executes the function "loaded" when the DOM is ready to be used.
159 * @param Function fn The function to execute when the DOM is ready.
165 * A means of creating a duplicate copy of a jQuery object.
167 * @example var div = $("div");
169 * @desc Locates all p elements with all div elements, without disrupting the original jQuery object contained in 'div'.
172 * @param jQuery obj The jQuery object to be cloned.
177 // Map the jQuery namespace to the '$' one
180 jQuery.fn = jQuery.prototype = {
182 * The current SVN version of jQuery.
193 * The number of elements currently matched.
195 * @example $("img").length;
196 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
199 * @test cmpOK( $("div").length, "==", 2, "Get Number of Elements Found" );
208 * The number of elements currently matched.
210 * @example $("img").size();
211 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
214 * @test cmpOK( $("div").size(), "==", 2, "Get Number of Elements Found" );
225 * Access all matched elements. This serves as a backwards-compatible
226 * way of accessing all matched elements (other than the jQuery object
227 * itself, which is, in fact, an array of elements).
229 * @example $("img").get();
230 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
231 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
233 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
236 * @type Array<Element>
241 * Access a single matched element. num is used to access the
242 * Nth element matched.
244 * @example $("img").get(1);
245 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
246 * @result [ <img src="test1.jpg"/> ]
248 * @test cmpOK( $("div").get(0), "==", document.getElementById("main"), "Get A Single Element" );
252 * @param Number num Access the element in the Nth position.
257 * Set the jQuery object to an array of elements.
259 * @example $("img").get([ document.body ]);
260 * @result $("img").get() == [ document.body ]
265 * @param Elements elems An array of elements
268 get: function( num ) {
269 // Watch for when an array (of elements) is passed in
270 if ( num && num.constructor == Array ) {
272 // Use a tricky hack to make the jQuery object
273 // look and feel like an array
275 [].push.apply( this, num );
279 return num == undefined ?
281 // Return a 'clean' array
282 jQuery.map( this, function(a){ return a } ) :
284 // Return just the object
289 * Execute a function within the context of every matched element.
290 * This means that every time the passed-in function is executed
291 * (which is once for every element matched) the 'this' keyword
292 * points to the specific element.
294 * Additionally, the function, when executed, is passed a single
295 * argument representing the position of the element in the matched
298 * @example $("img").each(function(){
299 * this.src = "test.jpg";
301 * @before <img/> <img/>
302 * @result <img src="test.jpg"/> <img src="test.jpg"/>
304 * @example $("img").each(function(i){
305 * alert( "Image #" + i + " is " + this );
307 * @before <img/> <img/>
308 * @result <img src="test.jpg"/> <img src="test.jpg"/>
310 * @test var div = $("div");
311 * div.each(function(){this.foo = 'zoo';});
313 * for ( var i = 0; i < div.size(); i++ ) {
314 * if ( div.get(i).foo != "zoo" ) pass = false;
316 * ok( pass, "Execute a function, Relative" );
320 * @param Function fn A function to execute
323 each: function( fn, args ) {
324 return jQuery.each( this, fn, args );
327 index: function( obj ) {
329 this.each(function(i){
330 if ( this == obj ) pos = i;
336 * Access a property on the first matched element.
337 * This method makes it easy to retreive a property value
338 * from the first matched element.
340 * @example $("img").attr("src");
341 * @before <img src="test.jpg"/>
346 * @param String name The name of the property to access.
351 * Set a hash of key/value object properties to all matched elements.
352 * This serves as the best way to set a large number of properties
353 * on all matched elements.
355 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
357 * @result <img src="test.jpg" alt="Test Image"/>
359 * @test var pass = true;
360 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
361 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
363 * ok( pass, "Set Multiple Attributes" );
367 * @param Hash prop A set of key/value pairs to set as object properties.
372 * Set a single property to a value, on all matched elements.
374 * @example $("img").attr("src","test.jpg");
376 * @result <img src="test.jpg"/>
378 * @test var div = $("div");
379 * div.attr("foo", "bar");
381 * for ( var i = 0; i < div.size(); i++ ) {
382 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
384 * ok( pass, "Set Attribute" );
388 * @param String key The name of the property to set.
389 * @param Object value The value to set the property to.
392 attr: function( key, value, type ) {
393 // Check to see if we're setting style values
394 return key.constructor != String || value != undefined ?
395 this.each(function(){
396 // See if we're setting a hash of styles
397 if ( value == undefined )
398 // Set all the styles
399 for ( var prop in key )
401 type ? this.style : this,
405 // See if we're setting a single key/value style
408 type ? this.style : this,
413 // Look for the case where we're accessing a style value
414 jQuery[ type || "attr" ]( this[0], key );
418 * Access a style property on the first matched element.
419 * This method makes it easy to retreive a style property value
420 * from the first matched element.
422 * @example $("p").css("red");
423 * @before <p style="color:red;">Test Paragraph.</p>
428 * @param String name The name of the property to access.
433 * Set a hash of key/value style properties to all matched elements.
434 * This serves as the best way to set a large number of style properties
435 * on all matched elements.
437 * @example $("p").css({ color: "red", background: "blue" });
438 * @before <p>Test Paragraph.</p>
439 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
443 * @param Hash prop A set of key/value pairs to set as style properties.
448 * Set a single style property to a value, on all matched elements.
450 * @example $("p").css("color","red");
451 * @before <p>Test Paragraph.</p>
452 * @result <p style="color:red;">Test Paragraph.</p>
456 * @param String key The name of the property to set.
457 * @param Object value The value to set the property to.
460 css: function( key, value ) {
461 return this.attr( key, value, "curCSS" );
465 * Retreive the text contents of all matched elements. The result is
466 * a string that contains the combined text contents of all matched
467 * elements. This method works on both HTML and XML documents.
469 * @example $("p").text();
470 * @before <p>Test Paragraph.</p>
471 * @result Test Paragraph.
480 for ( var j = 0; j < e.length; j++ ) {
481 var r = e[j].childNodes;
482 for ( var i = 0; i < r.length; i++ )
483 if ( r[i].nodeType != 8 )
484 t += r[i].nodeType != 1 ?
485 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
491 * Wrap all matched elements with a structure of other elements.
492 * This wrapping process is most useful for injecting additional
493 * stucture into a document, without ruining the original semantic
494 * qualities of a document.
496 * The way that is works is that it goes through the first element argument
497 * provided and finds the deepest element within the structure - it is that
498 * element that will en-wrap everything else.
500 * @example $("p").wrap("<div class='wrap'></div>");
501 * @before <p>Test Paragraph.</p>
502 * @result <div class='wrap'><p>Test Paragraph.</p></div>
506 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
507 * @any Element elem A DOM element that will be wrapped.
508 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
509 * @any Object obj Any object, converted to a string, then a text node.
510 * @cat DOM/Manipulation
513 // The elements to wrap the target around
514 var a = jQuery.clean(arguments);
516 // Wrap each of the matched elements individually
517 return this.each(function(){
518 // Clone the structure that we're using to wrap
519 var b = a[0].cloneNode(true);
521 // Insert it before the element to be wrapped
522 this.parentNode.insertBefore( b, this );
524 // Find he deepest point in the wrap structure
525 while ( b.firstChild )
528 // Move the matched element to within the wrap structure
529 b.appendChild( this );
534 * Append any number of elements to the inside of all matched elements.
535 * This operation is similar to doing an appendChild to all the
536 * specified elements, adding them into the document.
538 * @example $("p").append("<b>Hello</b>");
539 * @before <p>I would like to say: </p>
540 * @result <p>I would like to say: <b>Hello</b></p>
544 * @any String html A string of HTML, that will be created on the fly and appended to the target.
545 * @any Element elem A DOM element that will be appended.
546 * @any Array<Element> elems An array of elements, all of which will be appended.
547 * @any Object obj Any object, converted to a string, then a text node.
548 * @cat DOM/Manipulation
551 return this.domManip(arguments, true, 1, function(a){
552 this.appendChild( a );
557 * Prepend any number of elements to the inside of all matched elements.
558 * This operation is the best way to insert a set of elements inside, at the
559 * beginning, of all the matched element.
561 * @example $("p").prepend("<b>Hello</b>");
562 * @before <p>, how are you?</p>
563 * @result <p><b>Hello</b>, how are you?</p>
567 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
568 * @any Element elem A DOM element that will be prepended.
569 * @any Array<Element> elems An array of elements, all of which will be prepended.
570 * @any Object obj Any object, converted to a string, then a text node.
571 * @cat DOM/Manipulation
573 prepend: function() {
574 return this.domManip(arguments, true, -1, function(a){
575 this.insertBefore( a, this.firstChild );
580 * Insert any number of elements before each of the matched elements.
582 * @example $("p").before("<b>Hello</b>");
583 * @before <p>how are you?</p>
584 * @result <b>Hello</b><p>how are you?</p>
588 * @any String html A string of HTML, that will be created on the fly and inserted.
589 * @any Element elem A DOM element that will beinserted.
590 * @any Array<Element> elems An array of elements, all of which will be inserted.
591 * @any Object obj Any object, converted to a string, then a text node.
592 * @cat DOM/Manipulation
595 return this.domManip(arguments, false, 1, function(a){
596 this.parentNode.insertBefore( a, this );
601 * Insert any number of elements after each of the matched elements.
603 * @example $("p").after("<p>I'm doing fine.</p>");
604 * @before <p>How are you?</p>
605 * @result <p>How are you?</p><p>I'm doing fine.</p>
609 * @any String html A string of HTML, that will be created on the fly and inserted.
610 * @any Element elem A DOM element that will beinserted.
611 * @any Array<Element> elems An array of elements, all of which will be inserted.
612 * @any Object obj Any object, converted to a string, then a text node.
613 * @cat DOM/Manipulation
616 return this.domManip(arguments, false, -1, function(a){
617 this.parentNode.insertBefore( a, this.nextSibling );
622 * End the most recent 'destructive' operation, reverting the list of matched elements
623 * back to its previous state. After an end operation, the list of matched elements will
624 * revert to the last state of matched elements.
626 * @example $("p").find("span").end();
627 * @before <p><span>Hello</span>, how are you?</p>
628 * @result $("p").find("span").end() == [ <p>...</p> ]
632 * @cat DOM/Traversing
635 return this.get( this.stack.pop() );
639 * Searches for all elements that match the specified expression.
640 * This method is the optimal way of finding additional descendant
641 * elements with which to process.
643 * All searching is done using a jQuery expression. The expression can be
644 * written using CSS 1-3 Selector syntax, or basic XPath.
646 * @example $("p").find("span");
647 * @before <p><span>Hello</span>, how are you?</p>
648 * @result $("p").find("span") == [ <span>Hello</span> ]
652 * @param String expr An expression to search with.
653 * @cat DOM/Traversing
656 return this.pushStack( jQuery.map( this, function(a){
657 return jQuery.find(t,a);
661 clone: function(deep) {
662 return this.pushStack( jQuery.map( this, function(a){
663 return a.cloneNode( deep != undefined ? deep : true );
668 * Removes all elements from the set of matched elements that do not
669 * match the specified expression. This method is used to narrow down
670 * the results of a search.
672 * All searching is done using a jQuery expression. The expression
673 * can be written using CSS 1-3 Selector syntax, or basic XPath.
675 * @example $("p").filter(".selected")
676 * @before <p class="selected">Hello</p><p>How are you?</p>
677 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
681 * @param String expr An expression to search with.
682 * @cat DOM/Traversing
686 * Removes all elements from the set of matched elements that do not
687 * match at least one of the expressions passed to the function. This
688 * method is used when you want to filter the set of matched elements
689 * through more than one expression.
691 * Elements will be retained in the jQuery object if they match at
692 * least one of the expressions passed.
694 * @example $("p").filter([".selected", ":first"])
695 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
696 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
700 * @param Array<String> exprs A set of expressions to evaluate against
701 * @cat DOM/Traversing
703 filter: function(t) {
704 return this.pushStack(
705 t.constructor == Array &&
706 jQuery.map(this,function(a){
707 for ( var i = 0; i < t.length; i++ )
708 if ( jQuery.filter(t[i],[a]).r.length )
712 t.constructor == Boolean &&
713 ( t ? this.get() : [] ) ||
715 t.constructor == Function &&
716 jQuery.grep( this, t ) ||
718 jQuery.filter(t,this).r, arguments );
722 * Removes the specified Element from the set of matched elements. This
723 * method is used to remove a single Element from a jQuery object.
725 * @example $("p").not( document.getElementById("selected") )
726 * @before <p>Hello</p><p id="selected">Hello Again</p>
727 * @result [ <p>Hello</p> ]
731 * @param Element el An element to remove from the set
732 * @cat DOM/Traversing
736 * Removes elements matching the specified expression from the set
737 * of matched elements. This method is used to remove one or more
738 * elements from a jQuery object.
740 * @example $("p").not("#selected")
741 * @before <p>Hello</p><p id="selected">Hello Again</p>
742 * @result [ <p>Hello</p> ]
743 * @test cmpOK($("#main > p#ap > a").not("#google").length, "==", 2, ".not")
747 * @param String expr An expression with which to remove matching elements
748 * @cat DOM/Traversing
751 return this.pushStack( t.constructor == String ?
752 jQuery.filter(t,this,false).r :
753 jQuery.grep(this,function(a){ return a != t; }), arguments );
757 * Adds the elements matched by the expression to the jQuery object. This
758 * can be used to concatenate the result sets of two expressions.
760 * @example $("p").add("span")
761 * @before <p>Hello</p><p><span>Hello Again</span></p>
762 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
766 * @param String expr An expression whose matched elements are added
767 * @cat DOM/Traversing
771 * Adds each of the Elements in the array to the set of matched elements.
772 * This is used to add a set of Elements to a jQuery object.
774 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
775 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
776 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
780 * @param Array<Element> els An array of Elements to add
781 * @cat DOM/Traversing
785 * Adds a single Element to the set of matched elements. This is used to
786 * add a single Element to a jQuery object.
788 * @example $("p").add( document.getElementById("a") )
789 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
790 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
794 * @param Element el An Element to add
795 * @cat DOM/Traversing
798 return this.pushStack( jQuery.merge( this, t.constructor == String ?
799 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
803 * A wrapper function for each() to be used by append and prepend.
804 * Handles cases where you're trying to modify the inner contents of
805 * a table, when you actually need to work with the tbody.
808 * @param {String} expr The expression with which to filter
810 * @cat DOM/Traversing
813 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
822 * @param Boolean table
824 * @param Function fn The function doing the DOM manipulation.
827 domManip: function(args, table, dir, fn){
828 var clone = this.size() > 1;
829 var a = jQuery.clean(args);
831 return this.each(function(){
834 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
835 var tbody = this.getElementsByTagName("tbody");
837 if ( !tbody.length ) {
838 obj = document.createElement("tbody");
839 this.appendChild( obj );
844 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
845 i != ( dir < 0 ? dir : a.length ); i += dir ) {
846 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
860 pushStack: function(a,args) {
861 var fn = args && args[args.length-1];
863 if ( !fn || fn.constructor != Function ) {
864 if ( !this.stack ) this.stack = [];
865 this.stack.push( this.get() );
868 var old = this.get();
870 if ( fn.constructor == Function )
890 * Extend one object with another, returning the original,
891 * modified, object. This is a great utility for simple inheritance.
893 * @name jQuery.extend
894 * @param Object obj The object to extend
895 * @param Object prop The object that will be merged into the first.
899 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
900 if ( !prop ) { prop = obj; obj = this; }
901 for ( var i in prop ) obj[i] = prop[i];
912 jQuery.initDone = true;
914 jQuery.each( jQuery.macros.axis, function(i,n){
915 jQuery.fn[ i ] = function(a) {
916 var ret = jQuery.map(this,n);
917 if ( a && a.constructor == String )
918 ret = jQuery.filter(a,ret).r;
919 return this.pushStack( ret, arguments );
923 jQuery.each( jQuery.macros.to, function(i,n){
924 jQuery.fn[ i ] = function(){
926 return this.each(function(){
927 for ( var j = 0; j < a.length; j++ )
928 jQuery(a[j])[n]( this );
933 jQuery.each( jQuery.macros.each, function(i,n){
934 jQuery.fn[ i ] = function() {
935 return this.each( n, arguments );
939 jQuery.each( jQuery.macros.filter, function(i,n){
940 jQuery.fn[ n ] = function(num,fn) {
941 return this.filter( ":" + n + "(" + num + ")", fn );
945 jQuery.each( jQuery.macros.attr, function(i,n){
947 jQuery.fn[ i ] = function(h) {
948 return h == undefined ?
949 this.length ? this[0][n] : null :
954 jQuery.each( jQuery.macros.css, function(i,n){
955 jQuery.fn[ n ] = function(h) {
956 return h == undefined ?
957 ( this.length ? jQuery.css( this[0], n ) : null ) :
965 * A generic iterator function, which can be used to seemlessly
966 * iterate over both objects and arrays.
969 * @param Object obj The object, or array, to iterate over.
970 * @param Object fn The function that will be executed on every object.
974 each: function( obj, fn, args ) {
975 if ( obj.length == undefined )
977 fn.apply( obj[i], args || [i, obj[i]] );
979 for ( var i = 0; i < obj.length; i++ )
980 fn.apply( obj[i], args || [i, obj[i]] );
986 if (jQuery.className.has(o,c)) return;
987 o.className += ( o.className ? " " : "" ) + c;
989 remove: function(o,c){
990 o.className = !c ? "" :
992 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
995 if ( e.className != undefined )
997 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1002 * Swap in/out style options.
1005 swap: function(e,o,f) {
1006 for ( var i in o ) {
1007 e.style["old"+i] = e.style[i];
1012 e.style[i] = e.style["old"+i];
1015 css: function(e,p) {
1016 if ( p == "height" || p == "width" ) {
1017 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1019 for ( var i in d ) {
1020 old["padding" + d[i]] = 0;
1021 old["border" + d[i] + "Width"] = 0;
1024 jQuery.swap( e, old, function() {
1025 if (jQuery.css(e,"display") != "none") {
1026 oHeight = e.offsetHeight;
1027 oWidth = e.offsetWidth;
1029 e = jQuery(e.cloneNode(true)).css({
1030 visibility: "hidden", position: "absolute", display: "block"
1031 }).appendTo(e.parentNode)[0];
1033 oHeight = e.clientHeight;
1034 oWidth = e.clientWidth;
1036 e.parentNode.removeChild(e);
1040 return p == "height" ? oHeight : oWidth;
1041 } else if ( p == "opacity" && jQuery.browser.msie )
1042 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
1044 return jQuery.curCSS( e, p );
1047 curCSS: function(elem, prop, force) {
1050 if (!force && elem.style[prop]) {
1052 ret = elem.style[prop];
1054 } else if (elem.currentStyle) {
1056 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
1057 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1059 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1061 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1062 var cur = document.defaultView.getComputedStyle(elem, null);
1065 ret = cur.getPropertyValue(prop);
1066 else if ( prop == 'display' )
1069 jQuery.swap(elem, { display: 'block' }, function() {
1070 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1078 clean: function(a) {
1080 for ( var i = 0; i < a.length; i++ ) {
1081 if ( a[i].constructor == String ) {
1085 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1087 a[i] = "<table>" + a[i] + "</table>";
1088 } else if ( !a[i].indexOf("<tr") ) {
1090 a[i] = "<table>" + a[i] + "</table>";
1091 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1093 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1096 var div = document.createElement("div");
1097 div.innerHTML = a[i];
1100 div = div.firstChild;
1101 if ( table != "thead" ) div = div.firstChild;
1102 if ( table == "td" ) div = div.firstChild;
1105 for ( var j = 0; j < div.childNodes.length; j++ )
1106 r.push( div.childNodes[j] );
1107 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1108 for ( var k = 0; k < a[i].length; k++ )
1110 else if ( a[i] !== null )
1111 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1117 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1118 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1126 last: "i==r.length-1",
1131 "nth-child": "jQuery.sibling(a,m[3]).cur",
1132 "first-child": "jQuery.sibling(a,0).cur",
1133 "last-child": "jQuery.sibling(a,0).last",
1134 "only-child": "jQuery.sibling(a).length==1",
1137 parent: "a.childNodes.length",
1138 empty: "!a.childNodes.length",
1141 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1144 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1145 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1148 enabled: "!a.disabled",
1149 disabled: "a.disabled",
1150 checked: "a.checked",
1151 selected: "a.selected"
1153 ".": "jQuery.className.has(a,m[2])",
1157 "^=": "!z.indexOf(m[4])",
1158 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1159 "*=": "z.indexOf(m[4])>=0",
1162 "[": "jQuery.find(m[2],a).length"
1166 "\\.\\.|/\\.\\.", "a.parentNode",
1167 ">|/", "jQuery.sibling(a.firstChild)",
1168 "\\+", "jQuery.sibling(a).next",
1171 var s = jQuery.sibling(a);
1173 for ( var i = s.n; i < s.length; i++ )
1181 * @test t( "Element Selector", "div", ["main","foo"] );
1182 * @test t( "Element Selector", "body", ["body"] );
1183 * @test t( "Element Selector", "html", ["html"] );
1184 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1185 * @test t( "Parent Element", "div div", ["foo"] );
1187 * @test t( "ID Selector", "#body", ["body"] );
1188 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1189 * @test t( "ID Selector w/ Element", "ul#first", [] );
1191 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1192 * @test t( "Class Selector", ".blog.link", ["simon"] );
1193 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1194 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1196 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1197 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1198 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1199 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1201 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1202 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1203 * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1204 * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1205 * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1206 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1207 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1208 * @test t( "Adjacent", "a + a", ["groups"] );
1209 * @test t( "Adjacent", "a +a", ["groups"] );
1210 * @test t( "Adjacent", "a+ a", ["groups"] );
1211 * @test t( "Adjacent", "a+a", ["groups"] );
1212 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1213 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1214 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1215 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1216 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1217 * @test t( "Attribute Exists", "[@title]", ["google"] );
1218 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1219 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1220 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1221 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1222 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1223 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1225 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1226 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1227 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1228 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1229 * @test t( "Last Child", "p:last-child", ["sap"] );
1230 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1231 * @test t( "Empty", "ul:empty", ["firstUL"] );
1232 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1233 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1234 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1235 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1236 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1237 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1238 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1240 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1241 * @test t( "All Div Elements", "//div", ["main","foo"] );
1242 * @test t( "Absolute Path", "/html/body", ["body"] );
1243 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1244 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1245 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1246 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1247 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1248 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1249 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1250 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1251 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1252 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1253 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1255 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1256 * @test t( "First Element", "p:first", ["firstp"] );
1257 * @test t( "Last Element", "p:last", ["first"] );
1258 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1259 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1260 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1261 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1262 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1263 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1264 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1265 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1270 find: function( t, context ) {
1271 // Make sure that the context is a DOM Element
1272 if ( context && context.nodeType == undefined )
1275 // Set the correct context (if none is provided)
1276 context = context || jQuery.context || document;
1278 if ( t.constructor != String ) return [t];
1280 if ( !t.indexOf("//") ) {
1281 context = context.documentElement;
1282 t = t.substr(2,t.length);
1283 } else if ( !t.indexOf("/") ) {
1284 context = context.documentElement;
1285 t = t.substr(1,t.length);
1286 // FIX Assume the root element is right :(
1287 if ( t.indexOf("/") >= 1 )
1288 t = t.substr(t.indexOf("/"),t.length);
1291 var ret = [context];
1295 while ( t.length > 0 && last != t ) {
1299 t = jQuery.trim(t).replace( /^\/\//i, "" );
1301 var foundToken = false;
1303 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1304 if ( foundToken ) continue;
1306 var re = new RegExp("^(" + jQuery.token[i] + ")");
1310 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1311 t = jQuery.trim( t.replace( re, "" ) );
1316 if ( !foundToken ) {
1317 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1318 if ( ret[0] == context ) ret.shift();
1319 done = jQuery.merge( done, ret );
1320 r = ret = [context];
1321 t = " " + t.substr(1,t.length);
1323 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1324 var m = re2.exec(t);
1326 if ( m[1] == "#" ) {
1327 // Ummm, should make this work in all XML docs
1328 var oid = document.getElementById(m[2]);
1329 r = ret = oid ? [oid] : [];
1330 t = t.replace( re2, "" );
1332 if ( !m[2] || m[1] == "." ) m[2] = "*";
1334 for ( var i = 0; i < ret.length; i++ )
1335 r = jQuery.merge( r,
1337 jQuery.getAll(ret[i]) :
1338 ret[i].getElementsByTagName(m[2])
1346 var val = jQuery.filter(t,r);
1348 t = jQuery.trim(val.t);
1352 if ( ret && ret[0] == context ) ret.shift();
1353 done = jQuery.merge( done, ret );
1358 getAll: function(o,r) {
1360 var s = o.childNodes;
1361 for ( var i = 0; i < s.length; i++ )
1362 if ( s[i].nodeType == 1 ) {
1364 jQuery.getAll( s[i], r );
1369 attr: function(elem, name, value){
1372 "class": "className",
1373 "float": "cssFloat",
1374 innerHTML: "innerHTML",
1375 className: "className",
1377 disabled: "disabled"
1381 if ( value != undefined ) elem[fix[name]] = value;
1382 return elem[fix[name]];
1383 } else if ( elem.getAttribute ) {
1384 if ( value != undefined ) elem.setAttribute( name, value );
1385 return elem.getAttribute( name, 2 );
1387 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1388 if ( value != undefined ) elem[name] = value;
1393 // The regular expressions that power the parsing engine
1395 // Match: [@value='test'], [@foo]
1396 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1398 // Match: [div], [div p]
1401 // Match: :contains('foo')
1402 [ "(:)S\\(Q\\)", 0 ],
1404 // Match: :even, :last-chlid
1408 filter: function(t,r,not) {
1409 // Figure out if we're doing regular, or inverse, filtering
1410 var g = not !== false ? jQuery.grep :
1411 function(a,f) {return jQuery.grep(a,f,true);};
1413 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1415 var p = jQuery.parse;
1417 for ( var i = 0; i < p.length; i++ ) {
1418 var re = new RegExp( "^" + p[i][0]
1420 // Look for a string-like sequence
1421 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1423 // Look for something (optionally) enclosed with quotes
1424 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1426 var m = re.exec( t );
1429 // Re-organize the match
1431 m = ["", m[1], m[3], m[2], m[4]];
1433 // Remove what we just matched
1434 t = t.replace( re, "" );
1440 // :not() is a special case that can be optomized by
1441 // keeping it out of the expression list
1442 if ( m[1] == ":" && m[2] == "not" )
1443 r = jQuery.filter(m[3],r,false).r;
1445 // Otherwise, find the expression to execute
1447 var f = jQuery.expr[m[1]];
1448 if ( f.constructor != String )
1449 f = jQuery.expr[m[1]][m[2]];
1451 // Build a custom macro to enclose it
1452 eval("f = function(a,i){" +
1453 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1454 "return " + f + "}");
1456 // Execute it against the current filter
1461 // Return an array of filtered elements (r)
1462 // and the modified expression string (t)
1463 return { r: r, t: t };
1467 * Remove the whitespace from the beginning and end of a string.
1472 * @param String str The string to trim.
1475 return t.replace(/^\s+|\s+$/g, "");
1479 * All ancestors of a given element.
1482 * @name jQuery.parents
1483 * @type Array<Element>
1484 * @param Element elem The element to find the ancestors of.
1486 parents: function( elem ){
1488 var cur = elem.parentNode;
1489 while ( cur && cur != document ) {
1490 matched.push( cur );
1491 cur = cur.parentNode;
1497 * All elements on a specified axis.
1500 * @name jQuery.sibling
1502 * @param Element elem The element to find all the siblings of (including itself).
1504 sibling: function(elem, pos, not) {
1507 var siblings = elem.parentNode.childNodes;
1508 for ( var i = 0; i < siblings.length; i++ ) {
1509 if ( not === true && siblings[i] == elem ) continue;
1511 if ( siblings[i].nodeType == 1 )
1512 elems.push( siblings[i] );
1513 if ( siblings[i] == elem )
1514 elems.n = elems.length - 1;
1517 return jQuery.extend( elems, {
1518 last: elems.n == elems.length - 1,
1519 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1520 prev: elems[elems.n - 1],
1521 next: elems[elems.n + 1]
1526 * Merge two arrays together, removing all duplicates.
1529 * @name jQuery.merge
1531 * @param Array a The first array to merge.
1532 * @param Array b The second array to merge.
1534 merge: function(first, second) {
1537 // Move b over to the new array (this helps to avoid
1538 // StaticNodeList instances)
1539 for ( var k = 0; k < first.length; k++ )
1540 result[k] = first[k];
1542 // Now check for duplicates between a and b and only
1543 // add the unique items
1544 for ( var i = 0; i < second.length; i++ ) {
1545 var noCollision = true;
1547 // The collision-checking process
1548 for ( var j = 0; j < first.length; j++ )
1549 if ( second[i] == first[j] )
1550 noCollision = false;
1552 // If the item is unique, add it
1554 result.push( second[i] );
1561 * Remove items that aren't matched in an array. The function passed
1562 * in to this method will be passed two arguments: 'a' (which is the
1563 * array item) and 'i' (which is the index of the item in the array).
1568 * @param Array array The Array to find items in.
1569 * @param Function fn The function to process each item against.
1570 * @param Boolean inv Invert the selection - select the opposite of the function.
1572 grep: function(elems, fn, inv) {
1573 // If a string is passed in for the function, make a function
1574 // for it (a handy shortcut)
1575 if ( fn.constructor == String )
1576 fn = new Function("a","i","return " + fn);
1580 // Go through the array, only saving the items
1581 // that pass the validator function
1582 for ( var i = 0; i < elems.length; i++ )
1583 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1584 result.push( elems[i] );
1590 * Translate all items in array to another array of items. The translation function
1591 * that is provided to this method is passed one argument: 'a' (the item to be
1592 * translated). If an array is returned, that array is mapped out and merged into
1593 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1594 * from the array. Both of these changes imply that the size of the array may not
1595 * be the same size upon completion, as it was when it started.
1600 * @param Array array The Array to translate.
1601 * @param Function fn The function to process each item against.
1603 map: function(elems, fn) {
1604 // If a string is passed in for the function, make a function
1605 // for it (a handy shortcut)
1606 if ( fn.constructor == String )
1607 fn = new Function("a","return " + fn);
1611 // Go through the array, translating each of the items to their
1612 // new value (or values).
1613 for ( var i = 0; i < elems.length; i++ ) {
1614 var val = fn(elems[i],i);
1616 if ( val !== null && val != undefined ) {
1617 if ( val.constructor != Array ) val = [val];
1618 result = jQuery.merge( result, val );
1626 * A number of helper functions used for managing events.
1627 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1631 // Bind an event to an element
1632 // Original by Dean Edwards
1633 add: function(element, type, handler) {
1634 // For whatever reason, IE has trouble passing the window object
1635 // around, causing it to be cloned in the process
1636 if ( jQuery.browser.msie && element.setInterval != undefined )
1639 // Make sure that the function being executed has a unique ID
1640 if ( !handler.guid )
1641 handler.guid = this.guid++;
1643 // Init the element's event structure
1644 if (!element.events)
1645 element.events = {};
1647 // Get the current list of functions bound to this event
1648 var handlers = element.events[type];
1650 // If it hasn't been initialized yet
1652 // Init the event handler queue
1653 handlers = element.events[type] = {};
1655 // Remember an existing handler, if it's already there
1656 if (element["on" + type])
1657 handlers[0] = element["on" + type];
1660 // Add the function to the element's handler list
1661 handlers[handler.guid] = handler;
1663 // And bind the global event handler to the element
1664 element["on" + type] = this.handle;
1666 // Remember the function in a global list (for triggering)
1667 if (!this.global[type])
1668 this.global[type] = [];
1669 this.global[type].push( element );
1675 // Detach an event or set of events from an element
1676 remove: function(element, type, handler) {
1678 if (type && element.events[type])
1680 delete element.events[type][handler.guid];
1682 for ( var i in element.events[type] )
1683 delete element.events[type][i];
1685 for ( var j in element.events )
1686 this.remove( element, j );
1689 trigger: function(type,data,element) {
1690 // Touch up the incoming data
1693 // Handle a global trigger
1695 var g = this.global[type];
1697 for ( var i = 0; i < g.length; i++ )
1698 this.trigger( type, data, g[i] );
1700 // Handle triggering a single element
1701 } else if ( element["on" + type] ) {
1702 // Pass along a fake event
1703 data.unshift( this.fix({ type: type, target: element }) );
1705 // Trigger the event
1706 element["on" + type].apply( element, data );
1710 handle: function(event) {
1711 if ( typeof jQuery == "undefined" ) return;
1713 event = event || jQuery.event.fix( window.event );
1715 // If no correct event was found, fail
1716 if ( !event ) return;
1718 var returnValue = true;
1720 var c = this.events[event.type];
1722 for ( var j in c ) {
1723 if ( c[j].apply( this, [event] ) === false ) {
1724 event.preventDefault();
1725 event.stopPropagation();
1726 returnValue = false;
1733 fix: function(event) {
1735 event.preventDefault = function() {
1736 this.returnValue = false;
1739 event.stopPropagation = function() {
1740 this.cancelBubble = true;
1751 var b = navigator.userAgent.toLowerCase();
1753 // Figure out what browser is being used
1755 safari: /webkit/.test(b),
1756 opera: /opera/.test(b),
1757 msie: /msie/.test(b) && !/opera/.test(b),
1758 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
1761 // Check to see if the W3C box model is being used
1762 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1768 * Append all of the matched elements to another, specified, set of elements.
1769 * This operation is, essentially, the reverse of doing a regular
1770 * $(A).append(B), in that instead of appending B to A, you're appending
1773 * @example $("p").appendTo("#foo");
1774 * @before <p>I would like to say: </p><div id="foo"></div>
1775 * @result <div id="foo"><p>I would like to say: </p></div>
1779 * @param String expr A jQuery expression of elements to match.
1780 * @cat DOM/Manipulation
1785 * Prepend all of the matched elements to another, specified, set of elements.
1786 * This operation is, essentially, the reverse of doing a regular
1787 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1790 * @example $("p").prependTo("#foo");
1791 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1792 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1796 * @param String expr A jQuery expression of elements to match.
1797 * @cat DOM/Manipulation
1799 prependTo: "prepend",
1802 * Insert all of the matched elements before another, specified, set of elements.
1803 * This operation is, essentially, the reverse of doing a regular
1804 * $(A).before(B), in that instead of inserting B before A, you're inserting
1807 * @example $("p").insertBefore("#foo");
1808 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1809 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1811 * @name insertBefore
1813 * @param String expr A jQuery expression of elements to match.
1814 * @cat DOM/Manipulation
1816 insertBefore: "before",
1819 * Insert all of the matched elements after another, specified, set of elements.
1820 * This operation is, essentially, the reverse of doing a regular
1821 * $(A).after(B), in that instead of inserting B after A, you're inserting
1824 * @example $("p").insertAfter("#foo");
1825 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1826 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1830 * @param String expr A jQuery expression of elements to match.
1831 * @cat DOM/Manipulation
1833 insertAfter: "after"
1837 * Get the current CSS width of the first matched element.
1839 * @example $("p").width();
1840 * @before <p>This is just a test.</p>
1849 * Set the CSS width of every matched element. Be sure to include
1850 * the "px" (or other unit of measurement) after the number that you
1851 * specify, otherwise you might get strange results.
1853 * @example $("p").width("20px");
1854 * @before <p>This is just a test.</p>
1855 * @result <p style="width:20px;">This is just a test.</p>
1859 * @param String val Set the CSS property to the specified value.
1864 * Get the current CSS height of the first matched element.
1866 * @example $("p").height();
1867 * @before <p>This is just a test.</p>
1876 * Set the CSS height of every matched element. Be sure to include
1877 * the "px" (or other unit of measurement) after the number that you
1878 * specify, otherwise you might get strange results.
1880 * @example $("p").height("20px");
1881 * @before <p>This is just a test.</p>
1882 * @result <p style="height:20px;">This is just a test.</p>
1886 * @param String val Set the CSS property to the specified value.
1891 * Get the current CSS top of the first matched element.
1893 * @example $("p").top();
1894 * @before <p>This is just a test.</p>
1903 * Set the CSS top of every matched element. Be sure to include
1904 * the "px" (or other unit of measurement) after the number that you
1905 * specify, otherwise you might get strange results.
1907 * @example $("p").top("20px");
1908 * @before <p>This is just a test.</p>
1909 * @result <p style="top:20px;">This is just a test.</p>
1913 * @param String val Set the CSS property to the specified value.
1918 * Get the current CSS left of the first matched element.
1920 * @example $("p").left();
1921 * @before <p>This is just a test.</p>
1930 * Set the CSS left of every matched element. Be sure to include
1931 * the "px" (or other unit of measurement) after the number that you
1932 * specify, otherwise you might get strange results.
1934 * @example $("p").left("20px");
1935 * @before <p>This is just a test.</p>
1936 * @result <p style="left:20px;">This is just a test.</p>
1940 * @param String val Set the CSS property to the specified value.
1945 * Get the current CSS position of the first matched element.
1947 * @example $("p").position();
1948 * @before <p>This is just a test.</p>
1957 * Set the CSS position of every matched element.
1959 * @example $("p").position("relative");
1960 * @before <p>This is just a test.</p>
1961 * @result <p style="position:relative;">This is just a test.</p>
1965 * @param String val Set the CSS property to the specified value.
1970 * Get the current CSS float of the first matched element.
1972 * @example $("p").float();
1973 * @before <p>This is just a test.</p>
1982 * Set the CSS float of every matched element.
1984 * @example $("p").float("left");
1985 * @before <p>This is just a test.</p>
1986 * @result <p style="float:left;">This is just a test.</p>
1990 * @param String val Set the CSS property to the specified value.
1995 * Get the current CSS overflow of the first matched element.
1997 * @example $("p").overflow();
1998 * @before <p>This is just a test.</p>
2007 * Set the CSS overflow of every matched element.
2009 * @example $("p").overflow("auto");
2010 * @before <p>This is just a test.</p>
2011 * @result <p style="overflow:auto;">This is just a test.</p>
2015 * @param String val Set the CSS property to the specified value.
2020 * Get the current CSS color of the first matched element.
2022 * @example $("p").color();
2023 * @before <p>This is just a test.</p>
2032 * Set the CSS color of every matched element.
2034 * @example $("p").color("blue");
2035 * @before <p>This is just a test.</p>
2036 * @result <p style="color:blue;">This is just a test.</p>
2040 * @param String val Set the CSS property to the specified value.
2045 * Get the current CSS background of the first matched element.
2047 * @example $("p").background();
2048 * @before <p>This is just a test.</p>
2057 * Set the CSS background of every matched element.
2059 * @example $("p").background("blue");
2060 * @before <p>This is just a test.</p>
2061 * @result <p style="background:blue;">This is just a test.</p>
2065 * @param String val Set the CSS property to the specified value.
2069 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2071 filter: [ "eq", "lt", "gt", "contains" ],
2075 * Get the current value of the first matched element.
2077 * @example $("input").val();
2078 * @before <input type="text" value="some text"/>
2079 * @result "some text"
2083 * @cat DOM/Attributes
2087 * Set the value of every matched element.
2089 * @example $("input").value("test");
2090 * @before <input type="text" value="some text"/>
2091 * @result <input type="text" value="test"/>
2095 * @param String val Set the property to the specified value.
2096 * @cat DOM/Attributes
2101 * Get the html contents of the first matched element.
2103 * @example $("div").html();
2104 * @before <div><input/></div>
2109 * @cat DOM/Attributes
2113 * Set the html contents of every matched element.
2115 * @example $("div").html("<b>new stuff</b>");
2116 * @before <div><input/></div>
2117 * @result <div><b>new stuff</b></div>
2119 * @test var div = $("div");
2120 * div.html("<b>test</b>");
2122 * for ( var i = 0; i < div.size(); i++ ) {
2123 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2125 * ok( pass, "Set HTML" );
2129 * @param String val Set the html contents to the specified value.
2130 * @cat DOM/Attributes
2135 * Get the current id of the first matched element.
2137 * @example $("input").id();
2138 * @before <input type="text" id="test" value="some text"/>
2143 * @cat DOM/Attributes
2147 * Set the id of every matched element.
2149 * @example $("input").id("newid");
2150 * @before <input type="text" id="test" value="some text"/>
2151 * @result <input type="text" id="newid" value="some text"/>
2155 * @param String val Set the property to the specified value.
2156 * @cat DOM/Attributes
2161 * Get the current title of the first matched element.
2163 * @example $("img").title();
2164 * @before <img src="test.jpg" title="my image"/>
2165 * @result "my image"
2169 * @cat DOM/Attributes
2173 * Set the title of every matched element.
2175 * @example $("img").title("new title");
2176 * @before <img src="test.jpg" title="my image"/>
2177 * @result <img src="test.jpg" title="new image"/>
2181 * @param String val Set the property to the specified value.
2182 * @cat DOM/Attributes
2187 * Get the current name of the first matched element.
2189 * @example $("input").name();
2190 * @before <input type="text" name="username"/>
2191 * @result "username"
2195 * @cat DOM/Attributes
2199 * Set the name of every matched element.
2201 * @example $("input").name("user");
2202 * @before <input type="text" name="username"/>
2203 * @result <input type="text" name="user"/>
2207 * @param String val Set the property to the specified value.
2208 * @cat DOM/Attributes
2213 * Get the current href of the first matched element.
2215 * @example $("a").href();
2216 * @before <a href="test.html">my link</a>
2217 * @result "test.html"
2221 * @cat DOM/Attributes
2225 * Set the href of every matched element.
2227 * @example $("a").href("test2.html");
2228 * @before <a href="test.html">my link</a>
2229 * @result <a href="test2.html">my link</a>
2233 * @param String val Set the property to the specified value.
2234 * @cat DOM/Attributes
2239 * Get the current src of the first matched element.
2241 * @example $("img").src();
2242 * @before <img src="test.jpg" title="my image"/>
2243 * @result "test.jpg"
2247 * @cat DOM/Attributes
2251 * Set the src of every matched element.
2253 * @example $("img").src("test2.jpg");
2254 * @before <img src="test.jpg" title="my image"/>
2255 * @result <img src="test2.jpg" title="my image"/>
2259 * @param String val Set the property to the specified value.
2260 * @cat DOM/Attributes
2265 * Get the current rel of the first matched element.
2267 * @example $("a").rel();
2268 * @before <a href="test.html" rel="nofollow">my link</a>
2269 * @result "nofollow"
2273 * @cat DOM/Attributes
2277 * Set the rel of every matched element.
2279 * @example $("a").rel("nofollow");
2280 * @before <a href="test.html">my link</a>
2281 * @result <a href="test.html" rel="nofollow">my link</a>
2285 * @param String val Set the property to the specified value.
2286 * @cat DOM/Attributes
2293 * Get a set of elements containing the unique parents of the matched
2296 * @example $("p").parent()
2297 * @before <div><p>Hello</p><p>Hello</p></div>
2298 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2302 * @cat DOM/Traversing
2306 * Get a set of elements containing the unique parents of the matched
2307 * set of elements, and filtered by an expression.
2309 * @example $("p").parent(".selected")
2310 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2311 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2315 * @param String expr An expression to filter the parents with
2316 * @cat DOM/Traversing
2318 parent: "a.parentNode",
2321 * Get a set of elements containing the unique ancestors of the matched
2322 * set of elements (except for the root element).
2324 * @example $("span").ancestors()
2325 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2326 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2330 * @cat DOM/Traversing
2334 * Get a set of elements containing the unique ancestors of the matched
2335 * set of elements, and filtered by an expression.
2337 * @example $("span").ancestors("p")
2338 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2339 * @result [ <p><span>Hello</span></p> ]
2343 * @param String expr An expression to filter the ancestors with
2344 * @cat DOM/Traversing
2346 ancestors: jQuery.parents,
2349 * Get a set of elements containing the unique ancestors of the matched
2350 * set of elements (except for the root element).
2352 * @example $("span").ancestors()
2353 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2354 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2358 * @cat DOM/Traversing
2362 * Get a set of elements containing the unique ancestors of the matched
2363 * set of elements, and filtered by an expression.
2365 * @example $("span").ancestors("p")
2366 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2367 * @result [ <p><span>Hello</span></p> ]
2371 * @param String expr An expression to filter the ancestors with
2372 * @cat DOM/Traversing
2374 parents: jQuery.parents,
2377 * Get a set of elements containing the unique next siblings of each of the
2378 * matched set of elements.
2380 * It only returns the very next sibling, not all next siblings.
2382 * @example $("p").next()
2383 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2384 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2388 * @cat DOM/Traversing
2392 * Get a set of elements containing the unique next siblings of each of the
2393 * matched set of elements, and filtered by an expression.
2395 * It only returns the very next sibling, not all next siblings.
2397 * @example $("p").next(".selected")
2398 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2399 * @result [ <p class="selected">Hello Again</p> ]
2403 * @param String expr An expression to filter the next Elements with
2404 * @cat DOM/Traversing
2406 next: "jQuery.sibling(a).next",
2409 * Get a set of elements containing the unique previous siblings of each of the
2410 * matched set of elements.
2412 * It only returns the immediately previous sibling, not all previous siblings.
2414 * @example $("p").previous()
2415 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2416 * @result [ <div><span>Hello Again</span></div> ]
2420 * @cat DOM/Traversing
2424 * Get a set of elements containing the unique previous siblings of each of the
2425 * matched set of elements, and filtered by an expression.
2427 * It only returns the immediately previous sibling, not all previous siblings.
2429 * @example $("p").previous(".selected")
2430 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2431 * @result [ <div><span>Hello</span></div> ]
2435 * @param String expr An expression to filter the previous Elements with
2436 * @cat DOM/Traversing
2438 prev: "jQuery.sibling(a).prev",
2441 * Get a set of elements containing all of the unique siblings of each of the
2442 * matched set of elements.
2444 * @example $("div").siblings()
2445 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2446 * @result [ <p>Hello</p>, <p>And Again</p> ]
2450 * @cat DOM/Traversing
2454 * Get a set of elements containing all of the unique siblings of each of the
2455 * matched set of elements, and filtered by an expression.
2457 * @example $("div").siblings(".selected")
2458 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2459 * @result [ <p class="selected">Hello Again</p> ]
2463 * @param String expr An expression to filter the sibling Elements with
2464 * @cat DOM/Traversing
2466 siblings: jQuery.sibling,
2470 * Get a set of elements containing all of the unique children of each of the
2471 * matched set of elements.
2473 * @example $("div").children()
2474 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2475 * @result [ <span>Hello Again</span> ]
2479 * @cat DOM/Traversing
2483 * Get a set of elements containing all of the unique children of each of the
2484 * matched set of elements, and filtered by an expression.
2486 * @example $("div").children(".selected")
2487 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2488 * @result [ <p class="selected">Hello Again</p> ]
2492 * @param String expr An expression to filter the child Elements with
2493 * @cat DOM/Traversing
2495 children: "jQuery.sibling(a.firstChild)"
2500 removeAttr: function( key ) {
2501 this.removeAttribute( key );
2505 * Displays each of the set of matched elements if they are hidden.
2507 * @example $("p").show()
2508 * @before <p style="display: none">Hello</p>
2509 * @result [ <p style="display: block">Hello</p> ]
2511 * @test var pass = true, div = $("div");
2512 * div.show().each(function(){
2513 * if ( this.style.display == "none" ) pass = false;
2515 * ok( pass, "Show" );
2522 this.style.display = this.oldblock ? this.oldblock : "";
2523 if ( jQuery.css(this,"display") == "none" )
2524 this.style.display = "block";
2528 * Hides each of the set of matched elements if they are shown.
2530 * @example $("p").hide()
2531 * @before <p>Hello</p>
2532 * @result [ <p style="display: none">Hello</p> ]
2534 * var pass = true, div = $("div");
2535 * div.hide().each(function(){
2536 * if ( this.style.display != "none" ) pass = false;
2538 * ok( pass, "Hide" );
2545 this.oldblock = this.oldblock || jQuery.css(this,"display");
2546 if ( this.oldblock == "none" )
2547 this.oldblock = "block";
2548 this.style.display = "none";
2552 * Toggles each of the set of matched elements. If they are shown,
2553 * toggle makes them hidden. If they are hidden, toggle
2556 * @example $("p").toggle()
2557 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2558 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2565 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
2569 * Adds the specified class to each of the set of matched elements.
2571 * @example $("p").addClass("selected")
2572 * @before <p>Hello</p>
2573 * @result [ <p class="selected">Hello</p> ]
2575 * @test var div = $("div");
2576 * div.addClass("test");
2578 * for ( var i = 0; i < div.size(); i++ ) {
2579 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2581 * ok( pass, "Add Class" );
2585 * @param String class A CSS class to add to the elements
2588 addClass: function(c){
2589 jQuery.className.add(this,c);
2593 * Removes the specified class from the set of matched elements.
2595 * @example $("p").removeClass("selected")
2596 * @before <p class="selected">Hello</p>
2597 * @result [ <p>Hello</p> ]
2599 * @test var div = $("div").addClass("test");
2600 * div.removeClass("test");
2602 * for ( var i = 0; i < div.size(); i++ ) {
2603 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2605 * ok( pass, "Remove Class" );
2609 * @param String class A CSS class to remove from the elements
2612 removeClass: function(c){
2613 jQuery.className.remove(this,c);
2617 * Adds the specified class if it is present, removes it if it is
2620 * @example $("p").toggleClass("selected")
2621 * @before <p>Hello</p><p class="selected">Hello Again</p>
2622 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2626 * @param String class A CSS class with which to toggle the elements
2629 toggleClass: function( c ){
2630 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2634 * Removes all matched elements from the DOM. This does NOT remove them from the
2635 * jQuery object, allowing you to use the matched elements further.
2637 * @example $("p").remove();
2638 * @before <p>Hello</p> how are <p>you?</p>
2643 * @cat DOM/Manipulation
2647 * Removes only elements (out of the list of matched elements) that match
2648 * the specified jQuery expression. This does NOT remove them from the
2649 * jQuery object, allowing you to use the matched elements further.
2651 * @example $("p").remove(".hello");
2652 * @before <p class="hello">Hello</p> how are <p>you?</p>
2653 * @result how are <p>you?</p>
2657 * @param String expr A jQuery expression to filter elements by.
2658 * @cat DOM/Manipulation
2660 remove: function(a){
2661 if ( !a || jQuery.filter( a, [this] ).r )
2662 this.parentNode.removeChild( this );
2666 * Removes all child nodes from the set of matched elements.
2668 * @example $("p").empty()
2669 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2670 * @result [ <p></p> ]
2674 * @cat DOM/Manipulation
2677 while ( this.firstChild )
2678 this.removeChild( this.firstChild );
2682 * Binds a particular event (like click) to a each of a set of match elements.
2684 * @example $("p").bind( "click", function() { alert("Hello"); } )
2685 * @before <p>Hello</p>
2686 * @result [ <p>Hello</p> ]
2688 * Cancel a default action and prevent it from bubbling by returning false
2689 * from your function.
2691 * @example $("form").bind( "submit", function() { return false; } )
2693 * Cancel a default action by using the preventDefault method.
2695 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2697 * Stop an event from bubbling by using the stopPropogation method.
2699 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2703 * @param String type An event type
2704 * @param Function fn A function to bind to the event on each of the set of matched elements
2707 bind: function( type, fn ) {
2708 if ( fn.constructor == String )
2709 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
2710 jQuery.event.add( this, type, fn );
2714 * The opposite of bind, removes a bound event from each of the matched
2715 * elements. You must pass the identical function that was used in the original
2718 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2719 * @before <p onclick="alert('Hello');">Hello</p>
2720 * @result [ <p>Hello</p> ]
2724 * @param String type An event type
2725 * @param Function fn A function to unbind from the event on each of the set of matched elements
2730 * Removes all bound events of a particular type from each of the matched
2733 * @example $("p").unbind( "click" )
2734 * @before <p onclick="alert('Hello');">Hello</p>
2735 * @result [ <p>Hello</p> ]
2739 * @param String type An event type
2744 * Removes all bound events from each of the matched elements.
2746 * @example $("p").unbind()
2747 * @before <p onclick="alert('Hello');">Hello</p>
2748 * @result [ <p>Hello</p> ]
2754 unbind: function( type, fn ) {
2755 jQuery.event.remove( this, type, fn );
2759 * Trigger a type of event on every matched element.
2761 * @example $("p").trigger("click")
2762 * @before <p click="alert('hello')">Hello</p>
2763 * @result alert('hello')
2767 * @param String type An event type to trigger.
2770 trigger: function( type, data ) {
2771 jQuery.event.trigger( type, data, this );