2 * jQuery - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Licensed under the MIT License:
6 * http://www.opensource.org/licenses/mit-license.php
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 // Initalize the extra macro functions
33 if ( !jQuery.initDone ) jQuery.init();
35 // Shortcut for document ready (because $(document).each() is silly)
36 if ( a && a.constructor == Function && jQuery.fn.ready )
37 return jQuery(document).ready(a);
39 // Make sure that a selection was provided
40 a = a || jQuery.context || document;
43 * Handle support for overriding other $() functions. Way too many libraries
44 * provide this function to simply ignore it and overwrite it.
47 // Check to see if this is a possible collision case
48 if ( jQuery._$ && !c && a.constructor == String &&
50 // Make sure that the expression is a colliding one
51 !/[^a-zA-Z0-9_-]/.test(a) &&
53 // and that there are no elements that match it
54 // (this is the one truly ambiguous case)
55 !document.getElementsByTagName(a).length )
57 // Use the default method, in case it works some voodoo
58 return jQuery._$( a );
61 // Watch for when a jQuery object is passed as the selector
62 if ( a.jquery ) return a;
64 // Watch for when a jQuery object is passed at the context
65 if ( c && c.jquery ) return c.find(a);
67 // If the context is global, return a new object
69 return new jQuery(a,c);
71 // Handle HTML strings
72 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
73 if ( m ) a = jQuery.clean( [ m[1] ] );
75 // Watch for when an array is passed in
76 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
77 // Assume that it is an array of DOM Elements
78 jQuery.merge( a, [] ) :
80 // Find the matching elements and save them for later
81 jQuery.find( a, c ) );
83 var fn = arguments[ arguments.length - 1 ];
84 if ( fn && fn.constructor == Function )
88 // Map over the $ in case of overwrite
92 // Map the jQuery namespace to the '$' one
95 jQuery.fn = jQuery.prototype = {
97 * The current SVN version of jQuery.
108 * The number of elements currently matched.
110 * @example $("img").length;
111 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
114 * @test cmpOK( $("div").length, "==", 2, "Get Number of Elements Found" );
123 * The number of elements currently matched.
125 * @example $("img").size();
126 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
129 * @test cmpOK( $("div").size(), "==", 2, "Get Number of Elements Found" );
140 * Access all matched elements. This serves as a backwards-compatible
141 * way of accessing all matched elements (other than the jQuery object
142 * itself, which is, in fact, an array of elements).
144 * @example $("img").get();
145 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
146 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
148 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
151 * @type Array<Element>
156 * Access a single matched element. num is used to access the
157 * Nth element matched.
159 * @example $("img").get(1);
160 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
161 * @result [ <img src="test1.jpg"/> ]
163 * @test cmpOK( $("div").get(0), "==", document.getElementById("main"), "Get A Single Element" );
167 * @param Number num Access the element in the Nth position.
172 * Set the jQuery object to an array of elements.
174 * @example $("img").get([ document.body ]);
175 * @result $("img").get() == [ document.body ]
180 * @param Elements elems An array of elements
183 get: function( num ) {
184 // Watch for when an array (of elements) is passed in
185 if ( num && num.constructor == Array ) {
187 // Use a tricky hack to make the jQuery object
188 // look and feel like an array
190 [].push.apply( this, num );
194 return num == undefined ?
196 // Return a 'clean' array
197 jQuery.map( this, function(a){ return a } ) :
199 // Return just the object
204 * Execute a function within the context of every matched element.
205 * This means that every time the passed-in function is executed
206 * (which is once for every element matched) the 'this' keyword
207 * points to the specific element.
209 * Additionally, the function, when executed, is passed a single
210 * argument representing the position of the element in the matched
213 * @example $("img").each(function(){ this.src = "test.jpg"; });
214 * @before <img/> <img/>
215 * @result <img src="test.jpg"/> <img src="test.jpg"/>
217 * @test var div = $("div");
218 * div.each(function(){this.foo = 'zoo';});
220 * for ( var i = 0; i < div.size(); i++ ) {
221 * if ( div.get(i).foo != "zoo" ) pass = false;
223 * ok( pass, "Execute a function, Relative" );
227 * @param Function fn A function to execute
230 each: function( fn, args ) {
231 return jQuery.each( this, fn, args );
235 * Access a property on the first matched element.
236 * This method makes it easy to retreive a property value
237 * from the first matched element.
239 * @example $("img").attr("src");
240 * @before <img src="test.jpg"/>
245 * @param String name The name of the property to access.
250 * Set a hash of key/value object properties to all matched elements.
251 * This serves as the best way to set a large number of properties
252 * on all matched elements.
254 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
256 * @result <img src="test.jpg" alt="Test Image"/>
258 * @test var div = $("div");
259 * div.attr({foo: 'baz', zoo: 'ping'});
261 * for ( var i = 0; i < div.size(); i++ ) {
262 * if ( div.get(i).foo != "baz" && div.get(i).zoo != "ping" ) pass = false;
264 * ok( pass, "Set Multiple Attributes" );
268 * @param Hash prop A set of key/value pairs to set as object properties.
273 * Set a single property to a value, on all matched elements.
275 * @example $("img").attr("src","test.jpg");
277 * @result <img src="test.jpg"/>
279 * @test var div = $("div");
280 * div.attr("foo", "bar");
282 * for ( var i = 0; i < div.size(); i++ ) {
283 * if ( div.get(i).foo != "bar" ) pass = false;
285 * ok( pass, "Set Attribute" );
289 * @param String key The name of the property to set.
290 * @param Object value The value to set the property to.
293 attr: function( key, value, type ) {
294 // Check to see if we're setting style values
295 return key.constructor != String || value != undefined ?
296 this.each(function(){
297 // See if we're setting a hash of styles
298 if ( value == undefined )
299 // Set all the styles
300 for ( var prop in key )
302 type ? this.style : this,
306 // See if we're setting a single key/value style
309 type ? this.style : this,
314 // Look for the case where we're accessing a style value
315 jQuery[ type || "attr" ]( this[0], key );
319 * Access a style property on the first matched element.
320 * This method makes it easy to retreive a style property value
321 * from the first matched element.
323 * @example $("p").css("red");
324 * @before <p style="color:red;">Test Paragraph.</p>
329 * @param String name The name of the property to access.
334 * Set a hash of key/value style properties to all matched elements.
335 * This serves as the best way to set a large number of style properties
336 * on all matched elements.
338 * @example $("p").css({ color: "red", background: "blue" });
339 * @before <p>Test Paragraph.</p>
340 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
344 * @param Hash prop A set of key/value pairs to set as style properties.
349 * Set a single style property to a value, on all matched elements.
351 * @example $("p").css("color","red");
352 * @before <p>Test Paragraph.</p>
353 * @result <p style="color:red;">Test Paragraph.</p>
357 * @param String key The name of the property to set.
358 * @param Object value The value to set the property to.
361 css: function( key, value ) {
362 return this.attr( key, value, "curCSS" );
366 * Retreive the text contents of all matched elements. The result is
367 * a string that contains the combined text contents of all matched
368 * elements. This method works on both HTML and XML documents.
370 * @example $("p").text();
371 * @before <p>Test Paragraph.</p>
372 * @result Test Paragraph.
381 for ( var j = 0; j < e.length; j++ ) {
382 var r = e[j].childNodes;
383 for ( var i = 0; i < r.length; i++ )
384 t += r[i].nodeType != 1 ?
385 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
391 * Wrap all matched elements with a structure of other elements.
392 * This wrapping process is most useful for injecting additional
393 * stucture into a document, without ruining the original semantic
394 * qualities of a document.
396 * The way that is works is that it goes through the first element argument
397 * provided and finds the deepest element within the structure - it is that
398 * element that will en-wrap everything else.
400 * @example $("p").wrap("<div class='wrap'></div>");
401 * @before <p>Test Paragraph.</p>
402 * @result <div class='wrap'><p>Test Paragraph.</p></div>
406 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
407 * @any Element elem A DOM element that will be wrapped.
408 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
409 * @any Object obj Any object, converted to a string, then a text node.
410 * @cat DOM/Manipulation
413 // The elements to wrap the target around
414 var a = jQuery.clean(arguments);
416 // Wrap each of the matched elements individually
417 return this.each(function(){
418 // Clone the structure that we're using to wrap
419 var b = a[0].cloneNode(true);
421 // Insert it before the element to be wrapped
422 this.parentNode.insertBefore( b, this );
424 // Find he deepest point in the wrap structure
425 while ( b.firstChild )
428 // Move the matched element to within the wrap structure
429 b.appendChild( this );
434 * Append any number of elements to the inside of all matched elements.
435 * This operation is similar to doing an appendChild to all the
436 * specified elements, adding them into the document.
438 * @example $("p").append("<b>Hello</b>");
439 * @before <p>I would like to say: </p>
440 * @result <p>I would like to say: <b>Hello</b></p>
444 * @any String html A string of HTML, that will be created on the fly and appended to the target.
445 * @any Element elem A DOM element that will be appended.
446 * @any Array<Element> elems An array of elements, all of which will be appended.
447 * @any Object obj Any object, converted to a string, then a text node.
448 * @cat DOM/Manipulation
451 return this.domManip(arguments, true, 1, function(a){
452 this.appendChild( a );
457 * Prepend any number of elements to the inside of all matched elements.
458 * This operation is the best way to insert a set of elements inside, at the
459 * beginning, of all the matched element.
461 * @example $("p").prepend("<b>Hello</b>");
462 * @before <p>, how are you?</p>
463 * @result <p><b>Hello</b>, how are you?</p>
467 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
468 * @any Element elem A DOM element that will be prepended.
469 * @any Array<Element> elems An array of elements, all of which will be prepended.
470 * @any Object obj Any object, converted to a string, then a text node.
471 * @cat DOM/Manipulation
473 prepend: function() {
474 return this.domManip(arguments, true, -1, function(a){
475 this.insertBefore( a, this.firstChild );
480 * Insert any number of elements before each of the matched elements.
482 * @example $("p").before("<b>Hello</b>");
483 * @before <p>how are you?</p>
484 * @result <b>Hello</b><p>how are you?</p>
488 * @any String html A string of HTML, that will be created on the fly and inserted.
489 * @any Element elem A DOM element that will beinserted.
490 * @any Array<Element> elems An array of elements, all of which will be inserted.
491 * @any Object obj Any object, converted to a string, then a text node.
492 * @cat DOM/Manipulation
495 return this.domManip(arguments, false, 1, function(a){
496 this.parentNode.insertBefore( a, this );
501 * Insert any number of elements after each of the matched elements.
503 * @example $("p").after("<p>I'm doing fine.</p>");
504 * @before <p>How are you?</p>
505 * @result <p>How are you?</p><p>I'm doing fine.</p>
509 * @any String html A string of HTML, that will be created on the fly and inserted.
510 * @any Element elem A DOM element that will beinserted.
511 * @any Array<Element> elems An array of elements, all of which will be inserted.
512 * @any Object obj Any object, converted to a string, then a text node.
513 * @cat DOM/Manipulation
516 return this.domManip(arguments, false, -1, function(a){
517 this.parentNode.insertBefore( a, this.nextSibling );
522 * End the most recent 'destructive' operation, reverting the list of matched elements
523 * back to its previous state. After an end operation, the list of matched elements will
524 * revert to the last state of matched elements.
526 * @example $("p").find("span").end();
527 * @before <p><span>Hello</span>, how are you?</p>
528 * @result $("p").find("span").end() == [ <p>...</p> ]
532 * @cat DOM/Traversing
535 return this.get( this.stack.pop() );
539 * Searches for all elements that match the specified expression.
540 * This method is the optimal way of finding additional descendant
541 * elements with which to process.
543 * All searching is done using a jQuery expression. The expression can be
544 * written using CSS 1-3 Selector syntax, or basic XPath.
546 * @example $("p").find("span");
547 * @before <p><span>Hello</span>, how are you?</p>
548 * @result $("p").find("span") == [ <span>Hello</span> ]
552 * @param String expr An expression to search with.
553 * @cat DOM/Traversing
556 return this.pushStack( jQuery.map( this, function(a){
557 return jQuery.find(t,a);
561 clone: function(deep) {
562 return this.pushStack( jQuery.map( this, function(a){
563 return a.cloneNode( deep != undefined ? deep : true );
568 * Removes all elements from the set of matched elements that do not
569 * match the specified expression. This method is used to narrow down
570 * the results of a search.
572 * All searching is done using a jQuery expression. The expression
573 * can be written using CSS 1-3 Selector syntax, or basic XPath.
575 * @example $("p").filter(".selected")
576 * @before <p class="selected">Hello</p><p>How are you?</p>
577 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
581 * @param String expr An expression to search with.
582 * @cat DOM/Traversing
586 * Removes all elements from the set of matched elements that do not
587 * match at least one of the expressions passed to the function. This
588 * method is used when you want to filter the set of matched elements
589 * through more than one expression.
591 * Elements will be retained in the jQuery object if they match at
592 * least one of the expressions passed.
594 * @example $("p").filter([".selected", ":first"])
595 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
596 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
600 * @param Array<String> exprs A set of expressions to evaluate against
601 * @cat DOM/Traversing
603 filter: function(t) {
604 return this.pushStack(
605 t.constructor == Array &&
606 jQuery.map(this,function(a){
607 for ( var i = 0; i < t.length; i++ )
608 if ( jQuery.filter(t[i],[a]).r.length )
612 t.constructor == Boolean &&
613 ( t ? this.get() : [] ) ||
615 t.constructor == Function &&
616 jQuery.grep( this, t ) ||
618 jQuery.filter(t,this).r, arguments );
622 * Removes the specified Element from the set of matched elements. This
623 * method is used to remove a single Element from a jQuery object.
625 * @example $("p").not( document.getElementById("selected") )
626 * @before <p>Hello</p><p id="selected">Hello Again</p>
627 * @result [ <p>Hello</p> ]
631 * @param Element el An element to remove from the set
632 * @cat DOM/Traversing
636 * Removes elements matching the specified expression from the set
637 * of matched elements. This method is used to remove one or more
638 * elements from a jQuery object.
640 * @example $("p").not("#selected")
641 * @before <p>Hello</p><p id="selected">Hello Again</p>
642 * @result [ <p>Hello</p> ]
646 * @param String expr An expression with which to remove matching elements
647 * @cat DOM/Traversing
650 return this.pushStack( t.constructor == String ?
651 jQuery.filter(t,this,false).r :
652 jQuery.grep(this,function(a){ return a != t; }), arguments );
656 * Adds the elements matched by the expression to the jQuery object. This
657 * can be used to concatenate the result sets of two expressions.
659 * @example $("p").add("span")
660 * @before <p>Hello</p><p><span>Hello Again</span></p>
661 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
665 * @param String expr An expression whose matched elements are added
666 * @cat DOM/Traversing
670 * Adds each of the Elements in the array to the set of matched elements.
671 * This is used to add a set of Elements to a jQuery object.
673 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
674 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
675 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
679 * @param Array<Element> els An array of Elements to add
684 * Adds a single Element to the set of matched elements. This is used to
685 * add a single Element to a jQuery object.
687 * @example $("p").add( document.getElementById("a") )
688 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
689 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
693 * @param Element el An Element to add
697 return this.pushStack( jQuery.merge( this, t.constructor == String ?
698 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
702 * A wrapper function for each() to be used by append and prepend.
703 * Handles cases where you're trying to modify the inner contents of
704 * a table, when you actually need to work with the tbody.
707 * @param {String} expr The expression with which to filter
712 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
721 * @param Boolean table
723 * @param Function fn The function doing the DOM manipulation.
726 domManip: function(args, table, dir, fn){
727 var clone = this.size() > 1;
728 var a = jQuery.clean(args);
730 return this.each(function(){
733 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
734 var tbody = this.getElementsByTagName("tbody");
736 if ( !tbody.length ) {
737 obj = document.createElement("tbody");
738 this.appendChild( obj );
743 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
744 i != ( dir < 0 ? dir : a.length ); i += dir ) {
745 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
759 pushStack: function(a,args) {
760 var fn = args && args[args.length-1];
762 if ( !fn || fn.constructor != Function ) {
763 if ( !this.stack ) this.stack = [];
764 this.stack.push( this.get() );
767 var old = this.get();
769 if ( fn.constructor == Function )
770 return this.each( fn );
789 * Extend one object with another, returning the original,
790 * modified, object. This is a great utility for simple inheritance.
792 * @name jQuery.extend
793 * @param Object obj The object to extend
794 * @param Object prop The object that will be merged into the first.
798 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
799 if ( !prop ) { prop = obj; obj = this; }
800 for ( var i in prop ) obj[i] = prop[i];
813 jQuery.initDone = true;
815 jQuery.each( jQuery.macros.axis, function(i,n){
816 jQuery.fn[ i ] = function(a) {
817 var ret = jQuery.map(this,n);
818 if ( a && a.constructor == String )
819 ret = jQuery.filter(a,ret).r;
820 return this.pushStack( ret, arguments );
824 jQuery.each( jQuery.macros.to, function(i,n){
825 jQuery.fn[ i ] = function(){
827 return this.each(function(){
828 for ( var j = 0; j < a.length; j++ )
834 jQuery.each( jQuery.macros.each, function(i,n){
835 jQuery.fn[ i ] = function() {
836 return this.each( n, arguments );
840 jQuery.each( jQuery.macros.filter, function(i,n){
841 jQuery.fn[ n ] = function(num,fn) {
842 return this.filter( ":" + n + "(" + num + ")", fn );
846 jQuery.each( jQuery.macros.attr, function(i,n){
848 jQuery.fn[ i ] = function(h) {
849 return h == undefined ?
850 this.length ? this[0][n] : null :
855 jQuery.each( jQuery.macros.css, function(i,n){
856 jQuery.fn[ n ] = function(h) {
857 return h == undefined ?
858 ( this.length ? jQuery.css( this[0], n ) : null ) :
866 * A generic iterator function, which can be used to seemlessly
867 * iterate over both objects and arrays.
870 * @param Object obj The object, or array, to iterate over.
871 * @param Object fn The function that will be executed on every object.
875 each: function( obj, fn, args ) {
876 if ( obj.length == undefined )
878 fn.apply( obj[i], args || [i, obj[i]] );
880 for ( var i = 0; i < obj.length; i++ )
881 fn.apply( obj[i], args || [i, obj[i]] );
887 if (jQuery.className.has(o,c)) return;
888 o.className += ( o.className ? " " : "" ) + c;
890 remove: function(o,c){
891 o.className = !c ? "" :
893 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
898 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
903 * Swap in/out style options.
906 swap: function(e,o,f) {
908 e.style["old"+i] = e.style[i];
913 e.style[i] = e.style["old"+i];
917 if ( p == "height" || p == "width" ) {
918 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
921 old["padding" + d[i]] = 0;
922 old["border" + d[i] + "Width"] = 0;
925 jQuery.swap( e, old, function() {
926 if (jQuery.css(e,"display") != "none") {
927 oHeight = e.offsetHeight;
928 oWidth = e.offsetWidth;
930 jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
932 oHeight = e.clientHeight;
933 oWidth = e.clientWidth;
937 return p == "height" ? oHeight : oWidth;
938 } else if ( p == "opacity" && jQuery.browser.msie )
939 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
941 return jQuery.curCSS( e, p );
944 curCSS: function(e,p,force) {
947 if (!force && e.style[p])
949 else if (e.currentStyle) {
950 p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
951 r = e.currentStyle[p];
952 } else if (document.defaultView && document.defaultView.getComputedStyle) {
953 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
954 var s = document.defaultView.getComputedStyle(e,"");
955 r = s ? s.getPropertyValue(p) : null;
963 for ( var i = 0; i < a.length; i++ ) {
964 if ( a[i].constructor == String ) {
968 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
970 a[i] = "<table>" + a[i] + "</table>";
971 } else if ( !a[i].indexOf("<tr") ) {
973 a[i] = "<table>" + a[i] + "</table>";
974 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
976 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
979 var div = document.createElement("div");
980 div.innerHTML = a[i];
983 div = div.firstChild;
984 if ( table != "thead" ) div = div.firstChild;
985 if ( table == "td" ) div = div.firstChild;
988 for ( var j = 0; j < div.childNodes.length; j++ )
989 r.push( div.childNodes[j] );
990 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
991 for ( var k = 0; k < a[i].length; k++ )
993 else if ( a[i] !== null )
994 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1000 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1001 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1009 last: "i==r.length-1",
1014 "first-child": "jQuery.sibling(a,0).cur",
1015 "last-child": "jQuery.sibling(a,0).last",
1016 "only-child": "jQuery.sibling(a).length==1",
1019 parent: "a.childNodes.length",
1020 empty: "!a.childNodes.length",
1023 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1026 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1027 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1030 enabled: "!a.disabled",
1031 disabled: "a.disabled",
1032 checked: "a.checked"
1034 ".": "jQuery.className.has(a,m[2])",
1038 "^=": "!z.indexOf(m[4])",
1039 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1040 "*=": "z.indexOf(m[4])>=0",
1043 "[": "jQuery.find(m[2],a).length"
1047 "\\.\\.|/\\.\\.", "a.parentNode",
1048 ">|/", "jQuery.sibling(a.firstChild)",
1049 "\\+", "jQuery.sibling(a).next",
1052 var s = jQuery.sibling(a);
1054 for ( var i = s.n; i < s.length; i++ )
1062 * @test t( "Element Selector", "div", ["main","foo"] );
1063 * @test t( "Element Selector", "body", ["body"] );
1064 * @test t( "Element Selector", "html", ["html"] );
1065 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1066 * @test t( "Parent Element", "div div", ["foo"] );
1068 * @test t( "ID Selector", "#body", ["body"] );
1069 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1070 * @test t( "ID Selector w/ Element", "ul#first", [] );
1072 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1073 * @test t( "Class Selector", ".blog.link", ["simon"] );
1074 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1075 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1077 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1078 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1079 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1080 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1082 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1083 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
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 w/ Class", "p > a.blog", ["mark","simon"] );
1087 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1088 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1089 * @test t( "Adjacent", "a + a", ["groups"] );
1090 * @test t( "Adjacent", "a +a", ["groups"] );
1091 * @test t( "Adjacent", "a+ a", ["groups"] );
1092 * @test t( "Adjacent", "a+a", ["groups"] );
1093 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1094 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1095 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1096 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1097 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1098 * @test t( "Attribute Exists", "[@title]", ["google"] );
1099 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1100 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1101 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1102 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1103 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1104 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1106 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1107 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1108 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1109 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1110 * @test t( "Last Child", "p:last-child", ["sap"] );
1111 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1112 * @test t( "Empty", "ul:empty", ["firstUL"] );
1113 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1114 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1115 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1116 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1117 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1118 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1119 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1121 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1122 * @test t( "All Div Elements", "//div", ["main","foo"] );
1123 * @test t( "Absolute Path", "/html/body", ["body"] );
1124 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1125 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1126 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1127 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1128 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1129 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1130 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1131 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1132 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1133 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1134 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1136 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1137 * @test t( "First Element", "p:first", ["firstp"] );
1138 * @test t( "Last Element", "p:last", ["first"] );
1139 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1140 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1141 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1142 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1143 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1144 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1145 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1146 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1151 find: function( t, context ) {
1152 // Make sure that the context is a DOM Element
1153 if ( context && context.nodeType == undefined )
1156 // Set the correct context (if none is provided)
1157 context = context || jQuery.context || document;
1159 if ( t.constructor != String ) return [t];
1161 if ( !t.indexOf("//") ) {
1162 context = context.documentElement;
1163 t = t.substr(2,t.length);
1164 } else if ( !t.indexOf("/") ) {
1165 context = context.documentElement;
1166 t = t.substr(1,t.length);
1167 // FIX Assume the root element is right :(
1168 if ( t.indexOf("/") >= 1 )
1169 t = t.substr(t.indexOf("/"),t.length);
1172 var ret = [context];
1176 while ( t.length > 0 && last != t ) {
1180 t = jQuery.trim(t).replace( /^\/\//i, "" );
1182 var foundToken = false;
1184 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1185 var re = new RegExp("^(" + jQuery.token[i] + ")");
1189 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1190 t = jQuery.trim( t.replace( re, "" ) );
1195 if ( !foundToken ) {
1196 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1197 if ( ret[0] == context ) ret.shift();
1198 done = jQuery.merge( done, ret );
1199 r = ret = [context];
1200 t = " " + t.substr(1,t.length);
1202 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1203 var m = re2.exec(t);
1205 if ( m[1] == "#" ) {
1206 // Ummm, should make this work in all XML docs
1207 var oid = document.getElementById(m[2]);
1208 r = ret = oid ? [oid] : [];
1209 t = t.replace( re2, "" );
1211 if ( !m[2] || m[1] == "." ) m[2] = "*";
1213 for ( var i = 0; i < ret.length; i++ )
1214 r = jQuery.merge( r,
1216 jQuery.getAll(ret[i]) :
1217 ret[i].getElementsByTagName(m[2])
1224 var val = jQuery.filter(t,r);
1226 t = jQuery.trim(val.t);
1230 if ( ret && ret[0] == context ) ret.shift();
1231 done = jQuery.merge( done, ret );
1236 getAll: function(o,r) {
1238 var s = o.childNodes;
1239 for ( var i = 0; i < s.length; i++ )
1240 if ( s[i].nodeType == 1 ) {
1242 jQuery.getAll( s[i], r );
1247 attr: function(o,a,v){
1248 if ( a && a.constructor == String ) {
1251 "class": "className",
1255 a = (fix[a] && fix[a].replace && fix[a] || a)
1256 .replace(/-([a-z])/ig,function(z,b){
1257 return b.toUpperCase();
1260 if ( v != undefined ) {
1262 if ( o.setAttribute && a != "disabled" )
1263 o.setAttribute(a,v);
1266 return o[a] || o.getAttribute && o.getAttribute(a) || "";
1271 // The regular expressions that power the parsing engine
1273 // Match: [@value='test'], [@foo]
1274 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1276 // Match: [div], [div p]
1279 // Match: :contains('foo')
1280 [ "(:)S\\(Q\\)", 0 ],
1282 // Match: :even, :last-chlid
1286 filter: function(t,r,not) {
1287 // Figure out if we're doing regular, or inverse, filtering
1288 var g = not !== false ? jQuery.grep :
1289 function(a,f) {return jQuery.grep(a,f,true);};
1291 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1293 var p = jQuery.parse;
1295 for ( var i = 0; i < p.length; i++ ) {
1296 var re = new RegExp( "^" + p[i][0]
1298 // Look for a string-like sequence
1299 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1301 // Look for something (optionally) enclosed with quotes
1302 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1304 var m = re.exec( t );
1307 // Re-organize the match
1309 m = ["", m[1], m[3], m[2], m[4]];
1311 // Remove what we just matched
1312 t = t.replace( re, "" );
1318 // :not() is a special case that can be optomized by
1319 // keeping it out of the expression list
1320 if ( m[1] == ":" && m[2] == "not" )
1321 r = jQuery.filter(m[3],r,false).r;
1323 // Otherwise, find the expression to execute
1325 var f = jQuery.expr[m[1]];
1326 if ( f.constructor != String )
1327 f = jQuery.expr[m[1]][m[2]];
1329 // Build a custom macro to enclose it
1330 eval("f = function(a,i){" +
1331 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1332 "return " + f + "}");
1334 // Execute it against the current filter
1339 // Return an array of filtered elements (r)
1340 // and the modified expression string (t)
1341 return { r: r, t: t };
1345 * Remove the whitespace from the beginning and end of a string.
1350 * @param String str The string to trim.
1353 return t.replace(/^\s+|\s+$/g, "");
1357 * All ancestors of a given element.
1360 * @name jQuery.parents
1361 * @type Array<Element>
1362 * @param Element elem The element to find the ancestors of.
1364 parents: function(a){
1366 var c = a.parentNode;
1367 while ( c && c != document ) {
1375 * All elements on a specified axis.
1378 * @name jQuery.sibling
1380 * @param Element elem The element to find all the siblings of (including itself).
1382 sibling: function(a,n) {
1384 var tmp = a.parentNode.childNodes;
1385 for ( var i = 0; i < tmp.length; i++ ) {
1386 if ( tmp[i].nodeType == 1 )
1387 type.push( tmp[i] );
1389 type.n = type.length - 1;
1391 type.last = type.n == type.length - 1;
1393 n == "even" && type.n % 2 == 0 ||
1394 n == "odd" && type.n % 2 ||
1396 type.prev = type[type.n - 1];
1397 type.next = type[type.n + 1];
1402 * Merge two arrays together, removing all duplicates.
1405 * @name jQuery.merge
1407 * @param Array a The first array to merge.
1408 * @param Array b The second array to merge.
1410 merge: function(a,b) {
1413 // Move b over to the new array (this helps to avoid
1414 // StaticNodeList instances)
1415 for ( var k = 0; k < a.length; k++ )
1418 // Now check for duplicates between a and b and only
1419 // add the unique items
1420 for ( var i = 0; i < b.length; i++ ) {
1423 // The collision-checking process
1424 for ( var j = 0; j < a.length; j++ )
1428 // If the item is unique, add it
1437 * Remove items that aren't matched in an array. The function passed
1438 * in to this method will be passed two arguments: 'a' (which is the
1439 * array item) and 'i' (which is the index of the item in the array).
1444 * @param Array array The Array to find items in.
1445 * @param Function fn The function to process each item against.
1446 * @param Boolean inv Invert the selection - select the opposite of the function.
1448 grep: function(a,f,s) {
1449 // If a string is passed in for the function, make a function
1450 // for it (a handy shortcut)
1451 if ( f.constructor == String )
1452 f = new Function("a","i","return " + f);
1456 // Go through the array, only saving the items
1457 // that pass the validator function
1458 for ( var i = 0; i < a.length; i++ )
1459 if ( !s && f(a[i],i) || s && !f(a[i],i) )
1466 * Translate all items in array to another array of items. The translation function
1467 * that is provided to this method is passed one argument: 'a' (the item to be
1468 * translated). If an array is returned, that array is mapped out and merged into
1469 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1470 * from the array. Both of these changes imply that the size of the array may not
1471 * be the same size upon completion, as it was when it started.
1476 * @param Array array The Array to translate.
1477 * @param Function fn The function to process each item against.
1479 map: function(a,f) {
1480 // If a string is passed in for the function, make a function
1481 // for it (a handy shortcut)
1482 if ( f.constructor == String )
1483 f = new Function("a","return " + f);
1487 // Go through the array, translating each of the items to their
1488 // new value (or values).
1489 for ( var i = 0; i < a.length; i++ ) {
1491 if ( t !== null && t != undefined ) {
1492 if ( t.constructor != Array ) t = [t];
1493 r = jQuery.merge( r, t );
1500 * A number of helper functions used for managing events.
1501 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1505 // Bind an event to an element
1506 // Original by Dean Edwards
1507 add: function(element, type, handler) {
1508 // For whatever reason, IE has trouble passing the window object
1509 // around, causing it to be cloned in the process
1510 if ( jQuery.browser.msie && element.setInterval != undefined )
1513 // Make sure that the function being executed has a unique ID
1514 if ( !handler.guid )
1515 handler.guid = this.guid++;
1517 // Init the element's event structure
1518 if (!element.events)
1519 element.events = {};
1521 // Get the current list of functions bound to this event
1522 var handlers = element.events[type];
1524 // If it hasn't been initialized yet
1526 // Init the event handler queue
1527 handlers = element.events[type] = {};
1529 // Remember an existing handler, if it's already there
1530 if (element["on" + type])
1531 handlers[0] = element["on" + type];
1534 // Add the function to the element's handler list
1535 handlers[handler.guid] = handler;
1537 // And bind the global event handler to the element
1538 element["on" + type] = this.handle;
1540 // Remember the function in a global list (for triggering)
1541 if (!this.global[type])
1542 this.global[type] = [];
1543 this.global[type].push( element );
1549 // Detach an event or set of events from an element
1550 remove: function(element, type, handler) {
1552 if (type && element.events[type])
1554 delete element.events[type][handler.guid];
1556 for ( var i in element.events[type] )
1557 delete element.events[type][i];
1559 for ( var j in element.events )
1560 this.remove( element, j );
1563 trigger: function(type,data,element) {
1564 // Touch up the incoming data
1567 // Handle a global trigger
1569 var g = this.global[type];
1571 for ( var i = 0; i < g.length; i++ )
1572 this.trigger( type, data, g[i] );
1574 // Handle triggering a single element
1575 } else if ( element["on" + type] ) {
1576 // Pass along a fake event
1577 data.unshift( this.fix({ type: type, target: element }) );
1579 // Trigger the event
1580 element["on" + type].apply( element, data );
1584 handle: function(event) {
1585 if ( typeof jQuery == "undefined" ) return;
1587 event = event || jQuery.event.fix( window.event );
1589 // If no correct event was found, fail
1590 if ( !event ) return;
1592 var returnValue = true;
1594 var c = this.events[event.type];
1596 for ( var j in c ) {
1597 if ( c[j].apply( this, [event] ) === false ) {
1598 event.preventDefault();
1599 event.stopPropagation();
1600 returnValue = false;
1607 fix: function(event) {
1609 event.preventDefault = function() {
1610 this.returnValue = false;
1613 event.stopPropagation = function() {
1614 this.cancelBubble = true;
1625 var b = navigator.userAgent.toLowerCase();
1627 // Figure out what browser is being used
1629 safari: /webkit/.test(b),
1630 opera: /opera/.test(b),
1631 msie: /msie/.test(b) && !/opera/.test(b),
1632 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1635 // Check to see if the W3C box model is being used
1636 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1642 * Append all of the matched elements to another, specified, set of elements.
1643 * This operation is, essentially, the reverse of doing a regular
1644 * $(A).append(B), in that instead of appending B to A, you're appending
1647 * @example $("p").appendTo("#foo");
1648 * @before <p>I would like to say: </p><div id="foo"></div>
1649 * @result <div id="foo"><p>I would like to say: </p></div>
1653 * @param String expr A jQuery expression of elements to match.
1654 * @cat DOM/Manipulation
1659 * Prepend all of the matched elements to another, specified, set of elements.
1660 * This operation is, essentially, the reverse of doing a regular
1661 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1664 * @example $("p").prependTo("#foo");
1665 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1666 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1670 * @param String expr A jQuery expression of elements to match.
1671 * @cat DOM/Manipulation
1673 prependTo: "prepend",
1676 * Insert all of the matched elements before another, specified, set of elements.
1677 * This operation is, essentially, the reverse of doing a regular
1678 * $(A).before(B), in that instead of inserting B before A, you're inserting
1681 * @example $("p").insertBefore("#foo");
1682 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1683 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1685 * @name insertBefore
1687 * @param String expr A jQuery expression of elements to match.
1688 * @cat DOM/Manipulation
1690 insertBefore: "before",
1693 * Insert all of the matched elements after another, specified, set of elements.
1694 * This operation is, essentially, the reverse of doing a regular
1695 * $(A).after(B), in that instead of inserting B after A, you're inserting
1698 * @example $("p").insertAfter("#foo");
1699 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1700 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1704 * @param String expr A jQuery expression of elements to match.
1705 * @cat DOM/Manipulation
1707 insertAfter: "after"
1711 * Get the current CSS width of the first matched element.
1713 * @example $("p").width();
1714 * @before <p>This is just a test.</p>
1723 * Set the CSS width of every matched element. Be sure to include
1724 * the "px" (or other unit of measurement) after the number that you
1725 * specify, otherwise you might get strange results.
1727 * @example $("p").width("20px");
1728 * @before <p>This is just a test.</p>
1729 * @result <p style="width:20px;">This is just a test.</p>
1733 * @param String val Set the CSS property to the specified value.
1738 * Get the current CSS height of the first matched element.
1740 * @example $("p").height();
1741 * @before <p>This is just a test.</p>
1750 * Set the CSS height of every matched element. Be sure to include
1751 * the "px" (or other unit of measurement) after the number that you
1752 * specify, otherwise you might get strange results.
1754 * @example $("p").height("20px");
1755 * @before <p>This is just a test.</p>
1756 * @result <p style="height:20px;">This is just a test.</p>
1760 * @param String val Set the CSS property to the specified value.
1765 * Get the current CSS top of the first matched element.
1767 * @example $("p").top();
1768 * @before <p>This is just a test.</p>
1777 * Set the CSS top of every matched element. Be sure to include
1778 * the "px" (or other unit of measurement) after the number that you
1779 * specify, otherwise you might get strange results.
1781 * @example $("p").top("20px");
1782 * @before <p>This is just a test.</p>
1783 * @result <p style="top:20px;">This is just a test.</p>
1787 * @param String val Set the CSS property to the specified value.
1792 * Get the current CSS left of the first matched element.
1794 * @example $("p").left();
1795 * @before <p>This is just a test.</p>
1804 * Set the CSS left of every matched element. Be sure to include
1805 * the "px" (or other unit of measurement) after the number that you
1806 * specify, otherwise you might get strange results.
1808 * @example $("p").left("20px");
1809 * @before <p>This is just a test.</p>
1810 * @result <p style="left:20px;">This is just a test.</p>
1814 * @param String val Set the CSS property to the specified value.
1819 * Get the current CSS position of the first matched element.
1821 * @example $("p").position();
1822 * @before <p>This is just a test.</p>
1831 * Set the CSS position of every matched element.
1833 * @example $("p").position("relative");
1834 * @before <p>This is just a test.</p>
1835 * @result <p style="position:relative;">This is just a test.</p>
1839 * @param String val Set the CSS property to the specified value.
1844 * Get the current CSS float of the first matched element.
1846 * @example $("p").float();
1847 * @before <p>This is just a test.</p>
1856 * Set the CSS float of every matched element.
1858 * @example $("p").float("left");
1859 * @before <p>This is just a test.</p>
1860 * @result <p style="float:left;">This is just a test.</p>
1864 * @param String val Set the CSS property to the specified value.
1869 * Get the current CSS overflow of the first matched element.
1871 * @example $("p").overflow();
1872 * @before <p>This is just a test.</p>
1881 * Set the CSS overflow of every matched element.
1883 * @example $("p").overflow("auto");
1884 * @before <p>This is just a test.</p>
1885 * @result <p style="overflow:auto;">This is just a test.</p>
1889 * @param String val Set the CSS property to the specified value.
1894 * Get the current CSS color of the first matched element.
1896 * @example $("p").color();
1897 * @before <p>This is just a test.</p>
1906 * Set the CSS color of every matched element.
1908 * @example $("p").color("blue");
1909 * @before <p>This is just a test.</p>
1910 * @result <p style="color:blue;">This is just a test.</p>
1914 * @param String val Set the CSS property to the specified value.
1919 * Get the current CSS background of the first matched element.
1921 * @example $("p").background();
1922 * @before <p>This is just a test.</p>
1931 * Set the CSS background of every matched element.
1933 * @example $("p").background("blue");
1934 * @before <p>This is just a test.</p>
1935 * @result <p style="background:blue;">This is just a test.</p>
1939 * @param String val Set the CSS property to the specified value.
1943 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1945 filter: [ "eq", "lt", "gt", "contains" ],
1949 * Get the current value of the first matched element.
1951 * @example $("input").val();
1952 * @before <input type="text" value="some text"/>
1953 * @result "some text"
1957 * @cat DOM/Attributes
1961 * Set the value of every matched element.
1963 * @example $("input").value("test");
1964 * @before <input type="text" value="some text"/>
1965 * @result <input type="text" value="test"/>
1969 * @param String val Set the property to the specified value.
1970 * @cat DOM/Attributes
1975 * Get the html contents of the first matched element.
1977 * @example $("div").html();
1978 * @before <div><input/></div>
1983 * @cat DOM/Attributes
1987 * Set the html contents of every matched element.
1989 * @example $("div").html("<b>new stuff</b>");
1990 * @before <div><input/></div>
1991 * @result <div><b>new stuff</b></div>
1993 * @test var div = $("div");
1994 * div.html("<b>test</b>");
1996 * for ( var i = 0; i < div.size(); i++ ) {
1997 * if ( div.get(i).childNodes.length == 0 ) pass = false;
1999 * ok( pass, "Set HTML" );
2003 * @param String val Set the html contents to the specified value.
2004 * @cat DOM/Attributes
2009 * Get the current id of the first matched element.
2011 * @example $("input").id();
2012 * @before <input type="text" id="test" value="some text"/>
2017 * @cat DOM/Attributes
2021 * Set the id of every matched element.
2023 * @example $("input").id("newid");
2024 * @before <input type="text" id="test" value="some text"/>
2025 * @result <input type="text" id="newid" value="some text"/>
2029 * @param String val Set the property to the specified value.
2030 * @cat DOM/Attributes
2035 * Get the current title of the first matched element.
2037 * @example $("img").title();
2038 * @before <img src="test.jpg" title="my image"/>
2039 * @result "my image"
2043 * @cat DOM/Attributes
2047 * Set the title of every matched element.
2049 * @example $("img").title("new title");
2050 * @before <img src="test.jpg" title="my image"/>
2051 * @result <img src="test.jpg" title="new image"/>
2055 * @param String val Set the property to the specified value.
2056 * @cat DOM/Attributes
2061 * Get the current name of the first matched element.
2063 * @example $("input").name();
2064 * @before <input type="text" name="username"/>
2065 * @result "username"
2069 * @cat DOM/Attributes
2073 * Set the name of every matched element.
2075 * @example $("input").name("user");
2076 * @before <input type="text" name="username"/>
2077 * @result <input type="text" name="user"/>
2081 * @param String val Set the property to the specified value.
2082 * @cat DOM/Attributes
2087 * Get the current href of the first matched element.
2089 * @example $("a").href();
2090 * @before <a href="test.html">my link</a>
2091 * @result "test.html"
2095 * @cat DOM/Attributes
2099 * Set the href of every matched element.
2101 * @example $("a").href("test2.html");
2102 * @before <a href="test.html">my link</a>
2103 * @result <a href="test2.html">my link</a>
2107 * @param String val Set the property to the specified value.
2108 * @cat DOM/Attributes
2113 * Get the current src of the first matched element.
2115 * @example $("img").src();
2116 * @before <img src="test.jpg" title="my image"/>
2117 * @result "test.jpg"
2121 * @cat DOM/Attributes
2125 * Set the src of every matched element.
2127 * @example $("img").src("test2.jpg");
2128 * @before <img src="test.jpg" title="my image"/>
2129 * @result <img src="test2.jpg" title="my image"/>
2133 * @param String val Set the property to the specified value.
2134 * @cat DOM/Attributes
2139 * Get the current rel of the first matched element.
2141 * @example $("a").rel();
2142 * @before <a href="test.html" rel="nofollow">my link</a>
2143 * @result "nofollow"
2147 * @cat DOM/Attributes
2151 * Set the rel of every matched element.
2153 * @example $("a").rel("nofollow");
2154 * @before <a href="test.html">my link</a>
2155 * @result <a href="test.html" rel="nofollow">my link</a>
2159 * @param String val Set the property to the specified value.
2160 * @cat DOM/Attributes
2167 * Get a set of elements containing the unique parents of the matched
2170 * @example $("p").parent()
2171 * @before <div><p>Hello</p><p>Hello</p></div>
2172 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2176 * @cat DOM/Traversing
2180 * Get a set of elements containing the unique parents of the matched
2181 * set of elements, and filtered by an expression.
2183 * @example $("p").parent(".selected")
2184 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2185 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2189 * @param String expr An expression to filter the parents with
2190 * @cat DOM/Traversing
2192 parent: "a.parentNode",
2195 * Get a set of elements containing the unique ancestors of the matched
2198 * @example $("span").ancestors()
2199 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2200 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2204 * @cat DOM/Traversing
2208 * Get a set of elements containing the unique ancestors of the matched
2209 * set of elements, and filtered by an expression.
2211 * @example $("span").ancestors("p")
2212 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2213 * @result [ <p><span>Hello</span></p> ]
2217 * @param String expr An expression to filter the ancestors with
2218 * @cat DOM/Traversing
2220 ancestors: jQuery.parents,
2223 * Get a set of elements containing the unique ancestors of the matched
2226 * @example $("span").ancestors()
2227 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2228 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2232 * @cat DOM/Traversing
2236 * Get a set of elements containing the unique ancestors of the matched
2237 * set of elements, and filtered by an expression.
2239 * @example $("span").ancestors("p")
2240 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2241 * @result [ <p><span>Hello</span></p> ]
2245 * @param String expr An expression to filter the ancestors with
2246 * @cat DOM/Traversing
2248 parents: jQuery.parents,
2251 * Get a set of elements containing the unique next siblings of each of the
2252 * matched set of elements.
2254 * It only returns the very next sibling, not all next siblings.
2256 * @example $("p").next()
2257 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2258 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2262 * @cat DOM/Traversing
2266 * Get a set of elements containing the unique next siblings of each of the
2267 * matched set of elements, and filtered by an expression.
2269 * It only returns the very next sibling, not all next siblings.
2271 * @example $("p").next(".selected")
2272 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2273 * @result [ <p class="selected">Hello Again</p> ]
2277 * @param String expr An expression to filter the next Elements with
2278 * @cat DOM/Traversing
2280 next: "jQuery.sibling(a).next",
2283 * Get a set of elements containing the unique previous siblings of each of the
2284 * matched set of elements.
2286 * It only returns the immediately previous sibling, not all previous siblings.
2288 * @example $("p").previous()
2289 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2290 * @result [ <div><span>Hello Again</span></div> ]
2294 * @cat DOM/Traversing
2298 * Get a set of elements containing the unique previous siblings of each of the
2299 * matched set of elements, and filtered by an expression.
2301 * It only returns the immediately previous sibling, not all previous siblings.
2303 * @example $("p").previous(".selected")
2304 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2305 * @result [ <div><span>Hello</span></div> ]
2309 * @param String expr An expression to filter the previous Elements with
2310 * @cat DOM/Traversing
2312 prev: "jQuery.sibling(a).prev",
2315 * Get a set of elements containing all of the unique siblings of each of the
2316 * matched set of elements.
2318 * @example $("div").siblings()
2319 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2320 * @result [ <p>Hello</p>, <p>And Again</p> ]
2324 * @cat DOM/Traversing
2328 * Get a set of elements containing all of the unique siblings of each of the
2329 * matched set of elements, and filtered by an expression.
2331 * @example $("div").siblings(".selected")
2332 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2333 * @result [ <p class="selected">Hello Again</p> ]
2337 * @param String expr An expression to filter the sibling Elements with
2338 * @cat DOM/Traversing
2340 siblings: jQuery.sibling,
2344 * Get a set of elements containing all of the unique children of each of the
2345 * matched set of elements.
2347 * @example $("div").children()
2348 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2349 * @result [ <span>Hello Again</span> ]
2353 * @cat DOM/Traversing
2357 * Get a set of elements containing all of the unique children of each of the
2358 * matched set of elements, and filtered by an expression.
2360 * @example $("div").children(".selected")
2361 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2362 * @result [ <p class="selected">Hello Again</p> ]
2366 * @param String expr An expression to filter the child Elements with
2367 * @cat DOM/Traversing
2369 children: "a.childNodes"
2374 * Displays each of the set of matched elements if they are hidden.
2376 * @example $("p").show()
2377 * @before <p style="display: none">Hello</p>
2378 * @result [ <p style="display: block">Hello</p> ]
2380 * @test var pass = true, div = $("div");
2381 * div.show().each(function(){
2382 * if ( this.style.display == "none" ) pass = false;
2384 * ok( pass, "Show" );
2391 this.style.display = this.oldblock ? this.oldblock : "";
2392 if ( jQuery.css(this,"display") == "none" )
2393 this.style.display = "block";
2397 * Hides each of the set of matched elements if they are shown.
2399 * @example $("p").hide()
2400 * @before <p>Hello</p>
2401 * @result [ <p style="display: none">Hello</p> ]
2403 * var pass = true, div = $("div");
2404 * div.hide().each(function(){
2405 * if ( this.style.display != "none" ) pass = false;
2407 * ok( pass, "Hide" );
2414 this.oldblock = this.oldblock || jQuery.css(this,"display");
2415 if ( this.oldblock == "none" )
2416 this.oldblock = "block";
2417 this.style.display = "none";
2421 * Toggles each of the set of matched elements. If they are shown,
2422 * toggle makes them hidden. If they are hidden, toggle
2425 * @example $("p").toggle()
2426 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2427 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2433 _toggle: function(){
2434 var d = jQuery.css(this,"display");
2435 $(this)[ !d || d == "none" ? "show" : "hide" ]();
2439 * Adds the specified class to each of the set of matched elements.
2441 * @example $("p").addClass("selected")
2442 * @before <p>Hello</p>
2443 * @result [ <p class="selected">Hello</p> ]
2445 * @test var div = $("div");
2446 * div.addClass("test");
2448 * for ( var i = 0; i < div.size(); i++ ) {
2449 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2451 * ok( pass, "Add Class" );
2455 * @param String class A CSS class to add to the elements
2458 addClass: function(c){
2459 jQuery.className.add(this,c);
2463 * Removes the specified class from the set of matched elements.
2465 * @example $("p").removeClass("selected")
2466 * @before <p class="selected">Hello</p>
2467 * @result [ <p>Hello</p> ]
2469 * @test var div = $("div").addClass("test");
2470 * div.removeClass("test");
2472 * for ( var i = 0; i < div.size(); i++ ) {
2473 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2475 * ok( pass, "Remove Class" );
2479 * @param String class A CSS class to remove from the elements
2482 removeClass: function(c){
2483 jQuery.className.remove(this,c);
2487 * Adds the specified class if it is present, removes it if it is
2490 * @example $("p").toggleClass("selected")
2491 * @before <p>Hello</p><p class="selected">Hello Again</p>
2492 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2496 * @param String class A CSS class with which to toggle the elements
2499 toggleClass: function( c ){
2500 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2504 * Removes all matched elements from the DOM. This does NOT remove them from the
2505 * jQuery object, allowing you to use the matched elements further.
2507 * @example $("p").remove();
2508 * @before <p>Hello</p> how are <p>you?</p>
2513 * @cat DOM/Manipulation
2517 * Removes only elements (out of the list of matched elements) that match
2518 * the specified jQuery expression. This does NOT remove them from the
2519 * jQuery object, allowing you to use the matched elements further.
2521 * @example $("p").remove(".hello");
2522 * @before <p class="hello">Hello</p> how are <p>you?</p>
2523 * @result how are <p>you?</p>
2527 * @param String expr A jQuery expression to filter elements by.
2528 * @cat DOM/Manipulation
2530 remove: function(a){
2531 if ( !a || jQuery.filter( [this], a ).r )
2532 this.parentNode.removeChild( this );
2536 * Removes all child nodes from the set of matched elements.
2538 * @example $("p").empty()
2539 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2540 * @result [ <p></p> ]
2544 * @cat DOM/Manipulation
2547 while ( this.firstChild )
2548 this.removeChild( this.firstChild );
2552 * Binds a particular event (like click) to a each of a set of match elements.
2554 * @example $("p").bind( "click", function() { alert("Hello"); } )
2555 * @before <p>Hello</p>
2556 * @result [ <p>Hello</p> ]
2558 * Cancel a default action and prevent it from bubbling by returning false
2559 * from your function.
2561 * @example $("form").bind( "submit", function() { return false; } )
2563 * Cancel a default action by using the preventDefault method.
2565 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2567 * Stop an event from bubbling by using the stopPropogation method.
2569 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2573 * @param String type An event type
2574 * @param Function fn A function to bind to the event on each of the set of matched elements
2577 bind: function( type, fn ) {
2578 if ( fn.constructor == String )
2579 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2580 jQuery.event.add( this, type, fn );
2584 * The opposite of bind, removes a bound event from each of the matched
2585 * elements. You must pass the identical function that was used in the original
2588 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2589 * @before <p onclick="alert('Hello');">Hello</p>
2590 * @result [ <p>Hello</p> ]
2594 * @param String type An event type
2595 * @param Function fn A function to unbind from the event on each of the set of matched elements
2600 * Removes all bound events of a particular type from each of the matched
2603 * @example $("p").unbind( "click" )
2604 * @before <p onclick="alert('Hello');">Hello</p>
2605 * @result [ <p>Hello</p> ]
2609 * @param String type An event type
2614 * Removes all bound events from each of the matched elements.
2616 * @example $("p").unbind()
2617 * @before <p onclick="alert('Hello');">Hello</p>
2618 * @result [ <p>Hello</p> ]
2624 unbind: function( type, fn ) {
2625 jQuery.event.remove( this, type, fn );
2629 * Trigger a type of event on every matched element.
2631 * @example $("p").trigger("click")
2632 * @before <p click="alert('hello')">Hello</p>
2633 * @result alert('hello')
2637 * @param String type An event type to trigger.
2640 trigger: function( type, data ) {
2641 jQuery.event.trigger( type, data, this );