2 * jQuery - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
18 * @test ok( Array.prototype.push, "Array.push()" );
19 * @test ok( Function.prototype.apply, "Function.apply()" );
20 * @test ok( document.getElementById, "getElementById" );
21 * @test ok( document.getElementsByTagName, "getElementsByTagName" );
22 * @test ok( RegExp, "RegExp" );
23 * @test ok( jQuery, "jQuery" );
24 * @test ok( $, "$()" );
30 function jQuery(a,c) {
32 // 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
63 return $( jQuery.merge( a, [] ) );
65 // Watch for when a jQuery object is passed at the context
67 return $( c ).find(a);
69 // If the context is global, return a new object
71 return new jQuery(a,c);
73 // Handle HTML strings
74 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
75 if ( m ) a = jQuery.clean( [ m[1] ] );
77 // Watch for when an array is passed in
78 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
79 // Assume that it is an array of DOM Elements
80 jQuery.merge( a, [] ) :
82 // Find the matching elements and save them for later
83 jQuery.find( a, c ) );
85 var fn = arguments[ arguments.length - 1 ];
86 if ( fn && fn.constructor == Function )
90 // Map over the $ in case of overwrite
94 // Map the jQuery namespace to the '$' one
97 jQuery.fn = jQuery.prototype = {
99 * The current SVN version of jQuery.
110 * The number of elements currently matched.
112 * @example $("img").length;
113 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
116 * @test cmpOK( $("div").length, "==", 2, "Get Number of Elements Found" );
125 * The number of elements currently matched.
127 * @example $("img").size();
128 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
131 * @test cmpOK( $("div").size(), "==", 2, "Get Number of Elements Found" );
142 * Access all matched elements. This serves as a backwards-compatible
143 * way of accessing all matched elements (other than the jQuery object
144 * itself, which is, in fact, an array of elements).
146 * @example $("img").get();
147 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
148 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
150 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
153 * @type Array<Element>
158 * Access a single matched element. num is used to access the
159 * Nth element matched.
161 * @example $("img").get(1);
162 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
163 * @result [ <img src="test1.jpg"/> ]
165 * @test cmpOK( $("div").get(0), "==", document.getElementById("main"), "Get A Single Element" );
169 * @param Number num Access the element in the Nth position.
174 * Set the jQuery object to an array of elements.
176 * @example $("img").get([ document.body ]);
177 * @result $("img").get() == [ document.body ]
182 * @param Elements elems An array of elements
185 get: function( num ) {
186 // Watch for when an array (of elements) is passed in
187 if ( num && num.constructor == Array ) {
189 // Use a tricky hack to make the jQuery object
190 // look and feel like an array
192 [].push.apply( this, num );
196 return num == undefined ?
198 // Return a 'clean' array
199 jQuery.map( this, function(a){ return a } ) :
201 // Return just the object
206 * Execute a function within the context of every matched element.
207 * This means that every time the passed-in function is executed
208 * (which is once for every element matched) the 'this' keyword
209 * points to the specific element.
211 * Additionally, the function, when executed, is passed a single
212 * argument representing the position of the element in the matched
215 * @example $("img").each(function(){ this.src = "test.jpg"; });
216 * @before <img/> <img/>
217 * @result <img src="test.jpg"/> <img src="test.jpg"/>
219 * @test var div = $("div");
220 * div.each(function(){this.foo = 'zoo';});
222 * for ( var i = 0; i < div.size(); i++ ) {
223 * if ( div.get(i).foo != "zoo" ) pass = false;
225 * ok( pass, "Execute a function, Relative" );
229 * @param Function fn A function to execute
232 each: function( fn, args ) {
233 return jQuery.each( this, fn, args );
236 index: function( obj ) {
238 this.each(function(i){
239 if ( this == obj ) pos = i;
245 * Access a property on the first matched element.
246 * This method makes it easy to retreive a property value
247 * from the first matched element.
249 * @example $("img").attr("src");
250 * @before <img src="test.jpg"/>
255 * @param String name The name of the property to access.
260 * Set a hash of key/value object properties to all matched elements.
261 * This serves as the best way to set a large number of properties
262 * on all matched elements.
264 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
266 * @result <img src="test.jpg" alt="Test Image"/>
268 * @test var div = $("div");
269 * div.attr({foo: 'baz', zoo: 'ping'});
271 * for ( var i = 0; i < div.size(); i++ ) {
272 * if ( div.get(i).foo != "baz" && div.get(i).zoo != "ping" ) pass = false;
274 * ok( pass, "Set Multiple Attributes" );
278 * @param Hash prop A set of key/value pairs to set as object properties.
283 * Set a single property to a value, on all matched elements.
285 * @example $("img").attr("src","test.jpg");
287 * @result <img src="test.jpg"/>
289 * @test var div = $("div");
290 * div.attr("foo", "bar");
292 * for ( var i = 0; i < div.size(); i++ ) {
293 * if ( div.get(i).foo != "bar" ) pass = false;
295 * ok( pass, "Set Attribute" );
299 * @param String key The name of the property to set.
300 * @param Object value The value to set the property to.
303 attr: function( key, value, type ) {
304 // Check to see if we're setting style values
305 return key.constructor != String || value != undefined ?
306 this.each(function(){
307 // See if we're setting a hash of styles
308 if ( value == undefined )
309 // Set all the styles
310 for ( var prop in key )
312 type ? this.style : this,
316 // See if we're setting a single key/value style
319 type ? this.style : this,
324 // Look for the case where we're accessing a style value
325 jQuery[ type || "attr" ]( this[0], key );
329 * Access a style property on the first matched element.
330 * This method makes it easy to retreive a style property value
331 * from the first matched element.
333 * @example $("p").css("red");
334 * @before <p style="color:red;">Test Paragraph.</p>
339 * @param String name The name of the property to access.
344 * Set a hash of key/value style properties to all matched elements.
345 * This serves as the best way to set a large number of style properties
346 * on all matched elements.
348 * @example $("p").css({ color: "red", background: "blue" });
349 * @before <p>Test Paragraph.</p>
350 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
354 * @param Hash prop A set of key/value pairs to set as style properties.
359 * Set a single style property to a value, on all matched elements.
361 * @example $("p").css("color","red");
362 * @before <p>Test Paragraph.</p>
363 * @result <p style="color:red;">Test Paragraph.</p>
367 * @param String key The name of the property to set.
368 * @param Object value The value to set the property to.
371 css: function( key, value ) {
372 return this.attr( key, value, "curCSS" );
376 * Retreive the text contents of all matched elements. The result is
377 * a string that contains the combined text contents of all matched
378 * elements. This method works on both HTML and XML documents.
380 * @example $("p").text();
381 * @before <p>Test Paragraph.</p>
382 * @result Test Paragraph.
391 for ( var j = 0; j < e.length; j++ ) {
392 var r = e[j].childNodes;
393 for ( var i = 0; i < r.length; i++ )
394 t += r[i].nodeType != 1 ?
395 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
401 * Wrap all matched elements with a structure of other elements.
402 * This wrapping process is most useful for injecting additional
403 * stucture into a document, without ruining the original semantic
404 * qualities of a document.
406 * The way that is works is that it goes through the first element argument
407 * provided and finds the deepest element within the structure - it is that
408 * element that will en-wrap everything else.
410 * @example $("p").wrap("<div class='wrap'></div>");
411 * @before <p>Test Paragraph.</p>
412 * @result <div class='wrap'><p>Test Paragraph.</p></div>
416 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
417 * @any Element elem A DOM element that will be wrapped.
418 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
419 * @any Object obj Any object, converted to a string, then a text node.
420 * @cat DOM/Manipulation
423 // The elements to wrap the target around
424 var a = jQuery.clean(arguments);
426 // Wrap each of the matched elements individually
427 return this.each(function(){
428 // Clone the structure that we're using to wrap
429 var b = a[0].cloneNode(true);
431 // Insert it before the element to be wrapped
432 this.parentNode.insertBefore( b, this );
434 // Find he deepest point in the wrap structure
435 while ( b.firstChild )
438 // Move the matched element to within the wrap structure
439 b.appendChild( this );
444 * Append any number of elements to the inside of all matched elements.
445 * This operation is similar to doing an appendChild to all the
446 * specified elements, adding them into the document.
448 * @example $("p").append("<b>Hello</b>");
449 * @before <p>I would like to say: </p>
450 * @result <p>I would like to say: <b>Hello</b></p>
454 * @any String html A string of HTML, that will be created on the fly and appended to the target.
455 * @any Element elem A DOM element that will be appended.
456 * @any Array<Element> elems An array of elements, all of which will be appended.
457 * @any Object obj Any object, converted to a string, then a text node.
458 * @cat DOM/Manipulation
461 return this.domManip(arguments, true, 1, function(a){
462 this.appendChild( a );
467 * Prepend any number of elements to the inside of all matched elements.
468 * This operation is the best way to insert a set of elements inside, at the
469 * beginning, of all the matched element.
471 * @example $("p").prepend("<b>Hello</b>");
472 * @before <p>, how are you?</p>
473 * @result <p><b>Hello</b>, how are you?</p>
477 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
478 * @any Element elem A DOM element that will be prepended.
479 * @any Array<Element> elems An array of elements, all of which will be prepended.
480 * @any Object obj Any object, converted to a string, then a text node.
481 * @cat DOM/Manipulation
483 prepend: function() {
484 return this.domManip(arguments, true, -1, function(a){
485 this.insertBefore( a, this.firstChild );
490 * Insert any number of elements before each of the matched elements.
492 * @example $("p").before("<b>Hello</b>");
493 * @before <p>how are you?</p>
494 * @result <b>Hello</b><p>how are you?</p>
498 * @any String html A string of HTML, that will be created on the fly and inserted.
499 * @any Element elem A DOM element that will beinserted.
500 * @any Array<Element> elems An array of elements, all of which will be inserted.
501 * @any Object obj Any object, converted to a string, then a text node.
502 * @cat DOM/Manipulation
505 return this.domManip(arguments, false, 1, function(a){
506 this.parentNode.insertBefore( a, this );
511 * Insert any number of elements after each of the matched elements.
513 * @example $("p").after("<p>I'm doing fine.</p>");
514 * @before <p>How are you?</p>
515 * @result <p>How are you?</p><p>I'm doing fine.</p>
519 * @any String html A string of HTML, that will be created on the fly and inserted.
520 * @any Element elem A DOM element that will beinserted.
521 * @any Array<Element> elems An array of elements, all of which will be inserted.
522 * @any Object obj Any object, converted to a string, then a text node.
523 * @cat DOM/Manipulation
526 return this.domManip(arguments, false, -1, function(a){
527 this.parentNode.insertBefore( a, this.nextSibling );
532 * End the most recent 'destructive' operation, reverting the list of matched elements
533 * back to its previous state. After an end operation, the list of matched elements will
534 * revert to the last state of matched elements.
536 * @example $("p").find("span").end();
537 * @before <p><span>Hello</span>, how are you?</p>
538 * @result $("p").find("span").end() == [ <p>...</p> ]
542 * @cat DOM/Traversing
545 return this.get( this.stack.pop() );
549 * Searches for all elements that match the specified expression.
550 * This method is the optimal way of finding additional descendant
551 * elements with which to process.
553 * All searching is done using a jQuery expression. The expression can be
554 * written using CSS 1-3 Selector syntax, or basic XPath.
556 * @example $("p").find("span");
557 * @before <p><span>Hello</span>, how are you?</p>
558 * @result $("p").find("span") == [ <span>Hello</span> ]
562 * @param String expr An expression to search with.
563 * @cat DOM/Traversing
566 return this.pushStack( jQuery.map( this, function(a){
567 return jQuery.find(t,a);
571 clone: function(deep) {
572 return this.pushStack( jQuery.map( this, function(a){
573 return a.cloneNode( deep != undefined ? deep : true );
578 * Removes all elements from the set of matched elements that do not
579 * match the specified expression. This method is used to narrow down
580 * the results of a search.
582 * All searching is done using a jQuery expression. The expression
583 * can be written using CSS 1-3 Selector syntax, or basic XPath.
585 * @example $("p").filter(".selected")
586 * @before <p class="selected">Hello</p><p>How are you?</p>
587 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
591 * @param String expr An expression to search with.
592 * @cat DOM/Traversing
596 * Removes all elements from the set of matched elements that do not
597 * match at least one of the expressions passed to the function. This
598 * method is used when you want to filter the set of matched elements
599 * through more than one expression.
601 * Elements will be retained in the jQuery object if they match at
602 * least one of the expressions passed.
604 * @example $("p").filter([".selected", ":first"])
605 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
606 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
610 * @param Array<String> exprs A set of expressions to evaluate against
611 * @cat DOM/Traversing
613 filter: function(t) {
614 return this.pushStack(
615 t.constructor == Array &&
616 jQuery.map(this,function(a){
617 for ( var i = 0; i < t.length; i++ )
618 if ( jQuery.filter(t[i],[a]).r.length )
622 t.constructor == Boolean &&
623 ( t ? this.get() : [] ) ||
625 t.constructor == Function &&
626 jQuery.grep( this, t ) ||
628 jQuery.filter(t,this).r, arguments );
632 * Removes the specified Element from the set of matched elements. This
633 * method is used to remove a single Element from a jQuery object.
635 * @example $("p").not( document.getElementById("selected") )
636 * @before <p>Hello</p><p id="selected">Hello Again</p>
637 * @result [ <p>Hello</p> ]
641 * @param Element el An element to remove from the set
642 * @cat DOM/Traversing
646 * Removes elements matching the specified expression from the set
647 * of matched elements. This method is used to remove one or more
648 * elements from a jQuery object.
650 * @example $("p").not("#selected")
651 * @before <p>Hello</p><p id="selected">Hello Again</p>
652 * @result [ <p>Hello</p> ]
656 * @param String expr An expression with which to remove matching elements
657 * @cat DOM/Traversing
660 return this.pushStack( t.constructor == String ?
661 jQuery.filter(t,this,false).r :
662 jQuery.grep(this,function(a){ return a != t; }), arguments );
666 * Adds the elements matched by the expression to the jQuery object. This
667 * can be used to concatenate the result sets of two expressions.
669 * @example $("p").add("span")
670 * @before <p>Hello</p><p><span>Hello Again</span></p>
671 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
675 * @param String expr An expression whose matched elements are added
676 * @cat DOM/Traversing
680 * Adds each of the Elements in the array to the set of matched elements.
681 * This is used to add a set of Elements to a jQuery object.
683 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
684 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
685 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
689 * @param Array<Element> els An array of Elements to add
694 * Adds a single Element to the set of matched elements. This is used to
695 * add a single Element to a jQuery object.
697 * @example $("p").add( document.getElementById("a") )
698 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
699 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
703 * @param Element el An Element to add
707 return this.pushStack( jQuery.merge( this, t.constructor == String ?
708 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
712 * A wrapper function for each() to be used by append and prepend.
713 * Handles cases where you're trying to modify the inner contents of
714 * a table, when you actually need to work with the tbody.
717 * @param {String} expr The expression with which to filter
722 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
731 * @param Boolean table
733 * @param Function fn The function doing the DOM manipulation.
736 domManip: function(args, table, dir, fn){
737 var clone = this.size() > 1;
738 var a = jQuery.clean(args);
740 return this.each(function(){
743 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
744 var tbody = this.getElementsByTagName("tbody");
746 if ( !tbody.length ) {
747 obj = document.createElement("tbody");
748 this.appendChild( obj );
753 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
754 i != ( dir < 0 ? dir : a.length ); i += dir ) {
755 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
769 pushStack: function(a,args) {
770 var fn = args && args[args.length-1];
772 if ( !fn || fn.constructor != Function ) {
773 if ( !this.stack ) this.stack = [];
774 this.stack.push( this.get() );
777 var old = this.get();
779 if ( fn.constructor == Function )
780 return this.each( fn );
799 * Extend one object with another, returning the original,
800 * modified, object. This is a great utility for simple inheritance.
802 * @name jQuery.extend
803 * @param Object obj The object to extend
804 * @param Object prop The object that will be merged into the first.
808 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
809 if ( !prop ) { prop = obj; obj = this; }
810 for ( var i in prop ) obj[i] = prop[i];
823 jQuery.initDone = true;
825 jQuery.each( jQuery.macros.axis, function(i,n){
826 jQuery.fn[ i ] = function(a) {
827 var ret = jQuery.map(this,n);
828 if ( a && a.constructor == String )
829 ret = jQuery.filter(a,ret).r;
830 return this.pushStack( ret, arguments );
834 jQuery.each( jQuery.macros.to, function(i,n){
835 jQuery.fn[ i ] = function(){
837 return this.each(function(){
838 for ( var j = 0; j < a.length; j++ )
844 jQuery.each( jQuery.macros.each, function(i,n){
845 jQuery.fn[ i ] = function() {
846 return this.each( n, arguments );
850 jQuery.each( jQuery.macros.filter, function(i,n){
851 jQuery.fn[ n ] = function(num,fn) {
852 return this.filter( ":" + n + "(" + num + ")", fn );
856 jQuery.each( jQuery.macros.attr, function(i,n){
858 jQuery.fn[ i ] = function(h) {
859 return h == undefined ?
860 this.length ? this[0][n] : null :
865 jQuery.each( jQuery.macros.css, function(i,n){
866 jQuery.fn[ n ] = function(h) {
867 return h == undefined ?
868 ( this.length ? jQuery.css( this[0], n ) : null ) :
876 * A generic iterator function, which can be used to seemlessly
877 * iterate over both objects and arrays.
880 * @param Object obj The object, or array, to iterate over.
881 * @param Object fn The function that will be executed on every object.
885 each: function( obj, fn, args ) {
886 if ( obj.length == undefined )
888 fn.apply( obj[i], args || [i, obj[i]] );
890 for ( var i = 0; i < obj.length; i++ )
891 fn.apply( obj[i], args || [i, obj[i]] );
897 if (jQuery.className.has(o,c)) return;
898 o.className += ( o.className ? " " : "" ) + c;
900 remove: function(o,c){
901 o.className = !c ? "" :
903 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
906 if ( e.className != undefined )
908 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
913 * Swap in/out style options.
916 swap: function(e,o,f) {
918 e.style["old"+i] = e.style[i];
923 e.style[i] = e.style["old"+i];
927 if ( p == "height" || p == "width" ) {
928 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
931 old["padding" + d[i]] = 0;
932 old["border" + d[i] + "Width"] = 0;
935 jQuery.swap( e, old, function() {
936 if (jQuery.css(e,"display") != "none") {
937 oHeight = e.offsetHeight;
938 oWidth = e.offsetWidth;
940 jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
942 oHeight = e.clientHeight;
943 oWidth = e.clientWidth;
947 return p == "height" ? oHeight : oWidth;
948 } else if ( p == "opacity" && jQuery.browser.msie )
949 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
951 return jQuery.curCSS( e, p );
954 curCSS: function(e,p,force) {
957 if (!force && e.style[p])
959 else if (e.currentStyle) {
960 p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
961 r = e.currentStyle[p];
962 } else if (document.defaultView && document.defaultView.getComputedStyle) {
963 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
964 var s = document.defaultView.getComputedStyle(e,"");
965 r = s ? s.getPropertyValue(p) : null;
973 for ( var i = 0; i < a.length; i++ ) {
974 if ( a[i].constructor == String ) {
978 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
980 a[i] = "<table>" + a[i] + "</table>";
981 } else if ( !a[i].indexOf("<tr") ) {
983 a[i] = "<table>" + a[i] + "</table>";
984 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
986 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
989 var div = document.createElement("div");
990 div.innerHTML = a[i];
993 div = div.firstChild;
994 if ( table != "thead" ) div = div.firstChild;
995 if ( table == "td" ) div = div.firstChild;
998 for ( var j = 0; j < div.childNodes.length; j++ )
999 r.push( div.childNodes[j] );
1000 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1001 for ( var k = 0; k < a[i].length; k++ )
1003 else if ( a[i] !== null )
1004 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1010 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1011 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1019 last: "i==r.length-1",
1024 "first-child": "jQuery.sibling(a,0).cur",
1025 "last-child": "jQuery.sibling(a,0).last",
1026 "only-child": "jQuery.sibling(a).length==1",
1029 parent: "a.childNodes.length",
1030 empty: "!a.childNodes.length",
1033 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1036 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1037 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1040 enabled: "!a.disabled",
1041 disabled: "a.disabled",
1042 checked: "a.checked",
1043 selected: "a.selected"
1045 ".": "jQuery.className.has(a,m[2])",
1049 "^=": "!z.indexOf(m[4])",
1050 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1051 "*=": "z.indexOf(m[4])>=0",
1054 "[": "jQuery.find(m[2],a).length"
1058 "\\.\\.|/\\.\\.", "a.parentNode",
1059 ">|/", "jQuery.sibling(a.firstChild)",
1060 "\\+", "jQuery.sibling(a).next",
1063 var s = jQuery.sibling(a);
1065 for ( var i = s.n; i < s.length; i++ )
1073 * @test t( "Element Selector", "div", ["main","foo"] );
1074 * @test t( "Element Selector", "body", ["body"] );
1075 * @test t( "Element Selector", "html", ["html"] );
1076 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1077 * @test t( "Parent Element", "div div", ["foo"] );
1079 * @test t( "ID Selector", "#body", ["body"] );
1080 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1081 * @test t( "ID Selector w/ Element", "ul#first", [] );
1083 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1084 * @test t( "Class Selector", ".blog.link", ["simon"] );
1085 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1086 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1088 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1089 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1090 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1091 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1093 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1094 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1095 * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1096 * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1097 * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1098 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1099 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1100 * @test t( "Adjacent", "a + a", ["groups"] );
1101 * @test t( "Adjacent", "a +a", ["groups"] );
1102 * @test t( "Adjacent", "a+ a", ["groups"] );
1103 * @test t( "Adjacent", "a+a", ["groups"] );
1104 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1105 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1106 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1107 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1108 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1109 * @test t( "Attribute Exists", "[@title]", ["google"] );
1110 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1111 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1112 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1113 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1114 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1115 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1117 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1118 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1119 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1120 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1121 * @test t( "Last Child", "p:last-child", ["sap"] );
1122 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1123 * @test t( "Empty", "ul:empty", ["firstUL"] );
1124 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1125 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1126 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1127 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1128 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1129 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1130 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1132 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1133 * @test t( "All Div Elements", "//div", ["main","foo"] );
1134 * @test t( "Absolute Path", "/html/body", ["body"] );
1135 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1136 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1137 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1138 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1139 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1140 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1141 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1142 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1143 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1144 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1145 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1147 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1148 * @test t( "First Element", "p:first", ["firstp"] );
1149 * @test t( "Last Element", "p:last", ["first"] );
1150 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1151 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1152 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1153 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1154 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1155 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1156 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1157 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1162 find: function( t, context ) {
1163 // Make sure that the context is a DOM Element
1164 if ( context && context.nodeType == undefined )
1167 // Set the correct context (if none is provided)
1168 context = context || jQuery.context || document;
1170 if ( t.constructor != String ) return [t];
1172 if ( !t.indexOf("//") ) {
1173 context = context.documentElement;
1174 t = t.substr(2,t.length);
1175 } else if ( !t.indexOf("/") ) {
1176 context = context.documentElement;
1177 t = t.substr(1,t.length);
1178 // FIX Assume the root element is right :(
1179 if ( t.indexOf("/") >= 1 )
1180 t = t.substr(t.indexOf("/"),t.length);
1183 var ret = [context];
1187 while ( t.length > 0 && last != t ) {
1191 t = jQuery.trim(t).replace( /^\/\//i, "" );
1193 var foundToken = false;
1195 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1196 var re = new RegExp("^(" + jQuery.token[i] + ")");
1200 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1201 t = jQuery.trim( t.replace( re, "" ) );
1206 if ( !foundToken ) {
1207 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1208 if ( ret[0] == context ) ret.shift();
1209 done = jQuery.merge( done, ret );
1210 r = ret = [context];
1211 t = " " + t.substr(1,t.length);
1213 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1214 var m = re2.exec(t);
1216 if ( m[1] == "#" ) {
1217 // Ummm, should make this work in all XML docs
1218 var oid = document.getElementById(m[2]);
1219 r = ret = oid ? [oid] : [];
1220 t = t.replace( re2, "" );
1222 if ( !m[2] || m[1] == "." ) m[2] = "*";
1224 for ( var i = 0; i < ret.length; i++ )
1225 r = jQuery.merge( r,
1227 jQuery.getAll(ret[i]) :
1228 ret[i].getElementsByTagName(m[2])
1235 var val = jQuery.filter(t,r);
1237 t = jQuery.trim(val.t);
1241 if ( ret && ret[0] == context ) ret.shift();
1242 done = jQuery.merge( done, ret );
1247 getAll: function(o,r) {
1249 var s = o.childNodes;
1250 for ( var i = 0; i < s.length; i++ )
1251 if ( s[i].nodeType == 1 ) {
1253 jQuery.getAll( s[i], r );
1258 attr: function(o,a,v){
1259 if ( a && a.constructor == String ) {
1262 "class": "className",
1266 a = (fix[a] && fix[a].replace && fix[a] || a)
1267 .replace(/-([a-z])/ig,function(z,b){
1268 return b.toUpperCase();
1271 if ( v != undefined ) {
1273 if ( o.setAttribute && a != "disabled" )
1274 o.setAttribute(a,v);
1277 return o[a] || o.getAttribute && o.getAttribute(a) || "";
1282 // The regular expressions that power the parsing engine
1284 // Match: [@value='test'], [@foo]
1285 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1287 // Match: [div], [div p]
1290 // Match: :contains('foo')
1291 [ "(:)S\\(Q\\)", 0 ],
1293 // Match: :even, :last-chlid
1297 filter: function(t,r,not) {
1298 // Figure out if we're doing regular, or inverse, filtering
1299 var g = not !== false ? jQuery.grep :
1300 function(a,f) {return jQuery.grep(a,f,true);};
1302 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1304 var p = jQuery.parse;
1306 for ( var i = 0; i < p.length; i++ ) {
1307 var re = new RegExp( "^" + p[i][0]
1309 // Look for a string-like sequence
1310 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1312 // Look for something (optionally) enclosed with quotes
1313 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1315 var m = re.exec( t );
1318 // Re-organize the match
1320 m = ["", m[1], m[3], m[2], m[4]];
1322 // Remove what we just matched
1323 t = t.replace( re, "" );
1329 // :not() is a special case that can be optomized by
1330 // keeping it out of the expression list
1331 if ( m[1] == ":" && m[2] == "not" )
1332 r = jQuery.filter(m[3],r,false).r;
1334 // Otherwise, find the expression to execute
1336 var f = jQuery.expr[m[1]];
1337 if ( f.constructor != String )
1338 f = jQuery.expr[m[1]][m[2]];
1340 // Build a custom macro to enclose it
1341 eval("f = function(a,i){" +
1342 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1343 "return " + f + "}");
1345 // Execute it against the current filter
1350 // Return an array of filtered elements (r)
1351 // and the modified expression string (t)
1352 return { r: r, t: t };
1356 * Remove the whitespace from the beginning and end of a string.
1361 * @param String str The string to trim.
1364 return t.replace(/^\s+|\s+$/g, "");
1368 * All ancestors of a given element.
1371 * @name jQuery.parents
1372 * @type Array<Element>
1373 * @param Element elem The element to find the ancestors of.
1375 parents: function( elem ){
1377 var cur = elem.parentNode;
1378 while ( cur && cur != document ) {
1379 matched.push( cur );
1380 cur = cur.parentNode;
1386 * All elements on a specified axis.
1389 * @name jQuery.sibling
1391 * @param Element elem The element to find all the siblings of (including itself).
1393 sibling: function(elem, pos, not) {
1396 var siblings = elem.parentNode.childNodes;
1397 for ( var i = 0; i < siblings.length; i++ ) {
1398 if ( not === true && siblings[i] == elem ) continue;
1400 if ( siblings[i].nodeType == 1 )
1401 elems.push( siblings[i] );
1402 if ( siblings[i] == elem )
1403 elems.n = elems.length - 1;
1406 return jQuery.extend( elems, {
1407 last: elems.n == elems.length - 1,
1408 cur: n == "even" && elems.n % 2 == 0 || n == "odd" && elems.n % 2 || elems[pos] == a,
1409 prev: elems[elems.n - 1],
1410 next: elems[elems.n + 1]
1415 * Merge two arrays together, removing all duplicates.
1418 * @name jQuery.merge
1420 * @param Array a The first array to merge.
1421 * @param Array b The second array to merge.
1423 merge: function(first, second) {
1426 // Move b over to the new array (this helps to avoid
1427 // StaticNodeList instances)
1428 for ( var k = 0; k < first.length; k++ )
1429 result[k] = second[k];
1431 // Now check for duplicates between a and b and only
1432 // add the unique items
1433 for ( var i = 0; i < second.length; i++ ) {
1434 var noCollision = true;
1436 // The collision-checking process
1437 for ( var j = 0; j < first.length; j++ )
1438 if ( second[i] == first[j] )
1439 noCollision = false;
1441 // If the item is unique, add it
1443 result.push( second[i] );
1450 * Remove items that aren't matched in an array. The function passed
1451 * in to this method will be passed two arguments: 'a' (which is the
1452 * array item) and 'i' (which is the index of the item in the array).
1457 * @param Array array The Array to find items in.
1458 * @param Function fn The function to process each item against.
1459 * @param Boolean inv Invert the selection - select the opposite of the function.
1461 grep: function(elems, fn, inv) {
1462 // If a string is passed in for the function, make a function
1463 // for it (a handy shortcut)
1464 if ( fn.constructor == String )
1465 fn = new Function("a","i","return " + fn);
1469 // Go through the array, only saving the items
1470 // that pass the validator function
1471 for ( var i = 0; i < elems.length; i++ )
1472 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1473 result.push( elems[i] );
1479 * Translate all items in array to another array of items. The translation function
1480 * that is provided to this method is passed one argument: 'a' (the item to be
1481 * translated). If an array is returned, that array is mapped out and merged into
1482 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1483 * from the array. Both of these changes imply that the size of the array may not
1484 * be the same size upon completion, as it was when it started.
1489 * @param Array array The Array to translate.
1490 * @param Function fn The function to process each item against.
1492 map: function(elems, fn) {
1493 // If a string is passed in for the function, make a function
1494 // for it (a handy shortcut)
1495 if ( fn.constructor == String )
1496 fn = new Function("a","return " + fn);
1500 // Go through the array, translating each of the items to their
1501 // new value (or values).
1502 for ( var i = 0; i < elems.length; i++ ) {
1503 var val = fn(elems[i],i);
1505 if ( val !== null && val != undefined ) {
1506 if ( val.constructor != Array ) val = [val];
1507 result = jQuery.merge( result, val );
1515 * A number of helper functions used for managing events.
1516 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1520 // Bind an event to an element
1521 // Original by Dean Edwards
1522 add: function(element, type, handler) {
1523 // For whatever reason, IE has trouble passing the window object
1524 // around, causing it to be cloned in the process
1525 if ( jQuery.browser.msie && element.setInterval != undefined )
1528 // Make sure that the function being executed has a unique ID
1529 if ( !handler.guid )
1530 handler.guid = this.guid++;
1532 // Init the element's event structure
1533 if (!element.events)
1534 element.events = {};
1536 // Get the current list of functions bound to this event
1537 var handlers = element.events[type];
1539 // If it hasn't been initialized yet
1541 // Init the event handler queue
1542 handlers = element.events[type] = {};
1544 // Remember an existing handler, if it's already there
1545 if (element["on" + type])
1546 handlers[0] = element["on" + type];
1549 // Add the function to the element's handler list
1550 handlers[handler.guid] = handler;
1552 // And bind the global event handler to the element
1553 element["on" + type] = this.handle;
1555 // Remember the function in a global list (for triggering)
1556 if (!this.global[type])
1557 this.global[type] = [];
1558 this.global[type].push( element );
1564 // Detach an event or set of events from an element
1565 remove: function(element, type, handler) {
1567 if (type && element.events[type])
1569 delete element.events[type][handler.guid];
1571 for ( var i in element.events[type] )
1572 delete element.events[type][i];
1574 for ( var j in element.events )
1575 this.remove( element, j );
1578 trigger: function(type,data,element) {
1579 // Touch up the incoming data
1582 // Handle a global trigger
1584 var g = this.global[type];
1586 for ( var i = 0; i < g.length; i++ )
1587 this.trigger( type, data, g[i] );
1589 // Handle triggering a single element
1590 } else if ( element["on" + type] ) {
1591 // Pass along a fake event
1592 data.unshift( this.fix({ type: type, target: element }) );
1594 // Trigger the event
1595 element["on" + type].apply( element, data );
1599 handle: function(event) {
1600 if ( typeof jQuery == "undefined" ) return;
1602 event = event || jQuery.event.fix( window.event );
1604 // If no correct event was found, fail
1605 if ( !event ) return;
1607 var returnValue = true;
1609 var c = this.events[event.type];
1611 for ( var j in c ) {
1612 if ( c[j].apply( this, [event] ) === false ) {
1613 event.preventDefault();
1614 event.stopPropagation();
1615 returnValue = false;
1622 fix: function(event) {
1624 event.preventDefault = function() {
1625 this.returnValue = false;
1628 event.stopPropagation = function() {
1629 this.cancelBubble = true;
1640 var b = navigator.userAgent.toLowerCase();
1642 // Figure out what browser is being used
1644 safari: /webkit/.test(b),
1645 opera: /opera/.test(b),
1646 msie: /msie/.test(b) && !/opera/.test(b),
1647 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1650 // Check to see if the W3C box model is being used
1651 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1657 * Append all of the matched elements to another, specified, set of elements.
1658 * This operation is, essentially, the reverse of doing a regular
1659 * $(A).append(B), in that instead of appending B to A, you're appending
1662 * @example $("p").appendTo("#foo");
1663 * @before <p>I would like to say: </p><div id="foo"></div>
1664 * @result <div id="foo"><p>I would like to say: </p></div>
1668 * @param String expr A jQuery expression of elements to match.
1669 * @cat DOM/Manipulation
1674 * Prepend all of the matched elements to another, specified, set of elements.
1675 * This operation is, essentially, the reverse of doing a regular
1676 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1679 * @example $("p").prependTo("#foo");
1680 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1681 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1685 * @param String expr A jQuery expression of elements to match.
1686 * @cat DOM/Manipulation
1688 prependTo: "prepend",
1691 * Insert all of the matched elements before another, specified, set of elements.
1692 * This operation is, essentially, the reverse of doing a regular
1693 * $(A).before(B), in that instead of inserting B before A, you're inserting
1696 * @example $("p").insertBefore("#foo");
1697 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1698 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1700 * @name insertBefore
1702 * @param String expr A jQuery expression of elements to match.
1703 * @cat DOM/Manipulation
1705 insertBefore: "before",
1708 * Insert all of the matched elements after another, specified, set of elements.
1709 * This operation is, essentially, the reverse of doing a regular
1710 * $(A).after(B), in that instead of inserting B after A, you're inserting
1713 * @example $("p").insertAfter("#foo");
1714 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1715 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1719 * @param String expr A jQuery expression of elements to match.
1720 * @cat DOM/Manipulation
1722 insertAfter: "after"
1726 * Get the current CSS width of the first matched element.
1728 * @example $("p").width();
1729 * @before <p>This is just a test.</p>
1738 * Set the CSS width of every matched element. Be sure to include
1739 * the "px" (or other unit of measurement) after the number that you
1740 * specify, otherwise you might get strange results.
1742 * @example $("p").width("20px");
1743 * @before <p>This is just a test.</p>
1744 * @result <p style="width:20px;">This is just a test.</p>
1748 * @param String val Set the CSS property to the specified value.
1753 * Get the current CSS height of the first matched element.
1755 * @example $("p").height();
1756 * @before <p>This is just a test.</p>
1765 * Set the CSS height of every matched element. Be sure to include
1766 * the "px" (or other unit of measurement) after the number that you
1767 * specify, otherwise you might get strange results.
1769 * @example $("p").height("20px");
1770 * @before <p>This is just a test.</p>
1771 * @result <p style="height:20px;">This is just a test.</p>
1775 * @param String val Set the CSS property to the specified value.
1780 * Get the current CSS top of the first matched element.
1782 * @example $("p").top();
1783 * @before <p>This is just a test.</p>
1792 * Set the CSS top of every matched element. Be sure to include
1793 * the "px" (or other unit of measurement) after the number that you
1794 * specify, otherwise you might get strange results.
1796 * @example $("p").top("20px");
1797 * @before <p>This is just a test.</p>
1798 * @result <p style="top:20px;">This is just a test.</p>
1802 * @param String val Set the CSS property to the specified value.
1807 * Get the current CSS left of the first matched element.
1809 * @example $("p").left();
1810 * @before <p>This is just a test.</p>
1819 * Set the CSS left of every matched element. Be sure to include
1820 * the "px" (or other unit of measurement) after the number that you
1821 * specify, otherwise you might get strange results.
1823 * @example $("p").left("20px");
1824 * @before <p>This is just a test.</p>
1825 * @result <p style="left:20px;">This is just a test.</p>
1829 * @param String val Set the CSS property to the specified value.
1834 * Get the current CSS position of the first matched element.
1836 * @example $("p").position();
1837 * @before <p>This is just a test.</p>
1846 * Set the CSS position of every matched element.
1848 * @example $("p").position("relative");
1849 * @before <p>This is just a test.</p>
1850 * @result <p style="position:relative;">This is just a test.</p>
1854 * @param String val Set the CSS property to the specified value.
1859 * Get the current CSS float of the first matched element.
1861 * @example $("p").float();
1862 * @before <p>This is just a test.</p>
1871 * Set the CSS float of every matched element.
1873 * @example $("p").float("left");
1874 * @before <p>This is just a test.</p>
1875 * @result <p style="float:left;">This is just a test.</p>
1879 * @param String val Set the CSS property to the specified value.
1884 * Get the current CSS overflow of the first matched element.
1886 * @example $("p").overflow();
1887 * @before <p>This is just a test.</p>
1896 * Set the CSS overflow of every matched element.
1898 * @example $("p").overflow("auto");
1899 * @before <p>This is just a test.</p>
1900 * @result <p style="overflow:auto;">This is just a test.</p>
1904 * @param String val Set the CSS property to the specified value.
1909 * Get the current CSS color of the first matched element.
1911 * @example $("p").color();
1912 * @before <p>This is just a test.</p>
1921 * Set the CSS color of every matched element.
1923 * @example $("p").color("blue");
1924 * @before <p>This is just a test.</p>
1925 * @result <p style="color:blue;">This is just a test.</p>
1929 * @param String val Set the CSS property to the specified value.
1934 * Get the current CSS background of the first matched element.
1936 * @example $("p").background();
1937 * @before <p>This is just a test.</p>
1946 * Set the CSS background of every matched element.
1948 * @example $("p").background("blue");
1949 * @before <p>This is just a test.</p>
1950 * @result <p style="background:blue;">This is just a test.</p>
1954 * @param String val Set the CSS property to the specified value.
1958 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1960 filter: [ "eq", "lt", "gt", "contains" ],
1964 * Get the current value of the first matched element.
1966 * @example $("input").val();
1967 * @before <input type="text" value="some text"/>
1968 * @result "some text"
1972 * @cat DOM/Attributes
1976 * Set the value of every matched element.
1978 * @example $("input").value("test");
1979 * @before <input type="text" value="some text"/>
1980 * @result <input type="text" value="test"/>
1984 * @param String val Set the property to the specified value.
1985 * @cat DOM/Attributes
1990 * Get the html contents of the first matched element.
1992 * @example $("div").html();
1993 * @before <div><input/></div>
1998 * @cat DOM/Attributes
2002 * Set the html contents of every matched element.
2004 * @example $("div").html("<b>new stuff</b>");
2005 * @before <div><input/></div>
2006 * @result <div><b>new stuff</b></div>
2008 * @test var div = $("div");
2009 * div.html("<b>test</b>");
2011 * for ( var i = 0; i < div.size(); i++ ) {
2012 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2014 * ok( pass, "Set HTML" );
2018 * @param String val Set the html contents to the specified value.
2019 * @cat DOM/Attributes
2024 * Get the current id of the first matched element.
2026 * @example $("input").id();
2027 * @before <input type="text" id="test" value="some text"/>
2032 * @cat DOM/Attributes
2036 * Set the id of every matched element.
2038 * @example $("input").id("newid");
2039 * @before <input type="text" id="test" value="some text"/>
2040 * @result <input type="text" id="newid" value="some text"/>
2044 * @param String val Set the property to the specified value.
2045 * @cat DOM/Attributes
2050 * Get the current title of the first matched element.
2052 * @example $("img").title();
2053 * @before <img src="test.jpg" title="my image"/>
2054 * @result "my image"
2058 * @cat DOM/Attributes
2062 * Set the title of every matched element.
2064 * @example $("img").title("new title");
2065 * @before <img src="test.jpg" title="my image"/>
2066 * @result <img src="test.jpg" title="new image"/>
2070 * @param String val Set the property to the specified value.
2071 * @cat DOM/Attributes
2076 * Get the current name of the first matched element.
2078 * @example $("input").name();
2079 * @before <input type="text" name="username"/>
2080 * @result "username"
2084 * @cat DOM/Attributes
2088 * Set the name of every matched element.
2090 * @example $("input").name("user");
2091 * @before <input type="text" name="username"/>
2092 * @result <input type="text" name="user"/>
2096 * @param String val Set the property to the specified value.
2097 * @cat DOM/Attributes
2102 * Get the current href of the first matched element.
2104 * @example $("a").href();
2105 * @before <a href="test.html">my link</a>
2106 * @result "test.html"
2110 * @cat DOM/Attributes
2114 * Set the href of every matched element.
2116 * @example $("a").href("test2.html");
2117 * @before <a href="test.html">my link</a>
2118 * @result <a href="test2.html">my link</a>
2122 * @param String val Set the property to the specified value.
2123 * @cat DOM/Attributes
2128 * Get the current src of the first matched element.
2130 * @example $("img").src();
2131 * @before <img src="test.jpg" title="my image"/>
2132 * @result "test.jpg"
2136 * @cat DOM/Attributes
2140 * Set the src of every matched element.
2142 * @example $("img").src("test2.jpg");
2143 * @before <img src="test.jpg" title="my image"/>
2144 * @result <img src="test2.jpg" title="my image"/>
2148 * @param String val Set the property to the specified value.
2149 * @cat DOM/Attributes
2154 * Get the current rel of the first matched element.
2156 * @example $("a").rel();
2157 * @before <a href="test.html" rel="nofollow">my link</a>
2158 * @result "nofollow"
2162 * @cat DOM/Attributes
2166 * Set the rel of every matched element.
2168 * @example $("a").rel("nofollow");
2169 * @before <a href="test.html">my link</a>
2170 * @result <a href="test.html" rel="nofollow">my link</a>
2174 * @param String val Set the property to the specified value.
2175 * @cat DOM/Attributes
2182 * Get a set of elements containing the unique parents of the matched
2185 * @example $("p").parent()
2186 * @before <div><p>Hello</p><p>Hello</p></div>
2187 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2191 * @cat DOM/Traversing
2195 * Get a set of elements containing the unique parents of the matched
2196 * set of elements, and filtered by an expression.
2198 * @example $("p").parent(".selected")
2199 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2200 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2204 * @param String expr An expression to filter the parents with
2205 * @cat DOM/Traversing
2207 parent: "a.parentNode",
2210 * Get a set of elements containing the unique ancestors of the matched
2213 * @example $("span").ancestors()
2214 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2215 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2219 * @cat DOM/Traversing
2223 * Get a set of elements containing the unique ancestors of the matched
2224 * set of elements, and filtered by an expression.
2226 * @example $("span").ancestors("p")
2227 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2228 * @result [ <p><span>Hello</span></p> ]
2232 * @param String expr An expression to filter the ancestors with
2233 * @cat DOM/Traversing
2235 ancestors: jQuery.parents,
2238 * Get a set of elements containing the unique ancestors of the matched
2241 * @example $("span").ancestors()
2242 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2243 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2247 * @cat DOM/Traversing
2251 * Get a set of elements containing the unique ancestors of the matched
2252 * set of elements, and filtered by an expression.
2254 * @example $("span").ancestors("p")
2255 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2256 * @result [ <p><span>Hello</span></p> ]
2260 * @param String expr An expression to filter the ancestors with
2261 * @cat DOM/Traversing
2263 parents: jQuery.parents,
2266 * Get a set of elements containing the unique next siblings of each of the
2267 * matched set of elements.
2269 * It only returns the very next sibling, not all next siblings.
2271 * @example $("p").next()
2272 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2273 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2277 * @cat DOM/Traversing
2281 * Get a set of elements containing the unique next siblings of each of the
2282 * matched set of elements, and filtered by an expression.
2284 * It only returns the very next sibling, not all next siblings.
2286 * @example $("p").next(".selected")
2287 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2288 * @result [ <p class="selected">Hello Again</p> ]
2292 * @param String expr An expression to filter the next Elements with
2293 * @cat DOM/Traversing
2295 next: "jQuery.sibling(a).next",
2298 * Get a set of elements containing the unique previous siblings of each of the
2299 * matched set of elements.
2301 * It only returns the immediately previous sibling, not all previous siblings.
2303 * @example $("p").previous()
2304 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2305 * @result [ <div><span>Hello Again</span></div> ]
2309 * @cat DOM/Traversing
2313 * Get a set of elements containing the unique previous siblings of each of the
2314 * matched set of elements, and filtered by an expression.
2316 * It only returns the immediately previous sibling, not all previous siblings.
2318 * @example $("p").previous(".selected")
2319 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2320 * @result [ <div><span>Hello</span></div> ]
2324 * @param String expr An expression to filter the previous Elements with
2325 * @cat DOM/Traversing
2327 prev: "jQuery.sibling(a).prev",
2330 * Get a set of elements containing all of the unique siblings of each of the
2331 * matched set of elements.
2333 * @example $("div").siblings()
2334 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2335 * @result [ <p>Hello</p>, <p>And Again</p> ]
2339 * @cat DOM/Traversing
2343 * Get a set of elements containing all of the unique siblings of each of the
2344 * matched set of elements, and filtered by an expression.
2346 * @example $("div").siblings(".selected")
2347 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2348 * @result [ <p class="selected">Hello Again</p> ]
2352 * @param String expr An expression to filter the sibling Elements with
2353 * @cat DOM/Traversing
2355 siblings: jQuery.sibling,
2359 * Get a set of elements containing all of the unique children of each of the
2360 * matched set of elements.
2362 * @example $("div").children()
2363 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2364 * @result [ <span>Hello Again</span> ]
2368 * @cat DOM/Traversing
2372 * Get a set of elements containing all of the unique children of each of the
2373 * matched set of elements, and filtered by an expression.
2375 * @example $("div").children(".selected")
2376 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2377 * @result [ <p class="selected">Hello Again</p> ]
2381 * @param String expr An expression to filter the child Elements with
2382 * @cat DOM/Traversing
2384 children: "a.childNodes"
2389 removeAttr: function( key ) {
2390 this.removeAttribute( key );
2394 * Displays each of the set of matched elements if they are hidden.
2396 * @example $("p").show()
2397 * @before <p style="display: none">Hello</p>
2398 * @result [ <p style="display: block">Hello</p> ]
2400 * @test var pass = true, div = $("div");
2401 * div.show().each(function(){
2402 * if ( this.style.display == "none" ) pass = false;
2404 * ok( pass, "Show" );
2411 this.style.display = this.oldblock ? this.oldblock : "";
2412 if ( jQuery.css(this,"display") == "none" )
2413 this.style.display = "block";
2417 * Hides each of the set of matched elements if they are shown.
2419 * @example $("p").hide()
2420 * @before <p>Hello</p>
2421 * @result [ <p style="display: none">Hello</p> ]
2423 * var pass = true, div = $("div");
2424 * div.hide().each(function(){
2425 * if ( this.style.display != "none" ) pass = false;
2427 * ok( pass, "Hide" );
2434 this.oldblock = this.oldblock || jQuery.css(this,"display");
2435 if ( this.oldblock == "none" )
2436 this.oldblock = "block";
2437 this.style.display = "none";
2441 * Toggles each of the set of matched elements. If they are shown,
2442 * toggle makes them hidden. If they are hidden, toggle
2445 * @example $("p").toggle()
2446 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2447 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2453 _toggle: function(){
2454 var d = jQuery.css(this,"display");
2455 $(this)[ !d || d == "none" ? "show" : "hide" ]();
2459 * Adds the specified class to each of the set of matched elements.
2461 * @example $("p").addClass("selected")
2462 * @before <p>Hello</p>
2463 * @result [ <p class="selected">Hello</p> ]
2465 * @test var div = $("div");
2466 * div.addClass("test");
2468 * for ( var i = 0; i < div.size(); i++ ) {
2469 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2471 * ok( pass, "Add Class" );
2475 * @param String class A CSS class to add to the elements
2478 addClass: function(c){
2479 jQuery.className.add(this,c);
2483 * Removes the specified class from the set of matched elements.
2485 * @example $("p").removeClass("selected")
2486 * @before <p class="selected">Hello</p>
2487 * @result [ <p>Hello</p> ]
2489 * @test var div = $("div").addClass("test");
2490 * div.removeClass("test");
2492 * for ( var i = 0; i < div.size(); i++ ) {
2493 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2495 * ok( pass, "Remove Class" );
2499 * @param String class A CSS class to remove from the elements
2502 removeClass: function(c){
2503 jQuery.className.remove(this,c);
2507 * Adds the specified class if it is present, removes it if it is
2510 * @example $("p").toggleClass("selected")
2511 * @before <p>Hello</p><p class="selected">Hello Again</p>
2512 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2516 * @param String class A CSS class with which to toggle the elements
2519 toggleClass: function( c ){
2520 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2524 * Removes all matched elements from the DOM. This does NOT remove them from the
2525 * jQuery object, allowing you to use the matched elements further.
2527 * @example $("p").remove();
2528 * @before <p>Hello</p> how are <p>you?</p>
2533 * @cat DOM/Manipulation
2537 * Removes only elements (out of the list of matched elements) that match
2538 * the specified jQuery expression. This does NOT remove them from the
2539 * jQuery object, allowing you to use the matched elements further.
2541 * @example $("p").remove(".hello");
2542 * @before <p class="hello">Hello</p> how are <p>you?</p>
2543 * @result how are <p>you?</p>
2547 * @param String expr A jQuery expression to filter elements by.
2548 * @cat DOM/Manipulation
2550 remove: function(a){
2551 if ( !a || jQuery.filter( [this], a ).r )
2552 this.parentNode.removeChild( this );
2556 * Removes all child nodes from the set of matched elements.
2558 * @example $("p").empty()
2559 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2560 * @result [ <p></p> ]
2564 * @cat DOM/Manipulation
2567 while ( this.firstChild )
2568 this.removeChild( this.firstChild );
2572 * Binds a particular event (like click) to a each of a set of match elements.
2574 * @example $("p").bind( "click", function() { alert("Hello"); } )
2575 * @before <p>Hello</p>
2576 * @result [ <p>Hello</p> ]
2578 * Cancel a default action and prevent it from bubbling by returning false
2579 * from your function.
2581 * @example $("form").bind( "submit", function() { return false; } )
2583 * Cancel a default action by using the preventDefault method.
2585 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2587 * Stop an event from bubbling by using the stopPropogation method.
2589 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2593 * @param String type An event type
2594 * @param Function fn A function to bind to the event on each of the set of matched elements
2597 bind: function( type, fn ) {
2598 if ( fn.constructor == String )
2599 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2600 jQuery.event.add( this, type, fn );
2604 * The opposite of bind, removes a bound event from each of the matched
2605 * elements. You must pass the identical function that was used in the original
2608 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2609 * @before <p onclick="alert('Hello');">Hello</p>
2610 * @result [ <p>Hello</p> ]
2614 * @param String type An event type
2615 * @param Function fn A function to unbind from the event on each of the set of matched elements
2620 * Removes all bound events of a particular type from each of the matched
2623 * @example $("p").unbind( "click" )
2624 * @before <p onclick="alert('Hello');">Hello</p>
2625 * @result [ <p>Hello</p> ]
2629 * @param String type An event type
2634 * Removes all bound events from each of the matched elements.
2636 * @example $("p").unbind()
2637 * @before <p onclick="alert('Hello');">Hello</p>
2638 * @result [ <p>Hello</p> ]
2644 unbind: function( type, fn ) {
2645 jQuery.event.remove( this, type, fn );
2649 * Trigger a type of event on every matched element.
2651 * @example $("p").trigger("click")
2652 * @before <p click="alert('hello')">Hello</p>
2653 * @result alert('hello')
2657 * @param String type An event type to trigger.
2660 trigger: function( type, data ) {
2661 jQuery.event.trigger( type, data, this );