2 * jQuery - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Dual licensed under the MIT and GPL licenses.
11 // Global undefined variable
12 window.undefined = window.undefined;
15 * Create a new jQuery Object
17 * @test ok( Array.prototype.push, "Array.push()" );
18 * @test ok( Function.prototype.apply, "Function.apply()" );
19 * @test ok( document.getElementById, "getElementById" );
20 * @test ok( document.getElementsByTagName, "getElementsByTagName" );
21 * @test ok( RegExp, "RegExp" );
22 * @test ok( jQuery, "jQuery" );
23 * @test ok( $, "$()" );
29 function jQuery(a,c) {
31 // Initalize the extra macro functions
32 if ( !jQuery.initDone ) jQuery.init();
34 // Shortcut for document ready (because $(document).each() is silly)
35 if ( a && a.constructor == Function && jQuery.fn.ready )
36 return jQuery(document).ready(a);
38 // Make sure that a selection was provided
39 a = a || jQuery.context || document;
42 * Handle support for overriding other $() functions. Way too many libraries
43 * provide this function to simply ignore it and overwrite it.
46 // Check to see if this is a possible collision case
47 if ( jQuery._$ && !c && a.constructor == String &&
49 // Make sure that the expression is a colliding one
50 !/[^a-zA-Z0-9_-]/.test(a) &&
52 // and that there are no elements that match it
53 // (this is the one truly ambiguous case)
54 !document.getElementsByTagName(a).length )
56 // Use the default method, in case it works some voodoo
57 return jQuery._$( a );
60 // Watch for when a jQuery object is passed as the selector
62 return $( jQuery.merge( a, [] ) );
64 // Watch for when a jQuery object is passed at the context
66 return $( c ).find(a);
68 // If the context is global, return a new object
70 return new jQuery(a,c);
72 // Handle HTML strings
73 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
74 if ( m ) a = jQuery.clean( [ m[1] ] );
76 // Watch for when an array is passed in
77 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
78 // Assume that it is an array of DOM Elements
79 jQuery.merge( a, [] ) :
81 // Find the matching elements and save them for later
82 jQuery.find( a, c ) );
84 var fn = arguments[ arguments.length - 1 ];
85 if ( fn && fn.constructor == Function )
89 // Map over the $ in case of overwrite
93 // Map the jQuery namespace to the '$' one
96 jQuery.fn = jQuery.prototype = {
98 * The current SVN version of jQuery.
109 * The number of elements currently matched.
111 * @example $("img").length;
112 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
115 * @test cmpOK( $("div").length, "==", 2, "Get Number of Elements Found" );
124 * The number of elements currently matched.
126 * @example $("img").size();
127 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
130 * @test cmpOK( $("div").size(), "==", 2, "Get Number of Elements Found" );
141 * Access all matched elements. This serves as a backwards-compatible
142 * way of accessing all matched elements (other than the jQuery object
143 * itself, which is, in fact, an array of elements).
145 * @example $("img").get();
146 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
147 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
149 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
152 * @type Array<Element>
157 * Access a single matched element. num is used to access the
158 * Nth element matched.
160 * @example $("img").get(1);
161 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
162 * @result [ <img src="test1.jpg"/> ]
164 * @test cmpOK( $("div").get(0), "==", document.getElementById("main"), "Get A Single Element" );
168 * @param Number num Access the element in the Nth position.
173 * Set the jQuery object to an array of elements.
175 * @example $("img").get([ document.body ]);
176 * @result $("img").get() == [ document.body ]
181 * @param Elements elems An array of elements
184 get: function( num ) {
185 // Watch for when an array (of elements) is passed in
186 if ( num && num.constructor == Array ) {
188 // Use a tricky hack to make the jQuery object
189 // look and feel like an array
191 [].push.apply( this, num );
195 return num == undefined ?
197 // Return a 'clean' array
198 jQuery.map( this, function(a){ return a } ) :
200 // Return just the object
205 * Execute a function within the context of every matched element.
206 * This means that every time the passed-in function is executed
207 * (which is once for every element matched) the 'this' keyword
208 * points to the specific element.
210 * Additionally, the function, when executed, is passed a single
211 * argument representing the position of the element in the matched
214 * @example $("img").each(function(){ this.src = "test.jpg"; });
215 * @before <img/> <img/>
216 * @result <img src="test.jpg"/> <img src="test.jpg"/>
218 * @test var div = $("div");
219 * div.each(function(){this.foo = 'zoo';});
221 * for ( var i = 0; i < div.size(); i++ ) {
222 * if ( div.get(i).foo != "zoo" ) pass = false;
224 * ok( pass, "Execute a function, Relative" );
228 * @param Function fn A function to execute
231 each: function( fn, args ) {
232 return jQuery.each( this, fn, args );
236 * Access a property on the first matched element.
237 * This method makes it easy to retreive a property value
238 * from the first matched element.
240 * @example $("img").attr("src");
241 * @before <img src="test.jpg"/>
246 * @param String name The name of the property to access.
251 * Set a hash of key/value object properties to all matched elements.
252 * This serves as the best way to set a large number of properties
253 * on all matched elements.
255 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
257 * @result <img src="test.jpg" alt="Test Image"/>
259 * @test var div = $("div");
260 * div.attr({foo: 'baz', zoo: 'ping'});
262 * for ( var i = 0; i < div.size(); i++ ) {
263 * if ( div.get(i).foo != "baz" && div.get(i).zoo != "ping" ) pass = false;
265 * ok( pass, "Set Multiple Attributes" );
269 * @param Hash prop A set of key/value pairs to set as object properties.
274 * Set a single property to a value, on all matched elements.
276 * @example $("img").attr("src","test.jpg");
278 * @result <img src="test.jpg"/>
280 * @test var div = $("div");
281 * div.attr("foo", "bar");
283 * for ( var i = 0; i < div.size(); i++ ) {
284 * if ( div.get(i).foo != "bar" ) pass = false;
286 * ok( pass, "Set Attribute" );
290 * @param String key The name of the property to set.
291 * @param Object value The value to set the property to.
294 attr: function( key, value, type ) {
295 // Check to see if we're setting style values
296 return key.constructor != String || value != undefined ?
297 this.each(function(){
298 // See if we're setting a hash of styles
299 if ( value == undefined )
300 // Set all the styles
301 for ( var prop in key )
303 type ? this.style : this,
307 // See if we're setting a single key/value style
310 type ? this.style : this,
315 // Look for the case where we're accessing a style value
316 jQuery[ type || "attr" ]( this[0], key );
320 * Access a style property on the first matched element.
321 * This method makes it easy to retreive a style property value
322 * from the first matched element.
324 * @example $("p").css("red");
325 * @before <p style="color:red;">Test Paragraph.</p>
330 * @param String name The name of the property to access.
335 * Set a hash of key/value style properties to all matched elements.
336 * This serves as the best way to set a large number of style properties
337 * on all matched elements.
339 * @example $("p").css({ color: "red", background: "blue" });
340 * @before <p>Test Paragraph.</p>
341 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
345 * @param Hash prop A set of key/value pairs to set as style properties.
350 * Set a single style property to a value, on all matched elements.
352 * @example $("p").css("color","red");
353 * @before <p>Test Paragraph.</p>
354 * @result <p style="color:red;">Test Paragraph.</p>
358 * @param String key The name of the property to set.
359 * @param Object value The value to set the property to.
362 css: function( key, value ) {
363 return this.attr( key, value, "curCSS" );
367 * Retreive the text contents of all matched elements. The result is
368 * a string that contains the combined text contents of all matched
369 * elements. This method works on both HTML and XML documents.
371 * @example $("p").text();
372 * @before <p>Test Paragraph.</p>
373 * @result Test Paragraph.
382 for ( var j = 0; j < e.length; j++ ) {
383 var r = e[j].childNodes;
384 for ( var i = 0; i < r.length; i++ )
385 t += r[i].nodeType != 1 ?
386 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
392 * Wrap all matched elements with a structure of other elements.
393 * This wrapping process is most useful for injecting additional
394 * stucture into a document, without ruining the original semantic
395 * qualities of a document.
397 * The way that is works is that it goes through the first element argument
398 * provided and finds the deepest element within the structure - it is that
399 * element that will en-wrap everything else.
401 * @example $("p").wrap("<div class='wrap'></div>");
402 * @before <p>Test Paragraph.</p>
403 * @result <div class='wrap'><p>Test Paragraph.</p></div>
407 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
408 * @any Element elem A DOM element that will be wrapped.
409 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
410 * @any Object obj Any object, converted to a string, then a text node.
411 * @cat DOM/Manipulation
414 // The elements to wrap the target around
415 var a = jQuery.clean(arguments);
417 // Wrap each of the matched elements individually
418 return this.each(function(){
419 // Clone the structure that we're using to wrap
420 var b = a[0].cloneNode(true);
422 // Insert it before the element to be wrapped
423 this.parentNode.insertBefore( b, this );
425 // Find he deepest point in the wrap structure
426 while ( b.firstChild )
429 // Move the matched element to within the wrap structure
430 b.appendChild( this );
435 * Append any number of elements to the inside of all matched elements.
436 * This operation is similar to doing an appendChild to all the
437 * specified elements, adding them into the document.
439 * @example $("p").append("<b>Hello</b>");
440 * @before <p>I would like to say: </p>
441 * @result <p>I would like to say: <b>Hello</b></p>
445 * @any String html A string of HTML, that will be created on the fly and appended to the target.
446 * @any Element elem A DOM element that will be appended.
447 * @any Array<Element> elems An array of elements, all of which will be appended.
448 * @any Object obj Any object, converted to a string, then a text node.
449 * @cat DOM/Manipulation
452 return this.domManip(arguments, true, 1, function(a){
453 this.appendChild( a );
458 * Prepend any number of elements to the inside of all matched elements.
459 * This operation is the best way to insert a set of elements inside, at the
460 * beginning, of all the matched element.
462 * @example $("p").prepend("<b>Hello</b>");
463 * @before <p>, how are you?</p>
464 * @result <p><b>Hello</b>, how are you?</p>
468 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
469 * @any Element elem A DOM element that will be prepended.
470 * @any Array<Element> elems An array of elements, all of which will be prepended.
471 * @any Object obj Any object, converted to a string, then a text node.
472 * @cat DOM/Manipulation
474 prepend: function() {
475 return this.domManip(arguments, true, -1, function(a){
476 this.insertBefore( a, this.firstChild );
481 * Insert any number of elements before each of the matched elements.
483 * @example $("p").before("<b>Hello</b>");
484 * @before <p>how are you?</p>
485 * @result <b>Hello</b><p>how are you?</p>
489 * @any String html A string of HTML, that will be created on the fly and inserted.
490 * @any Element elem A DOM element that will beinserted.
491 * @any Array<Element> elems An array of elements, all of which will be inserted.
492 * @any Object obj Any object, converted to a string, then a text node.
493 * @cat DOM/Manipulation
496 return this.domManip(arguments, false, 1, function(a){
497 this.parentNode.insertBefore( a, this );
502 * Insert any number of elements after each of the matched elements.
504 * @example $("p").after("<p>I'm doing fine.</p>");
505 * @before <p>How are you?</p>
506 * @result <p>How are you?</p><p>I'm doing fine.</p>
510 * @any String html A string of HTML, that will be created on the fly and inserted.
511 * @any Element elem A DOM element that will beinserted.
512 * @any Array<Element> elems An array of elements, all of which will be inserted.
513 * @any Object obj Any object, converted to a string, then a text node.
514 * @cat DOM/Manipulation
517 return this.domManip(arguments, false, -1, function(a){
518 this.parentNode.insertBefore( a, this.nextSibling );
523 * End the most recent 'destructive' operation, reverting the list of matched elements
524 * back to its previous state. After an end operation, the list of matched elements will
525 * revert to the last state of matched elements.
527 * @example $("p").find("span").end();
528 * @before <p><span>Hello</span>, how are you?</p>
529 * @result $("p").find("span").end() == [ <p>...</p> ]
533 * @cat DOM/Traversing
536 return this.get( this.stack.pop() );
540 * Searches for all elements that match the specified expression.
541 * This method is the optimal way of finding additional descendant
542 * elements with which to process.
544 * All searching is done using a jQuery expression. The expression can be
545 * written using CSS 1-3 Selector syntax, or basic XPath.
547 * @example $("p").find("span");
548 * @before <p><span>Hello</span>, how are you?</p>
549 * @result $("p").find("span") == [ <span>Hello</span> ]
553 * @param String expr An expression to search with.
554 * @cat DOM/Traversing
557 return this.pushStack( jQuery.map( this, function(a){
558 return jQuery.find(t,a);
562 clone: function(deep) {
563 return this.pushStack( jQuery.map( this, function(a){
564 return a.cloneNode( deep != undefined ? deep : true );
569 * Removes all elements from the set of matched elements that do not
570 * match the specified expression. This method is used to narrow down
571 * the results of a search.
573 * All searching is done using a jQuery expression. The expression
574 * can be written using CSS 1-3 Selector syntax, or basic XPath.
576 * @example $("p").filter(".selected")
577 * @before <p class="selected">Hello</p><p>How are you?</p>
578 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
582 * @param String expr An expression to search with.
583 * @cat DOM/Traversing
587 * Removes all elements from the set of matched elements that do not
588 * match at least one of the expressions passed to the function. This
589 * method is used when you want to filter the set of matched elements
590 * through more than one expression.
592 * Elements will be retained in the jQuery object if they match at
593 * least one of the expressions passed.
595 * @example $("p").filter([".selected", ":first"])
596 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
597 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
601 * @param Array<String> exprs A set of expressions to evaluate against
602 * @cat DOM/Traversing
604 filter: function(t) {
605 return this.pushStack(
606 t.constructor == Array &&
607 jQuery.map(this,function(a){
608 for ( var i = 0; i < t.length; i++ )
609 if ( jQuery.filter(t[i],[a]).r.length )
613 t.constructor == Boolean &&
614 ( t ? this.get() : [] ) ||
616 t.constructor == Function &&
617 jQuery.grep( this, t ) ||
619 jQuery.filter(t,this).r, arguments );
623 * Removes the specified Element from the set of matched elements. This
624 * method is used to remove a single Element from a jQuery object.
626 * @example $("p").not( document.getElementById("selected") )
627 * @before <p>Hello</p><p id="selected">Hello Again</p>
628 * @result [ <p>Hello</p> ]
632 * @param Element el An element to remove from the set
633 * @cat DOM/Traversing
637 * Removes elements matching the specified expression from the set
638 * of matched elements. This method is used to remove one or more
639 * elements from a jQuery object.
641 * @example $("p").not("#selected")
642 * @before <p>Hello</p><p id="selected">Hello Again</p>
643 * @result [ <p>Hello</p> ]
647 * @param String expr An expression with which to remove matching elements
648 * @cat DOM/Traversing
651 return this.pushStack( t.constructor == String ?
652 jQuery.filter(t,this,false).r :
653 jQuery.grep(this,function(a){ return a != t; }), arguments );
657 * Adds the elements matched by the expression to the jQuery object. This
658 * can be used to concatenate the result sets of two expressions.
660 * @example $("p").add("span")
661 * @before <p>Hello</p><p><span>Hello Again</span></p>
662 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
666 * @param String expr An expression whose matched elements are added
667 * @cat DOM/Traversing
671 * Adds each of the Elements in the array to the set of matched elements.
672 * This is used to add a set of Elements to a jQuery object.
674 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
675 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
676 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
680 * @param Array<Element> els An array of Elements to add
685 * Adds a single Element to the set of matched elements. This is used to
686 * add a single Element to a jQuery object.
688 * @example $("p").add( document.getElementById("a") )
689 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
690 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
694 * @param Element el An Element to add
698 return this.pushStack( jQuery.merge( this, t.constructor == String ?
699 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
703 * A wrapper function for each() to be used by append and prepend.
704 * Handles cases where you're trying to modify the inner contents of
705 * a table, when you actually need to work with the tbody.
708 * @param {String} expr The expression with which to filter
713 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
722 * @param Boolean table
724 * @param Function fn The function doing the DOM manipulation.
727 domManip: function(args, table, dir, fn){
728 var clone = this.size() > 1;
729 var a = jQuery.clean(args);
731 return this.each(function(){
734 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
735 var tbody = this.getElementsByTagName("tbody");
737 if ( !tbody.length ) {
738 obj = document.createElement("tbody");
739 this.appendChild( obj );
744 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
745 i != ( dir < 0 ? dir : a.length ); i += dir ) {
746 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
760 pushStack: function(a,args) {
761 var fn = args && args[args.length-1];
763 if ( !fn || fn.constructor != Function ) {
764 if ( !this.stack ) this.stack = [];
765 this.stack.push( this.get() );
768 var old = this.get();
770 if ( fn.constructor == Function )
771 return this.each( fn );
790 * Extend one object with another, returning the original,
791 * modified, object. This is a great utility for simple inheritance.
793 * @name jQuery.extend
794 * @param Object obj The object to extend
795 * @param Object prop The object that will be merged into the first.
799 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
800 if ( !prop ) { prop = obj; obj = this; }
801 for ( var i in prop ) obj[i] = prop[i];
814 jQuery.initDone = true;
816 jQuery.each( jQuery.macros.axis, function(i,n){
817 jQuery.fn[ i ] = function(a) {
818 var ret = jQuery.map(this,n);
819 if ( a && a.constructor == String )
820 ret = jQuery.filter(a,ret).r;
821 return this.pushStack( ret, arguments );
825 jQuery.each( jQuery.macros.to, function(i,n){
826 jQuery.fn[ i ] = function(){
828 return this.each(function(){
829 for ( var j = 0; j < a.length; j++ )
835 jQuery.each( jQuery.macros.each, function(i,n){
836 jQuery.fn[ i ] = function() {
837 return this.each( n, arguments );
841 jQuery.each( jQuery.macros.filter, function(i,n){
842 jQuery.fn[ n ] = function(num,fn) {
843 return this.filter( ":" + n + "(" + num + ")", fn );
847 jQuery.each( jQuery.macros.attr, function(i,n){
849 jQuery.fn[ i ] = function(h) {
850 return h == undefined ?
851 this.length ? this[0][n] : null :
856 jQuery.each( jQuery.macros.css, function(i,n){
857 jQuery.fn[ n ] = function(h) {
858 return h == undefined ?
859 ( this.length ? jQuery.css( this[0], n ) : null ) :
867 * A generic iterator function, which can be used to seemlessly
868 * iterate over both objects and arrays.
871 * @param Object obj The object, or array, to iterate over.
872 * @param Object fn The function that will be executed on every object.
876 each: function( obj, fn, args ) {
877 if ( obj.length == undefined )
879 fn.apply( obj[i], args || [i, obj[i]] );
881 for ( var i = 0; i < obj.length; i++ )
882 fn.apply( obj[i], args || [i, obj[i]] );
888 if (jQuery.className.has(o,c)) return;
889 o.className += ( o.className ? " " : "" ) + c;
891 remove: function(o,c){
892 o.className = !c ? "" :
894 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
899 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
904 * Swap in/out style options.
907 swap: function(e,o,f) {
909 e.style["old"+i] = e.style[i];
914 e.style[i] = e.style["old"+i];
918 if ( p == "height" || p == "width" ) {
919 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
922 old["padding" + d[i]] = 0;
923 old["border" + d[i] + "Width"] = 0;
926 jQuery.swap( e, old, function() {
927 if (jQuery.css(e,"display") != "none") {
928 oHeight = e.offsetHeight;
929 oWidth = e.offsetWidth;
931 jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
933 oHeight = e.clientHeight;
934 oWidth = e.clientWidth;
938 return p == "height" ? oHeight : oWidth;
939 } else if ( p == "opacity" && jQuery.browser.msie )
940 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
942 return jQuery.curCSS( e, p );
945 curCSS: function(e,p,force) {
948 if (!force && e.style[p])
950 else if (e.currentStyle) {
951 p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
952 r = e.currentStyle[p];
953 } else if (document.defaultView && document.defaultView.getComputedStyle) {
954 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
955 var s = document.defaultView.getComputedStyle(e,"");
956 r = s ? s.getPropertyValue(p) : null;
964 for ( var i = 0; i < a.length; i++ ) {
965 if ( a[i].constructor == String ) {
969 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
971 a[i] = "<table>" + a[i] + "</table>";
972 } else if ( !a[i].indexOf("<tr") ) {
974 a[i] = "<table>" + a[i] + "</table>";
975 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
977 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
980 var div = document.createElement("div");
981 div.innerHTML = a[i];
984 div = div.firstChild;
985 if ( table != "thead" ) div = div.firstChild;
986 if ( table == "td" ) div = div.firstChild;
989 for ( var j = 0; j < div.childNodes.length; j++ )
990 r.push( div.childNodes[j] );
991 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
992 for ( var k = 0; k < a[i].length; k++ )
994 else if ( a[i] !== null )
995 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1001 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1002 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1010 last: "i==r.length-1",
1015 "first-child": "jQuery.sibling(a,0).cur",
1016 "last-child": "jQuery.sibling(a,0).last",
1017 "only-child": "jQuery.sibling(a).length==1",
1020 parent: "a.childNodes.length",
1021 empty: "!a.childNodes.length",
1024 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1027 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1028 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1031 enabled: "!a.disabled",
1032 disabled: "a.disabled",
1033 checked: "a.checked",
1034 selected: "a.selected"
1036 ".": "jQuery.className.has(a,m[2])",
1040 "^=": "!z.indexOf(m[4])",
1041 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1042 "*=": "z.indexOf(m[4])>=0",
1045 "[": "jQuery.find(m[2],a).length"
1049 "\\.\\.|/\\.\\.", "a.parentNode",
1050 ">|/", "jQuery.sibling(a.firstChild)",
1051 "\\+", "jQuery.sibling(a).next",
1054 var s = jQuery.sibling(a);
1056 for ( var i = s.n; i < s.length; i++ )
1064 * @test t( "Element Selector", "div", ["main","foo"] );
1065 * @test t( "Element Selector", "body", ["body"] );
1066 * @test t( "Element Selector", "html", ["html"] );
1067 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1068 * @test t( "Parent Element", "div div", ["foo"] );
1070 * @test t( "ID Selector", "#body", ["body"] );
1071 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1072 * @test t( "ID Selector w/ Element", "ul#first", [] );
1074 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1075 * @test t( "Class Selector", ".blog.link", ["simon"] );
1076 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1077 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1079 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1080 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1081 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1082 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1084 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1085 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1086 * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1087 * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1088 * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1089 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1090 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1091 * @test t( "Adjacent", "a + a", ["groups"] );
1092 * @test t( "Adjacent", "a +a", ["groups"] );
1093 * @test t( "Adjacent", "a+ a", ["groups"] );
1094 * @test t( "Adjacent", "a+a", ["groups"] );
1095 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1096 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1097 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1098 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1099 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1100 * @test t( "Attribute Exists", "[@title]", ["google"] );
1101 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1102 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1103 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1104 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1105 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1106 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1108 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1109 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1110 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1111 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1112 * @test t( "Last Child", "p:last-child", ["sap"] );
1113 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1114 * @test t( "Empty", "ul:empty", ["firstUL"] );
1115 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1116 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1117 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1118 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1119 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1120 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1121 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1123 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1124 * @test t( "All Div Elements", "//div", ["main","foo"] );
1125 * @test t( "Absolute Path", "/html/body", ["body"] );
1126 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1127 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1128 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1129 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1130 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1131 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1132 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1133 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1134 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1135 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1136 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1138 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1139 * @test t( "First Element", "p:first", ["firstp"] );
1140 * @test t( "Last Element", "p:last", ["first"] );
1141 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1142 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1143 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1144 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1145 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1146 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1147 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1148 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1153 find: function( t, context ) {
1154 // Make sure that the context is a DOM Element
1155 if ( context && context.nodeType == undefined )
1158 // Set the correct context (if none is provided)
1159 context = context || jQuery.context || document;
1161 if ( t.constructor != String ) return [t];
1163 if ( !t.indexOf("//") ) {
1164 context = context.documentElement;
1165 t = t.substr(2,t.length);
1166 } else if ( !t.indexOf("/") ) {
1167 context = context.documentElement;
1168 t = t.substr(1,t.length);
1169 // FIX Assume the root element is right :(
1170 if ( t.indexOf("/") >= 1 )
1171 t = t.substr(t.indexOf("/"),t.length);
1174 var ret = [context];
1178 while ( t.length > 0 && last != t ) {
1182 t = jQuery.trim(t).replace( /^\/\//i, "" );
1184 var foundToken = false;
1186 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1187 var re = new RegExp("^(" + jQuery.token[i] + ")");
1191 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1192 t = jQuery.trim( t.replace( re, "" ) );
1197 if ( !foundToken ) {
1198 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1199 if ( ret[0] == context ) ret.shift();
1200 done = jQuery.merge( done, ret );
1201 r = ret = [context];
1202 t = " " + t.substr(1,t.length);
1204 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1205 var m = re2.exec(t);
1207 if ( m[1] == "#" ) {
1208 // Ummm, should make this work in all XML docs
1209 var oid = document.getElementById(m[2]);
1210 r = ret = oid ? [oid] : [];
1211 t = t.replace( re2, "" );
1213 if ( !m[2] || m[1] == "." ) m[2] = "*";
1215 for ( var i = 0; i < ret.length; i++ )
1216 r = jQuery.merge( r,
1218 jQuery.getAll(ret[i]) :
1219 ret[i].getElementsByTagName(m[2])
1226 var val = jQuery.filter(t,r);
1228 t = jQuery.trim(val.t);
1232 if ( ret && ret[0] == context ) ret.shift();
1233 done = jQuery.merge( done, ret );
1238 getAll: function(o,r) {
1240 var s = o.childNodes;
1241 for ( var i = 0; i < s.length; i++ )
1242 if ( s[i].nodeType == 1 ) {
1244 jQuery.getAll( s[i], r );
1249 attr: function(o,a,v){
1250 if ( a && a.constructor == String ) {
1253 "class": "className",
1257 a = (fix[a] && fix[a].replace && fix[a] || a)
1258 .replace(/-([a-z])/ig,function(z,b){
1259 return b.toUpperCase();
1262 if ( v != undefined ) {
1264 if ( o.setAttribute && a != "disabled" )
1265 o.setAttribute(a,v);
1268 return o[a] || o.getAttribute && o.getAttribute(a) || "";
1273 // The regular expressions that power the parsing engine
1275 // Match: [@value='test'], [@foo]
1276 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1278 // Match: [div], [div p]
1281 // Match: :contains('foo')
1282 [ "(:)S\\(Q\\)", 0 ],
1284 // Match: :even, :last-chlid
1288 filter: function(t,r,not) {
1289 // Figure out if we're doing regular, or inverse, filtering
1290 var g = not !== false ? jQuery.grep :
1291 function(a,f) {return jQuery.grep(a,f,true);};
1293 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1295 var p = jQuery.parse;
1297 for ( var i = 0; i < p.length; i++ ) {
1298 var re = new RegExp( "^" + p[i][0]
1300 // Look for a string-like sequence
1301 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1303 // Look for something (optionally) enclosed with quotes
1304 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1306 var m = re.exec( t );
1309 // Re-organize the match
1311 m = ["", m[1], m[3], m[2], m[4]];
1313 // Remove what we just matched
1314 t = t.replace( re, "" );
1320 // :not() is a special case that can be optomized by
1321 // keeping it out of the expression list
1322 if ( m[1] == ":" && m[2] == "not" )
1323 r = jQuery.filter(m[3],r,false).r;
1325 // Otherwise, find the expression to execute
1327 var f = jQuery.expr[m[1]];
1328 if ( f.constructor != String )
1329 f = jQuery.expr[m[1]][m[2]];
1331 // Build a custom macro to enclose it
1332 eval("f = function(a,i){" +
1333 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1334 "return " + f + "}");
1336 // Execute it against the current filter
1341 // Return an array of filtered elements (r)
1342 // and the modified expression string (t)
1343 return { r: r, t: t };
1347 * Remove the whitespace from the beginning and end of a string.
1352 * @param String str The string to trim.
1355 return t.replace(/^\s+|\s+$/g, "");
1359 * All ancestors of a given element.
1362 * @name jQuery.parents
1363 * @type Array<Element>
1364 * @param Element elem The element to find the ancestors of.
1366 parents: function(a){
1368 var c = a.parentNode;
1369 while ( c && c != document ) {
1377 * All elements on a specified axis.
1380 * @name jQuery.sibling
1382 * @param Element elem The element to find all the siblings of (including itself).
1384 sibling: function(a,n) {
1386 var tmp = a.parentNode.childNodes;
1387 for ( var i = 0; i < tmp.length; i++ ) {
1388 if ( tmp[i].nodeType == 1 )
1389 type.push( tmp[i] );
1391 type.n = type.length - 1;
1393 type.last = type.n == type.length - 1;
1395 n == "even" && type.n % 2 == 0 ||
1396 n == "odd" && type.n % 2 ||
1398 type.prev = type[type.n - 1];
1399 type.next = type[type.n + 1];
1404 * Merge two arrays together, removing all duplicates.
1407 * @name jQuery.merge
1409 * @param Array a The first array to merge.
1410 * @param Array b The second array to merge.
1412 merge: function(a,b) {
1415 // Move b over to the new array (this helps to avoid
1416 // StaticNodeList instances)
1417 for ( var k = 0; k < a.length; k++ )
1420 // Now check for duplicates between a and b and only
1421 // add the unique items
1422 for ( var i = 0; i < b.length; i++ ) {
1425 // The collision-checking process
1426 for ( var j = 0; j < a.length; j++ )
1430 // If the item is unique, add it
1439 * Remove items that aren't matched in an array. The function passed
1440 * in to this method will be passed two arguments: 'a' (which is the
1441 * array item) and 'i' (which is the index of the item in the array).
1446 * @param Array array The Array to find items in.
1447 * @param Function fn The function to process each item against.
1448 * @param Boolean inv Invert the selection - select the opposite of the function.
1450 grep: function(a,f,s) {
1451 // If a string is passed in for the function, make a function
1452 // for it (a handy shortcut)
1453 if ( f.constructor == String )
1454 f = new Function("a","i","return " + f);
1458 // Go through the array, only saving the items
1459 // that pass the validator function
1460 for ( var i = 0; i < a.length; i++ )
1461 if ( !s && f(a[i],i) || s && !f(a[i],i) )
1468 * Translate all items in array to another array of items. The translation function
1469 * that is provided to this method is passed one argument: 'a' (the item to be
1470 * translated). If an array is returned, that array is mapped out and merged into
1471 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1472 * from the array. Both of these changes imply that the size of the array may not
1473 * be the same size upon completion, as it was when it started.
1478 * @param Array array The Array to translate.
1479 * @param Function fn The function to process each item against.
1481 map: function(a,f) {
1482 // If a string is passed in for the function, make a function
1483 // for it (a handy shortcut)
1484 if ( f.constructor == String )
1485 f = new Function("a","return " + f);
1489 // Go through the array, translating each of the items to their
1490 // new value (or values).
1491 for ( var i = 0; i < a.length; i++ ) {
1493 if ( t !== null && t != undefined ) {
1494 if ( t.constructor != Array ) t = [t];
1495 r = jQuery.merge( r, t );
1502 * A number of helper functions used for managing events.
1503 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1507 // Bind an event to an element
1508 // Original by Dean Edwards
1509 add: function(element, type, handler) {
1510 // For whatever reason, IE has trouble passing the window object
1511 // around, causing it to be cloned in the process
1512 if ( jQuery.browser.msie && element.setInterval != undefined )
1515 // Make sure that the function being executed has a unique ID
1516 if ( !handler.guid )
1517 handler.guid = this.guid++;
1519 // Init the element's event structure
1520 if (!element.events)
1521 element.events = {};
1523 // Get the current list of functions bound to this event
1524 var handlers = element.events[type];
1526 // If it hasn't been initialized yet
1528 // Init the event handler queue
1529 handlers = element.events[type] = {};
1531 // Remember an existing handler, if it's already there
1532 if (element["on" + type])
1533 handlers[0] = element["on" + type];
1536 // Add the function to the element's handler list
1537 handlers[handler.guid] = handler;
1539 // And bind the global event handler to the element
1540 element["on" + type] = this.handle;
1542 // Remember the function in a global list (for triggering)
1543 if (!this.global[type])
1544 this.global[type] = [];
1545 this.global[type].push( element );
1551 // Detach an event or set of events from an element
1552 remove: function(element, type, handler) {
1554 if (type && element.events[type])
1556 delete element.events[type][handler.guid];
1558 for ( var i in element.events[type] )
1559 delete element.events[type][i];
1561 for ( var j in element.events )
1562 this.remove( element, j );
1565 trigger: function(type,data,element) {
1566 // Touch up the incoming data
1569 // Handle a global trigger
1571 var g = this.global[type];
1573 for ( var i = 0; i < g.length; i++ )
1574 this.trigger( type, data, g[i] );
1576 // Handle triggering a single element
1577 } else if ( element["on" + type] ) {
1578 // Pass along a fake event
1579 data.unshift( this.fix({ type: type, target: element }) );
1581 // Trigger the event
1582 element["on" + type].apply( element, data );
1586 handle: function(event) {
1587 if ( typeof jQuery == "undefined" ) return;
1589 event = event || jQuery.event.fix( window.event );
1591 // If no correct event was found, fail
1592 if ( !event ) return;
1594 var returnValue = true;
1596 var c = this.events[event.type];
1598 for ( var j in c ) {
1599 if ( c[j].apply( this, [event] ) === false ) {
1600 event.preventDefault();
1601 event.stopPropagation();
1602 returnValue = false;
1609 fix: function(event) {
1611 event.preventDefault = function() {
1612 this.returnValue = false;
1615 event.stopPropagation = function() {
1616 this.cancelBubble = true;
1627 var b = navigator.userAgent.toLowerCase();
1629 // Figure out what browser is being used
1631 safari: /webkit/.test(b),
1632 opera: /opera/.test(b),
1633 msie: /msie/.test(b) && !/opera/.test(b),
1634 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1637 // Check to see if the W3C box model is being used
1638 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1644 * Append all of the matched elements to another, specified, set of elements.
1645 * This operation is, essentially, the reverse of doing a regular
1646 * $(A).append(B), in that instead of appending B to A, you're appending
1649 * @example $("p").appendTo("#foo");
1650 * @before <p>I would like to say: </p><div id="foo"></div>
1651 * @result <div id="foo"><p>I would like to say: </p></div>
1655 * @param String expr A jQuery expression of elements to match.
1656 * @cat DOM/Manipulation
1661 * Prepend all of the matched elements to another, specified, set of elements.
1662 * This operation is, essentially, the reverse of doing a regular
1663 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1666 * @example $("p").prependTo("#foo");
1667 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1668 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1672 * @param String expr A jQuery expression of elements to match.
1673 * @cat DOM/Manipulation
1675 prependTo: "prepend",
1678 * Insert all of the matched elements before another, specified, set of elements.
1679 * This operation is, essentially, the reverse of doing a regular
1680 * $(A).before(B), in that instead of inserting B before A, you're inserting
1683 * @example $("p").insertBefore("#foo");
1684 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1685 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1687 * @name insertBefore
1689 * @param String expr A jQuery expression of elements to match.
1690 * @cat DOM/Manipulation
1692 insertBefore: "before",
1695 * Insert all of the matched elements after another, specified, set of elements.
1696 * This operation is, essentially, the reverse of doing a regular
1697 * $(A).after(B), in that instead of inserting B after A, you're inserting
1700 * @example $("p").insertAfter("#foo");
1701 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1702 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1706 * @param String expr A jQuery expression of elements to match.
1707 * @cat DOM/Manipulation
1709 insertAfter: "after"
1713 * Get the current CSS width of the first matched element.
1715 * @example $("p").width();
1716 * @before <p>This is just a test.</p>
1725 * Set the CSS width of every matched element. Be sure to include
1726 * the "px" (or other unit of measurement) after the number that you
1727 * specify, otherwise you might get strange results.
1729 * @example $("p").width("20px");
1730 * @before <p>This is just a test.</p>
1731 * @result <p style="width:20px;">This is just a test.</p>
1735 * @param String val Set the CSS property to the specified value.
1740 * Get the current CSS height of the first matched element.
1742 * @example $("p").height();
1743 * @before <p>This is just a test.</p>
1752 * Set the CSS height of every matched element. Be sure to include
1753 * the "px" (or other unit of measurement) after the number that you
1754 * specify, otherwise you might get strange results.
1756 * @example $("p").height("20px");
1757 * @before <p>This is just a test.</p>
1758 * @result <p style="height:20px;">This is just a test.</p>
1762 * @param String val Set the CSS property to the specified value.
1767 * Get the current CSS top of the first matched element.
1769 * @example $("p").top();
1770 * @before <p>This is just a test.</p>
1779 * Set the CSS top of every matched element. Be sure to include
1780 * the "px" (or other unit of measurement) after the number that you
1781 * specify, otherwise you might get strange results.
1783 * @example $("p").top("20px");
1784 * @before <p>This is just a test.</p>
1785 * @result <p style="top:20px;">This is just a test.</p>
1789 * @param String val Set the CSS property to the specified value.
1794 * Get the current CSS left of the first matched element.
1796 * @example $("p").left();
1797 * @before <p>This is just a test.</p>
1806 * Set the CSS left of every matched element. Be sure to include
1807 * the "px" (or other unit of measurement) after the number that you
1808 * specify, otherwise you might get strange results.
1810 * @example $("p").left("20px");
1811 * @before <p>This is just a test.</p>
1812 * @result <p style="left:20px;">This is just a test.</p>
1816 * @param String val Set the CSS property to the specified value.
1821 * Get the current CSS position of the first matched element.
1823 * @example $("p").position();
1824 * @before <p>This is just a test.</p>
1833 * Set the CSS position of every matched element.
1835 * @example $("p").position("relative");
1836 * @before <p>This is just a test.</p>
1837 * @result <p style="position:relative;">This is just a test.</p>
1841 * @param String val Set the CSS property to the specified value.
1846 * Get the current CSS float of the first matched element.
1848 * @example $("p").float();
1849 * @before <p>This is just a test.</p>
1858 * Set the CSS float of every matched element.
1860 * @example $("p").float("left");
1861 * @before <p>This is just a test.</p>
1862 * @result <p style="float:left;">This is just a test.</p>
1866 * @param String val Set the CSS property to the specified value.
1871 * Get the current CSS overflow of the first matched element.
1873 * @example $("p").overflow();
1874 * @before <p>This is just a test.</p>
1883 * Set the CSS overflow of every matched element.
1885 * @example $("p").overflow("auto");
1886 * @before <p>This is just a test.</p>
1887 * @result <p style="overflow:auto;">This is just a test.</p>
1891 * @param String val Set the CSS property to the specified value.
1896 * Get the current CSS color of the first matched element.
1898 * @example $("p").color();
1899 * @before <p>This is just a test.</p>
1908 * Set the CSS color of every matched element.
1910 * @example $("p").color("blue");
1911 * @before <p>This is just a test.</p>
1912 * @result <p style="color:blue;">This is just a test.</p>
1916 * @param String val Set the CSS property to the specified value.
1921 * Get the current CSS background of the first matched element.
1923 * @example $("p").background();
1924 * @before <p>This is just a test.</p>
1933 * Set the CSS background of every matched element.
1935 * @example $("p").background("blue");
1936 * @before <p>This is just a test.</p>
1937 * @result <p style="background:blue;">This is just a test.</p>
1941 * @param String val Set the CSS property to the specified value.
1945 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1947 filter: [ "eq", "lt", "gt", "contains" ],
1951 * Get the current value of the first matched element.
1953 * @example $("input").val();
1954 * @before <input type="text" value="some text"/>
1955 * @result "some text"
1959 * @cat DOM/Attributes
1963 * Set the value of every matched element.
1965 * @example $("input").value("test");
1966 * @before <input type="text" value="some text"/>
1967 * @result <input type="text" value="test"/>
1971 * @param String val Set the property to the specified value.
1972 * @cat DOM/Attributes
1977 * Get the html contents of the first matched element.
1979 * @example $("div").html();
1980 * @before <div><input/></div>
1985 * @cat DOM/Attributes
1989 * Set the html contents of every matched element.
1991 * @example $("div").html("<b>new stuff</b>");
1992 * @before <div><input/></div>
1993 * @result <div><b>new stuff</b></div>
1995 * @test var div = $("div");
1996 * div.html("<b>test</b>");
1998 * for ( var i = 0; i < div.size(); i++ ) {
1999 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2001 * ok( pass, "Set HTML" );
2005 * @param String val Set the html contents to the specified value.
2006 * @cat DOM/Attributes
2011 * Get the current id of the first matched element.
2013 * @example $("input").id();
2014 * @before <input type="text" id="test" value="some text"/>
2019 * @cat DOM/Attributes
2023 * Set the id of every matched element.
2025 * @example $("input").id("newid");
2026 * @before <input type="text" id="test" value="some text"/>
2027 * @result <input type="text" id="newid" value="some text"/>
2031 * @param String val Set the property to the specified value.
2032 * @cat DOM/Attributes
2037 * Get the current title of the first matched element.
2039 * @example $("img").title();
2040 * @before <img src="test.jpg" title="my image"/>
2041 * @result "my image"
2045 * @cat DOM/Attributes
2049 * Set the title of every matched element.
2051 * @example $("img").title("new title");
2052 * @before <img src="test.jpg" title="my image"/>
2053 * @result <img src="test.jpg" title="new image"/>
2057 * @param String val Set the property to the specified value.
2058 * @cat DOM/Attributes
2063 * Get the current name of the first matched element.
2065 * @example $("input").name();
2066 * @before <input type="text" name="username"/>
2067 * @result "username"
2071 * @cat DOM/Attributes
2075 * Set the name of every matched element.
2077 * @example $("input").name("user");
2078 * @before <input type="text" name="username"/>
2079 * @result <input type="text" name="user"/>
2083 * @param String val Set the property to the specified value.
2084 * @cat DOM/Attributes
2089 * Get the current href of the first matched element.
2091 * @example $("a").href();
2092 * @before <a href="test.html">my link</a>
2093 * @result "test.html"
2097 * @cat DOM/Attributes
2101 * Set the href of every matched element.
2103 * @example $("a").href("test2.html");
2104 * @before <a href="test.html">my link</a>
2105 * @result <a href="test2.html">my link</a>
2109 * @param String val Set the property to the specified value.
2110 * @cat DOM/Attributes
2115 * Get the current src of the first matched element.
2117 * @example $("img").src();
2118 * @before <img src="test.jpg" title="my image"/>
2119 * @result "test.jpg"
2123 * @cat DOM/Attributes
2127 * Set the src of every matched element.
2129 * @example $("img").src("test2.jpg");
2130 * @before <img src="test.jpg" title="my image"/>
2131 * @result <img src="test2.jpg" title="my image"/>
2135 * @param String val Set the property to the specified value.
2136 * @cat DOM/Attributes
2141 * Get the current rel of the first matched element.
2143 * @example $("a").rel();
2144 * @before <a href="test.html" rel="nofollow">my link</a>
2145 * @result "nofollow"
2149 * @cat DOM/Attributes
2153 * Set the rel of every matched element.
2155 * @example $("a").rel("nofollow");
2156 * @before <a href="test.html">my link</a>
2157 * @result <a href="test.html" rel="nofollow">my link</a>
2161 * @param String val Set the property to the specified value.
2162 * @cat DOM/Attributes
2169 * Get a set of elements containing the unique parents of the matched
2172 * @example $("p").parent()
2173 * @before <div><p>Hello</p><p>Hello</p></div>
2174 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2178 * @cat DOM/Traversing
2182 * Get a set of elements containing the unique parents of the matched
2183 * set of elements, and filtered by an expression.
2185 * @example $("p").parent(".selected")
2186 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2187 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2191 * @param String expr An expression to filter the parents with
2192 * @cat DOM/Traversing
2194 parent: "a.parentNode",
2197 * Get a set of elements containing the unique ancestors of the matched
2200 * @example $("span").ancestors()
2201 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2202 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2206 * @cat DOM/Traversing
2210 * Get a set of elements containing the unique ancestors of the matched
2211 * set of elements, and filtered by an expression.
2213 * @example $("span").ancestors("p")
2214 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2215 * @result [ <p><span>Hello</span></p> ]
2219 * @param String expr An expression to filter the ancestors with
2220 * @cat DOM/Traversing
2222 ancestors: jQuery.parents,
2225 * Get a set of elements containing the unique ancestors of the matched
2228 * @example $("span").ancestors()
2229 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2230 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2234 * @cat DOM/Traversing
2238 * Get a set of elements containing the unique ancestors of the matched
2239 * set of elements, and filtered by an expression.
2241 * @example $("span").ancestors("p")
2242 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2243 * @result [ <p><span>Hello</span></p> ]
2247 * @param String expr An expression to filter the ancestors with
2248 * @cat DOM/Traversing
2250 parents: jQuery.parents,
2253 * Get a set of elements containing the unique next siblings of each of the
2254 * matched set of elements.
2256 * It only returns the very next sibling, not all next siblings.
2258 * @example $("p").next()
2259 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2260 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2264 * @cat DOM/Traversing
2268 * Get a set of elements containing the unique next siblings of each of the
2269 * matched set of elements, and filtered by an expression.
2271 * It only returns the very next sibling, not all next siblings.
2273 * @example $("p").next(".selected")
2274 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2275 * @result [ <p class="selected">Hello Again</p> ]
2279 * @param String expr An expression to filter the next Elements with
2280 * @cat DOM/Traversing
2282 next: "jQuery.sibling(a).next",
2285 * Get a set of elements containing the unique previous siblings of each of the
2286 * matched set of elements.
2288 * It only returns the immediately previous sibling, not all previous siblings.
2290 * @example $("p").previous()
2291 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2292 * @result [ <div><span>Hello Again</span></div> ]
2296 * @cat DOM/Traversing
2300 * Get a set of elements containing the unique previous siblings of each of the
2301 * matched set of elements, and filtered by an expression.
2303 * It only returns the immediately previous sibling, not all previous siblings.
2305 * @example $("p").previous(".selected")
2306 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2307 * @result [ <div><span>Hello</span></div> ]
2311 * @param String expr An expression to filter the previous Elements with
2312 * @cat DOM/Traversing
2314 prev: "jQuery.sibling(a).prev",
2317 * Get a set of elements containing all of the unique siblings of each of the
2318 * matched set of elements.
2320 * @example $("div").siblings()
2321 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2322 * @result [ <p>Hello</p>, <p>And Again</p> ]
2326 * @cat DOM/Traversing
2330 * Get a set of elements containing all of the unique siblings of each of the
2331 * matched set of elements, and filtered by an expression.
2333 * @example $("div").siblings(".selected")
2334 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2335 * @result [ <p class="selected">Hello Again</p> ]
2339 * @param String expr An expression to filter the sibling Elements with
2340 * @cat DOM/Traversing
2342 siblings: jQuery.sibling,
2346 * Get a set of elements containing all of the unique children of each of the
2347 * matched set of elements.
2349 * @example $("div").children()
2350 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2351 * @result [ <span>Hello Again</span> ]
2355 * @cat DOM/Traversing
2359 * Get a set of elements containing all of the unique children of each of the
2360 * matched set of elements, and filtered by an expression.
2362 * @example $("div").children(".selected")
2363 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2364 * @result [ <p class="selected">Hello Again</p> ]
2368 * @param String expr An expression to filter the child Elements with
2369 * @cat DOM/Traversing
2371 children: "a.childNodes"
2376 removeAttr: function( key ) {
2377 this.removeAttribute( key );
2381 * Displays each of the set of matched elements if they are hidden.
2383 * @example $("p").show()
2384 * @before <p style="display: none">Hello</p>
2385 * @result [ <p style="display: block">Hello</p> ]
2387 * @test var pass = true, div = $("div");
2388 * div.show().each(function(){
2389 * if ( this.style.display == "none" ) pass = false;
2391 * ok( pass, "Show" );
2398 this.style.display = this.oldblock ? this.oldblock : "";
2399 if ( jQuery.css(this,"display") == "none" )
2400 this.style.display = "block";
2404 * Hides each of the set of matched elements if they are shown.
2406 * @example $("p").hide()
2407 * @before <p>Hello</p>
2408 * @result [ <p style="display: none">Hello</p> ]
2410 * var pass = true, div = $("div");
2411 * div.hide().each(function(){
2412 * if ( this.style.display != "none" ) pass = false;
2414 * ok( pass, "Hide" );
2421 this.oldblock = this.oldblock || jQuery.css(this,"display");
2422 if ( this.oldblock == "none" )
2423 this.oldblock = "block";
2424 this.style.display = "none";
2428 * Toggles each of the set of matched elements. If they are shown,
2429 * toggle makes them hidden. If they are hidden, toggle
2432 * @example $("p").toggle()
2433 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2434 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2440 _toggle: function(){
2441 var d = jQuery.css(this,"display");
2442 $(this)[ !d || d == "none" ? "show" : "hide" ]();
2446 * Adds the specified class to each of the set of matched elements.
2448 * @example $("p").addClass("selected")
2449 * @before <p>Hello</p>
2450 * @result [ <p class="selected">Hello</p> ]
2452 * @test var div = $("div");
2453 * div.addClass("test");
2455 * for ( var i = 0; i < div.size(); i++ ) {
2456 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2458 * ok( pass, "Add Class" );
2462 * @param String class A CSS class to add to the elements
2465 addClass: function(c){
2466 jQuery.className.add(this,c);
2470 * Removes the specified class from the set of matched elements.
2472 * @example $("p").removeClass("selected")
2473 * @before <p class="selected">Hello</p>
2474 * @result [ <p>Hello</p> ]
2476 * @test var div = $("div").addClass("test");
2477 * div.removeClass("test");
2479 * for ( var i = 0; i < div.size(); i++ ) {
2480 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2482 * ok( pass, "Remove Class" );
2486 * @param String class A CSS class to remove from the elements
2489 removeClass: function(c){
2490 jQuery.className.remove(this,c);
2494 * Adds the specified class if it is present, removes it if it is
2497 * @example $("p").toggleClass("selected")
2498 * @before <p>Hello</p><p class="selected">Hello Again</p>
2499 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2503 * @param String class A CSS class with which to toggle the elements
2506 toggleClass: function( c ){
2507 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2511 * Removes all matched elements from the DOM. This does NOT remove them from the
2512 * jQuery object, allowing you to use the matched elements further.
2514 * @example $("p").remove();
2515 * @before <p>Hello</p> how are <p>you?</p>
2520 * @cat DOM/Manipulation
2524 * Removes only elements (out of the list of matched elements) that match
2525 * the specified jQuery expression. This does NOT remove them from the
2526 * jQuery object, allowing you to use the matched elements further.
2528 * @example $("p").remove(".hello");
2529 * @before <p class="hello">Hello</p> how are <p>you?</p>
2530 * @result how are <p>you?</p>
2534 * @param String expr A jQuery expression to filter elements by.
2535 * @cat DOM/Manipulation
2537 remove: function(a){
2538 if ( !a || jQuery.filter( [this], a ).r )
2539 this.parentNode.removeChild( this );
2543 * Removes all child nodes from the set of matched elements.
2545 * @example $("p").empty()
2546 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2547 * @result [ <p></p> ]
2551 * @cat DOM/Manipulation
2554 while ( this.firstChild )
2555 this.removeChild( this.firstChild );
2559 * Binds a particular event (like click) to a each of a set of match elements.
2561 * @example $("p").bind( "click", function() { alert("Hello"); } )
2562 * @before <p>Hello</p>
2563 * @result [ <p>Hello</p> ]
2565 * Cancel a default action and prevent it from bubbling by returning false
2566 * from your function.
2568 * @example $("form").bind( "submit", function() { return false; } )
2570 * Cancel a default action by using the preventDefault method.
2572 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2574 * Stop an event from bubbling by using the stopPropogation method.
2576 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2580 * @param String type An event type
2581 * @param Function fn A function to bind to the event on each of the set of matched elements
2584 bind: function( type, fn ) {
2585 if ( fn.constructor == String )
2586 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2587 jQuery.event.add( this, type, fn );
2591 * The opposite of bind, removes a bound event from each of the matched
2592 * elements. You must pass the identical function that was used in the original
2595 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2596 * @before <p onclick="alert('Hello');">Hello</p>
2597 * @result [ <p>Hello</p> ]
2601 * @param String type An event type
2602 * @param Function fn A function to unbind from the event on each of the set of matched elements
2607 * Removes all bound events of a particular type from each of the matched
2610 * @example $("p").unbind( "click" )
2611 * @before <p onclick="alert('Hello');">Hello</p>
2612 * @result [ <p>Hello</p> ]
2616 * @param String type An event type
2621 * Removes all bound events from each of the matched elements.
2623 * @example $("p").unbind()
2624 * @before <p onclick="alert('Hello');">Hello</p>
2625 * @result [ <p>Hello</p> ]
2631 unbind: function( type, fn ) {
2632 jQuery.event.remove( this, type, fn );
2636 * Trigger a type of event on every matched element.
2638 * @example $("p").trigger("click")
2639 * @before <p click="alert('hello')">Hello</p>
2640 * @result alert('hello')
2644 * @param String type An event type to trigger.
2647 trigger: function( type, data ) {
2648 jQuery.event.trigger( type, data, this );