2 * jQuery - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
18 * @test ok( Array.prototype.push, "Array.push()" );
19 * @test ok( Function.prototype.apply, "Function.apply()" );
20 * @test ok( document.getElementById, "getElementById" );
21 * @test ok( document.getElementsByTagName, "getElementsByTagName" );
22 * @test ok( RegExp, "RegExp" );
23 * @test ok( jQuery, "jQuery" );
24 * @test ok( $, "$()" );
30 function jQuery(a,c) {
32 // Shortcut for document ready (because $(document).each() is silly)
33 if ( a && a.constructor == Function && jQuery.fn.ready )
34 return jQuery(document).ready(a);
36 // Make sure that a selection was provided
37 a = a || jQuery.context || document;
39 // Watch for when a jQuery object is passed as the selector
41 return $( jQuery.merge( a, [] ) );
43 // Watch for when a jQuery object is passed at the context
45 return $( c ).find(a);
47 // If the context is global, return a new object
49 return new jQuery(a,c);
51 // Handle HTML strings
52 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
53 if ( m ) a = jQuery.clean( [ m[1] ] );
55 // Watch for when an array is passed in
56 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
57 // Assume that it is an array of DOM Elements
58 jQuery.merge( a, [] ) :
60 // Find the matching elements and save them for later
61 jQuery.find( a, c ) );
63 // See if an extra function was provided
64 var fn = arguments[ arguments.length - 1 ];
66 // If so, execute it in context
67 if ( fn && fn.constructor == Function )
71 // Map over the $ in case of overwrite
75 // Map the jQuery namespace to the '$' one
78 jQuery.fn = jQuery.prototype = {
80 * The current SVN version of jQuery.
91 * The number of elements currently matched.
93 * @example $("img").length;
94 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
97 * @test cmpOK( $("div").length, "==", 2, "Get Number of Elements Found" );
106 * The number of elements currently matched.
108 * @example $("img").size();
109 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
112 * @test cmpOK( $("div").size(), "==", 2, "Get Number of Elements Found" );
123 * Access all matched elements. This serves as a backwards-compatible
124 * way of accessing all matched elements (other than the jQuery object
125 * itself, which is, in fact, an array of elements).
127 * @example $("img").get();
128 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
129 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
131 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
134 * @type Array<Element>
139 * Access a single matched element. num is used to access the
140 * Nth element matched.
142 * @example $("img").get(1);
143 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
144 * @result [ <img src="test1.jpg"/> ]
146 * @test cmpOK( $("div").get(0), "==", document.getElementById("main"), "Get A Single Element" );
150 * @param Number num Access the element in the Nth position.
155 * Set the jQuery object to an array of elements.
157 * @example $("img").get([ document.body ]);
158 * @result $("img").get() == [ document.body ]
163 * @param Elements elems An array of elements
166 get: function( num ) {
167 // Watch for when an array (of elements) is passed in
168 if ( num && num.constructor == Array ) {
170 // Use a tricky hack to make the jQuery object
171 // look and feel like an array
173 [].push.apply( this, num );
177 return num == undefined ?
179 // Return a 'clean' array
180 jQuery.map( this, function(a){ return a } ) :
182 // Return just the object
187 * Execute a function within the context of every matched element.
188 * This means that every time the passed-in function is executed
189 * (which is once for every element matched) the 'this' keyword
190 * points to the specific element.
192 * Additionally, the function, when executed, is passed a single
193 * argument representing the position of the element in the matched
196 * @example $("img").each(function(){ this.src = "test.jpg"; });
197 * @before <img/> <img/>
198 * @result <img src="test.jpg"/> <img src="test.jpg"/>
200 * @test var div = $("div");
201 * div.each(function(){this.foo = 'zoo';});
203 * for ( var i = 0; i < div.size(); i++ ) {
204 * if ( div.get(i).foo != "zoo" ) pass = false;
206 * ok( pass, "Execute a function, Relative" );
210 * @param Function fn A function to execute
213 each: function( fn, args ) {
214 return jQuery.each( this, fn, args );
217 index: function( obj ) {
219 this.each(function(i){
220 if ( this == obj ) pos = i;
226 * Access a property on the first matched element.
227 * This method makes it easy to retreive a property value
228 * from the first matched element.
230 * @example $("img").attr("src");
231 * @before <img src="test.jpg"/>
236 * @param String name The name of the property to access.
241 * Set a hash of key/value object properties to all matched elements.
242 * This serves as the best way to set a large number of properties
243 * on all matched elements.
245 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
247 * @result <img src="test.jpg" alt="Test Image"/>
249 * @test var pass = true;
250 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
251 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
253 * ok( pass, "Set Multiple Attributes" );
257 * @param Hash prop A set of key/value pairs to set as object properties.
262 * Set a single property to a value, on all matched elements.
264 * @example $("img").attr("src","test.jpg");
266 * @result <img src="test.jpg"/>
268 * @test var div = $("div");
269 * div.attr("foo", "bar");
271 * for ( var i = 0; i < div.size(); i++ ) {
272 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
274 * ok( pass, "Set Attribute" );
278 * @param String key The name of the property to set.
279 * @param Object value The value to set the property to.
282 attr: function( key, value, type ) {
283 // Check to see if we're setting style values
284 return key.constructor != String || value != undefined ?
285 this.each(function(){
286 // See if we're setting a hash of styles
287 if ( value == undefined )
288 // Set all the styles
289 for ( var prop in key )
291 type ? this.style : this,
295 // See if we're setting a single key/value style
298 type ? this.style : this,
303 // Look for the case where we're accessing a style value
304 jQuery[ type || "attr" ]( this[0], key );
308 * Access a style property on the first matched element.
309 * This method makes it easy to retreive a style property value
310 * from the first matched element.
312 * @example $("p").css("red");
313 * @before <p style="color:red;">Test Paragraph.</p>
318 * @param String name The name of the property to access.
323 * Set a hash of key/value style properties to all matched elements.
324 * This serves as the best way to set a large number of style properties
325 * on all matched elements.
327 * @example $("p").css({ color: "red", background: "blue" });
328 * @before <p>Test Paragraph.</p>
329 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
333 * @param Hash prop A set of key/value pairs to set as style properties.
338 * Set a single style property to a value, on all matched elements.
340 * @example $("p").css("color","red");
341 * @before <p>Test Paragraph.</p>
342 * @result <p style="color:red;">Test Paragraph.</p>
346 * @param String key The name of the property to set.
347 * @param Object value The value to set the property to.
350 css: function( key, value ) {
351 return this.attr( key, value, "curCSS" );
355 * Retreive the text contents of all matched elements. The result is
356 * a string that contains the combined text contents of all matched
357 * elements. This method works on both HTML and XML documents.
359 * @example $("p").text();
360 * @before <p>Test Paragraph.</p>
361 * @result Test Paragraph.
370 for ( var j = 0; j < e.length; j++ ) {
371 var r = e[j].childNodes;
372 for ( var i = 0; i < r.length; i++ )
373 t += r[i].nodeType != 1 ?
374 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
380 * Wrap all matched elements with a structure of other elements.
381 * This wrapping process is most useful for injecting additional
382 * stucture into a document, without ruining the original semantic
383 * qualities of a document.
385 * The way that is works is that it goes through the first element argument
386 * provided and finds the deepest element within the structure - it is that
387 * element that will en-wrap everything else.
389 * @example $("p").wrap("<div class='wrap'></div>");
390 * @before <p>Test Paragraph.</p>
391 * @result <div class='wrap'><p>Test Paragraph.</p></div>
395 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
396 * @any Element elem A DOM element that will be wrapped.
397 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
398 * @any Object obj Any object, converted to a string, then a text node.
399 * @cat DOM/Manipulation
402 // The elements to wrap the target around
403 var a = jQuery.clean(arguments);
405 // Wrap each of the matched elements individually
406 return this.each(function(){
407 // Clone the structure that we're using to wrap
408 var b = a[0].cloneNode(true);
410 // Insert it before the element to be wrapped
411 this.parentNode.insertBefore( b, this );
413 // Find he deepest point in the wrap structure
414 while ( b.firstChild )
417 // Move the matched element to within the wrap structure
418 b.appendChild( this );
423 * Append any number of elements to the inside of all matched elements.
424 * This operation is similar to doing an appendChild to all the
425 * specified elements, adding them into the document.
427 * @example $("p").append("<b>Hello</b>");
428 * @before <p>I would like to say: </p>
429 * @result <p>I would like to say: <b>Hello</b></p>
433 * @any String html A string of HTML, that will be created on the fly and appended to the target.
434 * @any Element elem A DOM element that will be appended.
435 * @any Array<Element> elems An array of elements, all of which will be appended.
436 * @any Object obj Any object, converted to a string, then a text node.
437 * @cat DOM/Manipulation
440 return this.domManip(arguments, true, 1, function(a){
441 this.appendChild( a );
446 * Prepend any number of elements to the inside of all matched elements.
447 * This operation is the best way to insert a set of elements inside, at the
448 * beginning, of all the matched element.
450 * @example $("p").prepend("<b>Hello</b>");
451 * @before <p>, how are you?</p>
452 * @result <p><b>Hello</b>, how are you?</p>
456 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
457 * @any Element elem A DOM element that will be prepended.
458 * @any Array<Element> elems An array of elements, all of which will be prepended.
459 * @any Object obj Any object, converted to a string, then a text node.
460 * @cat DOM/Manipulation
462 prepend: function() {
463 return this.domManip(arguments, true, -1, function(a){
464 this.insertBefore( a, this.firstChild );
469 * Insert any number of elements before each of the matched elements.
471 * @example $("p").before("<b>Hello</b>");
472 * @before <p>how are you?</p>
473 * @result <b>Hello</b><p>how are you?</p>
477 * @any String html A string of HTML, that will be created on the fly and inserted.
478 * @any Element elem A DOM element that will beinserted.
479 * @any Array<Element> elems An array of elements, all of which will be inserted.
480 * @any Object obj Any object, converted to a string, then a text node.
481 * @cat DOM/Manipulation
484 return this.domManip(arguments, false, 1, function(a){
485 this.parentNode.insertBefore( a, this );
490 * Insert any number of elements after each of the matched elements.
492 * @example $("p").after("<p>I'm doing fine.</p>");
493 * @before <p>How are you?</p>
494 * @result <p>How are you?</p><p>I'm doing fine.</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.nextSibling );
511 * End the most recent 'destructive' operation, reverting the list of matched elements
512 * back to its previous state. After an end operation, the list of matched elements will
513 * revert to the last state of matched elements.
515 * @example $("p").find("span").end();
516 * @before <p><span>Hello</span>, how are you?</p>
517 * @result $("p").find("span").end() == [ <p>...</p> ]
521 * @cat DOM/Traversing
524 return this.get( this.stack.pop() );
528 * Searches for all elements that match the specified expression.
529 * This method is the optimal way of finding additional descendant
530 * elements with which to process.
532 * All searching is done using a jQuery expression. The expression can be
533 * written using CSS 1-3 Selector syntax, or basic XPath.
535 * @example $("p").find("span");
536 * @before <p><span>Hello</span>, how are you?</p>
537 * @result $("p").find("span") == [ <span>Hello</span> ]
541 * @param String expr An expression to search with.
542 * @cat DOM/Traversing
545 return this.pushStack( jQuery.map( this, function(a){
546 return jQuery.find(t,a);
550 clone: function(deep) {
551 return this.pushStack( jQuery.map( this, function(a){
552 return a.cloneNode( deep != undefined ? deep : true );
557 * Removes all elements from the set of matched elements that do not
558 * match the specified expression. This method is used to narrow down
559 * the results of a search.
561 * All searching is done using a jQuery expression. The expression
562 * can be written using CSS 1-3 Selector syntax, or basic XPath.
564 * @example $("p").filter(".selected")
565 * @before <p class="selected">Hello</p><p>How are you?</p>
566 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
570 * @param String expr An expression to search with.
571 * @cat DOM/Traversing
575 * Removes all elements from the set of matched elements that do not
576 * match at least one of the expressions passed to the function. This
577 * method is used when you want to filter the set of matched elements
578 * through more than one expression.
580 * Elements will be retained in the jQuery object if they match at
581 * least one of the expressions passed.
583 * @example $("p").filter([".selected", ":first"])
584 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
585 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
589 * @param Array<String> exprs A set of expressions to evaluate against
590 * @cat DOM/Traversing
592 filter: function(t) {
593 return this.pushStack(
594 t.constructor == Array &&
595 jQuery.map(this,function(a){
596 for ( var i = 0; i < t.length; i++ )
597 if ( jQuery.filter(t[i],[a]).r.length )
601 t.constructor == Boolean &&
602 ( t ? this.get() : [] ) ||
604 t.constructor == Function &&
605 jQuery.grep( this, t ) ||
607 jQuery.filter(t,this).r, arguments );
611 * Removes the specified Element from the set of matched elements. This
612 * method is used to remove a single Element from a jQuery object.
614 * @example $("p").not( document.getElementById("selected") )
615 * @before <p>Hello</p><p id="selected">Hello Again</p>
616 * @result [ <p>Hello</p> ]
620 * @param Element el An element to remove from the set
621 * @cat DOM/Traversing
625 * Removes elements matching the specified expression from the set
626 * of matched elements. This method is used to remove one or more
627 * elements from a jQuery object.
629 * @example $("p").not("#selected")
630 * @before <p>Hello</p><p id="selected">Hello Again</p>
631 * @result [ <p>Hello</p> ]
635 * @param String expr An expression with which to remove matching elements
636 * @cat DOM/Traversing
639 return this.pushStack( t.constructor == String ?
640 jQuery.filter(t,this,false).r :
641 jQuery.grep(this,function(a){ return a != t; }), arguments );
645 * Adds the elements matched by the expression to the jQuery object. This
646 * can be used to concatenate the result sets of two expressions.
648 * @example $("p").add("span")
649 * @before <p>Hello</p><p><span>Hello Again</span></p>
650 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
654 * @param String expr An expression whose matched elements are added
655 * @cat DOM/Traversing
659 * Adds each of the Elements in the array to the set of matched elements.
660 * This is used to add a set of Elements to a jQuery object.
662 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
663 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
664 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
668 * @param Array<Element> els An array of Elements to add
673 * Adds a single Element to the set of matched elements. This is used to
674 * add a single Element to a jQuery object.
676 * @example $("p").add( document.getElementById("a") )
677 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
678 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
682 * @param Element el An Element to add
686 return this.pushStack( jQuery.merge( this, t.constructor == String ?
687 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
691 * A wrapper function for each() to be used by append and prepend.
692 * Handles cases where you're trying to modify the inner contents of
693 * a table, when you actually need to work with the tbody.
696 * @param {String} expr The expression with which to filter
701 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
710 * @param Boolean table
712 * @param Function fn The function doing the DOM manipulation.
715 domManip: function(args, table, dir, fn){
716 var clone = this.size() > 1;
717 var a = jQuery.clean(args);
719 return this.each(function(){
722 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
723 var tbody = this.getElementsByTagName("tbody");
725 if ( !tbody.length ) {
726 obj = document.createElement("tbody");
727 this.appendChild( obj );
732 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
733 i != ( dir < 0 ? dir : a.length ); i += dir ) {
734 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
748 pushStack: function(a,args) {
749 var fn = args && args[args.length-1];
751 if ( !fn || fn.constructor != Function ) {
752 if ( !this.stack ) this.stack = [];
753 this.stack.push( this.get() );
756 var old = this.get();
758 if ( fn.constructor == Function )
759 return this.each( fn );
778 * Extend one object with another, returning the original,
779 * modified, object. This is a great utility for simple inheritance.
781 * @name jQuery.extend
782 * @param Object obj The object to extend
783 * @param Object prop The object that will be merged into the first.
787 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
788 if ( !prop ) { prop = obj; obj = this; }
789 for ( var i in prop ) obj[i] = prop[i];
800 jQuery.initDone = true;
802 jQuery.each( jQuery.macros.axis, function(i,n){
803 jQuery.fn[ i ] = function(a) {
804 var ret = jQuery.map(this,n);
805 if ( a && a.constructor == String )
806 ret = jQuery.filter(a,ret).r;
807 return this.pushStack( ret, arguments );
811 jQuery.each( jQuery.macros.to, function(i,n){
812 jQuery.fn[ i ] = function(){
814 return this.each(function(){
815 for ( var j = 0; j < a.length; j++ )
821 jQuery.each( jQuery.macros.each, function(i,n){
822 jQuery.fn[ i ] = function() {
823 return this.each( n, arguments );
827 jQuery.each( jQuery.macros.filter, function(i,n){
828 jQuery.fn[ n ] = function(num,fn) {
829 return this.filter( ":" + n + "(" + num + ")", fn );
833 jQuery.each( jQuery.macros.attr, function(i,n){
835 jQuery.fn[ i ] = function(h) {
836 return h == undefined ?
837 this.length ? this[0][n] : null :
842 jQuery.each( jQuery.macros.css, function(i,n){
843 jQuery.fn[ n ] = function(h) {
844 return h == undefined ?
845 ( this.length ? jQuery.css( this[0], n ) : null ) :
853 * A generic iterator function, which can be used to seemlessly
854 * iterate over both objects and arrays.
857 * @param Object obj The object, or array, to iterate over.
858 * @param Object fn The function that will be executed on every object.
862 each: function( obj, fn, args ) {
863 if ( obj.length == undefined )
865 fn.apply( obj[i], args || [i, obj[i]] );
867 for ( var i = 0; i < obj.length; i++ )
868 fn.apply( obj[i], args || [i, obj[i]] );
874 if (jQuery.className.has(o,c)) return;
875 o.className += ( o.className ? " " : "" ) + c;
877 remove: function(o,c){
878 o.className = !c ? "" :
880 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
883 if ( e.className != undefined )
885 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
890 * Swap in/out style options.
893 swap: function(e,o,f) {
895 e.style["old"+i] = e.style[i];
900 e.style[i] = e.style["old"+i];
904 if ( p == "height" || p == "width" ) {
905 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
908 old["padding" + d[i]] = 0;
909 old["border" + d[i] + "Width"] = 0;
912 jQuery.swap( e, old, function() {
913 if (jQuery.css(e,"display") != "none") {
914 oHeight = e.offsetHeight;
915 oWidth = e.offsetWidth;
917 e = $(e.cloneNode(true)).css({
918 visibility: "hidden", position: "absolute", display: "block"
919 }).prependTo("body")[0];
921 oHeight = e.clientHeight;
922 oWidth = e.clientWidth;
924 e.parentNode.removeChild(e);
928 return p == "height" ? oHeight : oWidth;
929 } else if ( p == "opacity" && jQuery.browser.msie )
930 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
932 return jQuery.curCSS( e, p );
935 curCSS: function(elem, prop, force) {
938 if (!force && elem.style[prop]) {
940 ret = elem.style[prop];
942 } else if (elem.currentStyle) {
944 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
945 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
947 } else if (document.defaultView && document.defaultView.getComputedStyle) {
949 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
950 var cur = document.defaultView.getComputedStyle(elem, null);
953 ret = cur.getPropertyValue(prop);
954 else if ( prop == 'display' )
957 jQuery.swap(elem, { display: 'block' }, function() {
958 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
968 for ( var i = 0; i < a.length; i++ ) {
969 if ( a[i].constructor == String ) {
973 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
975 a[i] = "<table>" + a[i] + "</table>";
976 } else if ( !a[i].indexOf("<tr") ) {
978 a[i] = "<table>" + a[i] + "</table>";
979 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
981 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
984 var div = document.createElement("div");
985 div.innerHTML = a[i];
988 div = div.firstChild;
989 if ( table != "thead" ) div = div.firstChild;
990 if ( table == "td" ) div = div.firstChild;
993 for ( var j = 0; j < div.childNodes.length; j++ )
994 r.push( div.childNodes[j] );
995 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
996 for ( var k = 0; k < a[i].length; k++ )
998 else if ( a[i] !== null )
999 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1005 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1006 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1014 last: "i==r.length-1",
1019 "first-child": "jQuery.sibling(a,0).cur",
1020 "last-child": "jQuery.sibling(a,0).last",
1021 "only-child": "jQuery.sibling(a).length==1",
1024 parent: "a.childNodes.length",
1025 empty: "!a.childNodes.length",
1028 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1031 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1032 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1035 enabled: "!a.disabled",
1036 disabled: "a.disabled",
1037 checked: "a.checked",
1038 selected: "a.selected"
1040 ".": "jQuery.className.has(a,m[2])",
1044 "^=": "!z.indexOf(m[4])",
1045 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1046 "*=": "z.indexOf(m[4])>=0",
1049 "[": "jQuery.find(m[2],a).length"
1053 "\\.\\.|/\\.\\.", "a.parentNode",
1054 ">|/", "jQuery.sibling(a.firstChild)",
1055 "\\+", "jQuery.sibling(a).next",
1058 var s = jQuery.sibling(a);
1060 for ( var i = s.n; i < s.length; i++ )
1068 * @test t( "Element Selector", "div", ["main","foo"] );
1069 * @test t( "Element Selector", "body", ["body"] );
1070 * @test t( "Element Selector", "html", ["html"] );
1071 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1072 * @test t( "Parent Element", "div div", ["foo"] );
1074 * @test t( "ID Selector", "#body", ["body"] );
1075 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1076 * @test t( "ID Selector w/ Element", "ul#first", [] );
1078 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1079 * @test t( "Class Selector", ".blog.link", ["simon"] );
1080 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1081 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1083 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1084 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1085 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1086 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1088 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1089 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1090 * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1091 * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1092 * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1093 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1094 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1095 * @test t( "Adjacent", "a + a", ["groups"] );
1096 * @test t( "Adjacent", "a +a", ["groups"] );
1097 * @test t( "Adjacent", "a+ a", ["groups"] );
1098 * @test t( "Adjacent", "a+a", ["groups"] );
1099 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1100 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1101 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1102 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1103 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1104 * @test t( "Attribute Exists", "[@title]", ["google"] );
1105 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1106 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1107 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1108 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1109 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1110 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1112 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1113 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1114 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1115 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1116 * @test t( "Last Child", "p:last-child", ["sap"] );
1117 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1118 * @test t( "Empty", "ul:empty", ["firstUL"] );
1119 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1120 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1121 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1122 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1123 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1124 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1125 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1127 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1128 * @test t( "All Div Elements", "//div", ["main","foo"] );
1129 * @test t( "Absolute Path", "/html/body", ["body"] );
1130 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1131 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1132 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1133 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1134 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1135 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1136 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1137 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1138 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1139 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1140 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1142 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1143 * @test t( "First Element", "p:first", ["firstp"] );
1144 * @test t( "Last Element", "p:last", ["first"] );
1145 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1146 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1147 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1148 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1149 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1150 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1151 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1152 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1157 find: function( t, context ) {
1158 // Make sure that the context is a DOM Element
1159 if ( context && context.nodeType == undefined )
1162 // Set the correct context (if none is provided)
1163 context = context || jQuery.context || document;
1165 if ( t.constructor != String ) return [t];
1167 if ( !t.indexOf("//") ) {
1168 context = context.documentElement;
1169 t = t.substr(2,t.length);
1170 } else if ( !t.indexOf("/") ) {
1171 context = context.documentElement;
1172 t = t.substr(1,t.length);
1173 // FIX Assume the root element is right :(
1174 if ( t.indexOf("/") >= 1 )
1175 t = t.substr(t.indexOf("/"),t.length);
1178 var ret = [context];
1182 while ( t.length > 0 && last != t ) {
1186 t = jQuery.trim(t).replace( /^\/\//i, "" );
1188 var foundToken = false;
1190 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1191 var re = new RegExp("^(" + jQuery.token[i] + ")");
1195 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1196 t = jQuery.trim( t.replace( re, "" ) );
1201 if ( !foundToken ) {
1202 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1203 if ( ret[0] == context ) ret.shift();
1204 done = jQuery.merge( done, ret );
1205 r = ret = [context];
1206 t = " " + t.substr(1,t.length);
1208 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1209 var m = re2.exec(t);
1211 if ( m[1] == "#" ) {
1212 // Ummm, should make this work in all XML docs
1213 var oid = document.getElementById(m[2]);
1214 r = ret = oid ? [oid] : [];
1215 t = t.replace( re2, "" );
1217 if ( !m[2] || m[1] == "." ) m[2] = "*";
1219 for ( var i = 0; i < ret.length; i++ )
1220 r = jQuery.merge( r,
1222 jQuery.getAll(ret[i]) :
1223 ret[i].getElementsByTagName(m[2])
1230 var val = jQuery.filter(t,r);
1232 t = jQuery.trim(val.t);
1236 if ( ret && ret[0] == context ) ret.shift();
1237 done = jQuery.merge( done, ret );
1242 getAll: function(o,r) {
1244 var s = o.childNodes;
1245 for ( var i = 0; i < s.length; i++ )
1246 if ( s[i].nodeType == 1 ) {
1248 jQuery.getAll( s[i], r );
1253 attr: function(elem, name, value){
1256 "class": "className",
1257 "float": "cssFloat",
1258 innerHTML: "innerHTML",
1259 className: "className"
1263 if ( value != undefined ) elem[fix[name]] = value;
1264 return elem[fix[name]];
1265 } else if ( elem.getAttribute ) {
1266 if ( value != undefined ) elem.setAttribute( name, value );
1267 return elem.getAttribute( name, 2 );
1269 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1270 if ( value != undefined ) elem[name] = value;
1275 // The regular expressions that power the parsing engine
1277 // Match: [@value='test'], [@foo]
1278 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1280 // Match: [div], [div p]
1283 // Match: :contains('foo')
1284 [ "(:)S\\(Q\\)", 0 ],
1286 // Match: :even, :last-chlid
1290 filter: function(t,r,not) {
1291 // Figure out if we're doing regular, or inverse, filtering
1292 var g = not !== false ? jQuery.grep :
1293 function(a,f) {return jQuery.grep(a,f,true);};
1295 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1297 var p = jQuery.parse;
1299 for ( var i = 0; i < p.length; i++ ) {
1300 var re = new RegExp( "^" + p[i][0]
1302 // Look for a string-like sequence
1303 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1305 // Look for something (optionally) enclosed with quotes
1306 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1308 var m = re.exec( t );
1311 // Re-organize the match
1313 m = ["", m[1], m[3], m[2], m[4]];
1315 // Remove what we just matched
1316 t = t.replace( re, "" );
1322 // :not() is a special case that can be optomized by
1323 // keeping it out of the expression list
1324 if ( m[1] == ":" && m[2] == "not" )
1325 r = jQuery.filter(m[3],r,false).r;
1327 // Otherwise, find the expression to execute
1329 var f = jQuery.expr[m[1]];
1330 if ( f.constructor != String )
1331 f = jQuery.expr[m[1]][m[2]];
1333 // Build a custom macro to enclose it
1334 eval("f = function(a,i){" +
1335 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1336 "return " + f + "}");
1338 // Execute it against the current filter
1343 // Return an array of filtered elements (r)
1344 // and the modified expression string (t)
1345 return { r: r, t: t };
1349 * Remove the whitespace from the beginning and end of a string.
1354 * @param String str The string to trim.
1357 return t.replace(/^\s+|\s+$/g, "");
1361 * All ancestors of a given element.
1364 * @name jQuery.parents
1365 * @type Array<Element>
1366 * @param Element elem The element to find the ancestors of.
1368 parents: function( elem ){
1370 var cur = elem.parentNode;
1371 while ( cur && cur != document ) {
1372 matched.push( cur );
1373 cur = cur.parentNode;
1379 * All elements on a specified axis.
1382 * @name jQuery.sibling
1384 * @param Element elem The element to find all the siblings of (including itself).
1386 sibling: function(elem, pos, not) {
1389 var siblings = elem.parentNode.childNodes;
1390 for ( var i = 0; i < siblings.length; i++ ) {
1391 if ( not === true && siblings[i] == elem ) continue;
1393 if ( siblings[i].nodeType == 1 )
1394 elems.push( siblings[i] );
1395 if ( siblings[i] == elem )
1396 elems.n = elems.length - 1;
1399 return jQuery.extend( elems, {
1400 last: elems.n == elems.length - 1,
1401 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1402 prev: elems[elems.n - 1],
1403 next: elems[elems.n + 1]
1408 * Merge two arrays together, removing all duplicates.
1411 * @name jQuery.merge
1413 * @param Array a The first array to merge.
1414 * @param Array b The second array to merge.
1416 merge: function(first, second) {
1419 // Move b over to the new array (this helps to avoid
1420 // StaticNodeList instances)
1421 for ( var k = 0; k < first.length; k++ )
1422 result[k] = first[k];
1424 // Now check for duplicates between a and b and only
1425 // add the unique items
1426 for ( var i = 0; i < second.length; i++ ) {
1427 var noCollision = true;
1429 // The collision-checking process
1430 for ( var j = 0; j < first.length; j++ )
1431 if ( second[i] == first[j] )
1432 noCollision = false;
1434 // If the item is unique, add it
1436 result.push( second[i] );
1443 * Remove items that aren't matched in an array. The function passed
1444 * in to this method will be passed two arguments: 'a' (which is the
1445 * array item) and 'i' (which is the index of the item in the array).
1450 * @param Array array The Array to find items in.
1451 * @param Function fn The function to process each item against.
1452 * @param Boolean inv Invert the selection - select the opposite of the function.
1454 grep: function(elems, fn, inv) {
1455 // If a string is passed in for the function, make a function
1456 // for it (a handy shortcut)
1457 if ( fn.constructor == String )
1458 fn = new Function("a","i","return " + fn);
1462 // Go through the array, only saving the items
1463 // that pass the validator function
1464 for ( var i = 0; i < elems.length; i++ )
1465 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1466 result.push( elems[i] );
1472 * Translate all items in array to another array of items. The translation function
1473 * that is provided to this method is passed one argument: 'a' (the item to be
1474 * translated). If an array is returned, that array is mapped out and merged into
1475 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1476 * from the array. Both of these changes imply that the size of the array may not
1477 * be the same size upon completion, as it was when it started.
1482 * @param Array array The Array to translate.
1483 * @param Function fn The function to process each item against.
1485 map: function(elems, fn) {
1486 // If a string is passed in for the function, make a function
1487 // for it (a handy shortcut)
1488 if ( fn.constructor == String )
1489 fn = new Function("a","return " + fn);
1493 // Go through the array, translating each of the items to their
1494 // new value (or values).
1495 for ( var i = 0; i < elems.length; i++ ) {
1496 var val = fn(elems[i],i);
1498 if ( val !== null && val != undefined ) {
1499 if ( val.constructor != Array ) val = [val];
1500 result = jQuery.merge( result, val );
1508 * A number of helper functions used for managing events.
1509 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1513 // Bind an event to an element
1514 // Original by Dean Edwards
1515 add: function(element, type, handler) {
1516 // For whatever reason, IE has trouble passing the window object
1517 // around, causing it to be cloned in the process
1518 if ( jQuery.browser.msie && element.setInterval != undefined )
1521 // Make sure that the function being executed has a unique ID
1522 if ( !handler.guid )
1523 handler.guid = this.guid++;
1525 // Init the element's event structure
1526 if (!element.events)
1527 element.events = {};
1529 // Get the current list of functions bound to this event
1530 var handlers = element.events[type];
1532 // If it hasn't been initialized yet
1534 // Init the event handler queue
1535 handlers = element.events[type] = {};
1537 // Remember an existing handler, if it's already there
1538 if (element["on" + type])
1539 handlers[0] = element["on" + type];
1542 // Add the function to the element's handler list
1543 handlers[handler.guid] = handler;
1545 // And bind the global event handler to the element
1546 element["on" + type] = this.handle;
1548 // Remember the function in a global list (for triggering)
1549 if (!this.global[type])
1550 this.global[type] = [];
1551 this.global[type].push( element );
1557 // Detach an event or set of events from an element
1558 remove: function(element, type, handler) {
1560 if (type && element.events[type])
1562 delete element.events[type][handler.guid];
1564 for ( var i in element.events[type] )
1565 delete element.events[type][i];
1567 for ( var j in element.events )
1568 this.remove( element, j );
1571 trigger: function(type,data,element) {
1572 // Touch up the incoming data
1575 // Handle a global trigger
1577 var g = this.global[type];
1579 for ( var i = 0; i < g.length; i++ )
1580 this.trigger( type, data, g[i] );
1582 // Handle triggering a single element
1583 } else if ( element["on" + type] ) {
1584 // Pass along a fake event
1585 data.unshift( this.fix({ type: type, target: element }) );
1587 // Trigger the event
1588 element["on" + type].apply( element, data );
1592 handle: function(event) {
1593 if ( typeof jQuery == "undefined" ) return;
1595 event = event || jQuery.event.fix( window.event );
1597 // If no correct event was found, fail
1598 if ( !event ) return;
1600 var returnValue = true;
1602 var c = this.events[event.type];
1604 for ( var j in c ) {
1605 if ( c[j].apply( this, [event] ) === false ) {
1606 event.preventDefault();
1607 event.stopPropagation();
1608 returnValue = false;
1615 fix: function(event) {
1617 event.preventDefault = function() {
1618 this.returnValue = false;
1621 event.stopPropagation = function() {
1622 this.cancelBubble = true;
1633 var b = navigator.userAgent.toLowerCase();
1635 // Figure out what browser is being used
1637 safari: /webkit/.test(b),
1638 opera: /opera/.test(b),
1639 msie: /msie/.test(b) && !/opera/.test(b),
1640 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1643 // Check to see if the W3C box model is being used
1644 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1650 * Append all of the matched elements to another, specified, set of elements.
1651 * This operation is, essentially, the reverse of doing a regular
1652 * $(A).append(B), in that instead of appending B to A, you're appending
1655 * @example $("p").appendTo("#foo");
1656 * @before <p>I would like to say: </p><div id="foo"></div>
1657 * @result <div id="foo"><p>I would like to say: </p></div>
1661 * @param String expr A jQuery expression of elements to match.
1662 * @cat DOM/Manipulation
1667 * Prepend all of the matched elements to another, specified, set of elements.
1668 * This operation is, essentially, the reverse of doing a regular
1669 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1672 * @example $("p").prependTo("#foo");
1673 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1674 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1678 * @param String expr A jQuery expression of elements to match.
1679 * @cat DOM/Manipulation
1681 prependTo: "prepend",
1684 * Insert all of the matched elements before another, specified, set of elements.
1685 * This operation is, essentially, the reverse of doing a regular
1686 * $(A).before(B), in that instead of inserting B before A, you're inserting
1689 * @example $("p").insertBefore("#foo");
1690 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1691 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1693 * @name insertBefore
1695 * @param String expr A jQuery expression of elements to match.
1696 * @cat DOM/Manipulation
1698 insertBefore: "before",
1701 * Insert all of the matched elements after another, specified, set of elements.
1702 * This operation is, essentially, the reverse of doing a regular
1703 * $(A).after(B), in that instead of inserting B after A, you're inserting
1706 * @example $("p").insertAfter("#foo");
1707 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1708 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1712 * @param String expr A jQuery expression of elements to match.
1713 * @cat DOM/Manipulation
1715 insertAfter: "after"
1719 * Get the current CSS width of the first matched element.
1721 * @example $("p").width();
1722 * @before <p>This is just a test.</p>
1731 * Set the CSS width of every matched element. Be sure to include
1732 * the "px" (or other unit of measurement) after the number that you
1733 * specify, otherwise you might get strange results.
1735 * @example $("p").width("20px");
1736 * @before <p>This is just a test.</p>
1737 * @result <p style="width:20px;">This is just a test.</p>
1741 * @param String val Set the CSS property to the specified value.
1746 * Get the current CSS height of the first matched element.
1748 * @example $("p").height();
1749 * @before <p>This is just a test.</p>
1758 * Set the CSS height of every matched element. Be sure to include
1759 * the "px" (or other unit of measurement) after the number that you
1760 * specify, otherwise you might get strange results.
1762 * @example $("p").height("20px");
1763 * @before <p>This is just a test.</p>
1764 * @result <p style="height:20px;">This is just a test.</p>
1768 * @param String val Set the CSS property to the specified value.
1773 * Get the current CSS top of the first matched element.
1775 * @example $("p").top();
1776 * @before <p>This is just a test.</p>
1785 * Set the CSS top of every matched element. Be sure to include
1786 * the "px" (or other unit of measurement) after the number that you
1787 * specify, otherwise you might get strange results.
1789 * @example $("p").top("20px");
1790 * @before <p>This is just a test.</p>
1791 * @result <p style="top:20px;">This is just a test.</p>
1795 * @param String val Set the CSS property to the specified value.
1800 * Get the current CSS left of the first matched element.
1802 * @example $("p").left();
1803 * @before <p>This is just a test.</p>
1812 * Set the CSS left of every matched element. Be sure to include
1813 * the "px" (or other unit of measurement) after the number that you
1814 * specify, otherwise you might get strange results.
1816 * @example $("p").left("20px");
1817 * @before <p>This is just a test.</p>
1818 * @result <p style="left:20px;">This is just a test.</p>
1822 * @param String val Set the CSS property to the specified value.
1827 * Get the current CSS position of the first matched element.
1829 * @example $("p").position();
1830 * @before <p>This is just a test.</p>
1839 * Set the CSS position of every matched element.
1841 * @example $("p").position("relative");
1842 * @before <p>This is just a test.</p>
1843 * @result <p style="position:relative;">This is just a test.</p>
1847 * @param String val Set the CSS property to the specified value.
1852 * Get the current CSS float of the first matched element.
1854 * @example $("p").float();
1855 * @before <p>This is just a test.</p>
1864 * Set the CSS float of every matched element.
1866 * @example $("p").float("left");
1867 * @before <p>This is just a test.</p>
1868 * @result <p style="float:left;">This is just a test.</p>
1872 * @param String val Set the CSS property to the specified value.
1877 * Get the current CSS overflow of the first matched element.
1879 * @example $("p").overflow();
1880 * @before <p>This is just a test.</p>
1889 * Set the CSS overflow of every matched element.
1891 * @example $("p").overflow("auto");
1892 * @before <p>This is just a test.</p>
1893 * @result <p style="overflow:auto;">This is just a test.</p>
1897 * @param String val Set the CSS property to the specified value.
1902 * Get the current CSS color of the first matched element.
1904 * @example $("p").color();
1905 * @before <p>This is just a test.</p>
1914 * Set the CSS color of every matched element.
1916 * @example $("p").color("blue");
1917 * @before <p>This is just a test.</p>
1918 * @result <p style="color:blue;">This is just a test.</p>
1922 * @param String val Set the CSS property to the specified value.
1927 * Get the current CSS background of the first matched element.
1929 * @example $("p").background();
1930 * @before <p>This is just a test.</p>
1939 * Set the CSS background of every matched element.
1941 * @example $("p").background("blue");
1942 * @before <p>This is just a test.</p>
1943 * @result <p style="background:blue;">This is just a test.</p>
1947 * @param String val Set the CSS property to the specified value.
1951 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1953 filter: [ "eq", "lt", "gt", "contains" ],
1957 * Get the current value of the first matched element.
1959 * @example $("input").val();
1960 * @before <input type="text" value="some text"/>
1961 * @result "some text"
1965 * @cat DOM/Attributes
1969 * Set the value of every matched element.
1971 * @example $("input").value("test");
1972 * @before <input type="text" value="some text"/>
1973 * @result <input type="text" value="test"/>
1977 * @param String val Set the property to the specified value.
1978 * @cat DOM/Attributes
1983 * Get the html contents of the first matched element.
1985 * @example $("div").html();
1986 * @before <div><input/></div>
1991 * @cat DOM/Attributes
1995 * Set the html contents of every matched element.
1997 * @example $("div").html("<b>new stuff</b>");
1998 * @before <div><input/></div>
1999 * @result <div><b>new stuff</b></div>
2001 * @test var div = $("div");
2002 * div.html("<b>test</b>");
2004 * for ( var i = 0; i < div.size(); i++ ) {
2005 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2007 * ok( pass, "Set HTML" );
2011 * @param String val Set the html contents to the specified value.
2012 * @cat DOM/Attributes
2017 * Get the current id of the first matched element.
2019 * @example $("input").id();
2020 * @before <input type="text" id="test" value="some text"/>
2025 * @cat DOM/Attributes
2029 * Set the id of every matched element.
2031 * @example $("input").id("newid");
2032 * @before <input type="text" id="test" value="some text"/>
2033 * @result <input type="text" id="newid" value="some text"/>
2037 * @param String val Set the property to the specified value.
2038 * @cat DOM/Attributes
2043 * Get the current title of the first matched element.
2045 * @example $("img").title();
2046 * @before <img src="test.jpg" title="my image"/>
2047 * @result "my image"
2051 * @cat DOM/Attributes
2055 * Set the title of every matched element.
2057 * @example $("img").title("new title");
2058 * @before <img src="test.jpg" title="my image"/>
2059 * @result <img src="test.jpg" title="new image"/>
2063 * @param String val Set the property to the specified value.
2064 * @cat DOM/Attributes
2069 * Get the current name of the first matched element.
2071 * @example $("input").name();
2072 * @before <input type="text" name="username"/>
2073 * @result "username"
2077 * @cat DOM/Attributes
2081 * Set the name of every matched element.
2083 * @example $("input").name("user");
2084 * @before <input type="text" name="username"/>
2085 * @result <input type="text" name="user"/>
2089 * @param String val Set the property to the specified value.
2090 * @cat DOM/Attributes
2095 * Get the current href of the first matched element.
2097 * @example $("a").href();
2098 * @before <a href="test.html">my link</a>
2099 * @result "test.html"
2103 * @cat DOM/Attributes
2107 * Set the href of every matched element.
2109 * @example $("a").href("test2.html");
2110 * @before <a href="test.html">my link</a>
2111 * @result <a href="test2.html">my link</a>
2115 * @param String val Set the property to the specified value.
2116 * @cat DOM/Attributes
2121 * Get the current src of the first matched element.
2123 * @example $("img").src();
2124 * @before <img src="test.jpg" title="my image"/>
2125 * @result "test.jpg"
2129 * @cat DOM/Attributes
2133 * Set the src of every matched element.
2135 * @example $("img").src("test2.jpg");
2136 * @before <img src="test.jpg" title="my image"/>
2137 * @result <img src="test2.jpg" title="my image"/>
2141 * @param String val Set the property to the specified value.
2142 * @cat DOM/Attributes
2147 * Get the current rel of the first matched element.
2149 * @example $("a").rel();
2150 * @before <a href="test.html" rel="nofollow">my link</a>
2151 * @result "nofollow"
2155 * @cat DOM/Attributes
2159 * Set the rel of every matched element.
2161 * @example $("a").rel("nofollow");
2162 * @before <a href="test.html">my link</a>
2163 * @result <a href="test.html" rel="nofollow">my link</a>
2167 * @param String val Set the property to the specified value.
2168 * @cat DOM/Attributes
2175 * Get a set of elements containing the unique parents of the matched
2178 * @example $("p").parent()
2179 * @before <div><p>Hello</p><p>Hello</p></div>
2180 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2184 * @cat DOM/Traversing
2188 * Get a set of elements containing the unique parents of the matched
2189 * set of elements, and filtered by an expression.
2191 * @example $("p").parent(".selected")
2192 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2193 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2197 * @param String expr An expression to filter the parents with
2198 * @cat DOM/Traversing
2200 parent: "a.parentNode",
2203 * Get a set of elements containing the unique ancestors of the matched
2206 * @example $("span").ancestors()
2207 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2208 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2212 * @cat DOM/Traversing
2216 * Get a set of elements containing the unique ancestors of the matched
2217 * set of elements, and filtered by an expression.
2219 * @example $("span").ancestors("p")
2220 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2221 * @result [ <p><span>Hello</span></p> ]
2225 * @param String expr An expression to filter the ancestors with
2226 * @cat DOM/Traversing
2228 ancestors: jQuery.parents,
2231 * Get a set of elements containing the unique ancestors of the matched
2234 * @example $("span").ancestors()
2235 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2236 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2240 * @cat DOM/Traversing
2244 * Get a set of elements containing the unique ancestors of the matched
2245 * set of elements, and filtered by an expression.
2247 * @example $("span").ancestors("p")
2248 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2249 * @result [ <p><span>Hello</span></p> ]
2253 * @param String expr An expression to filter the ancestors with
2254 * @cat DOM/Traversing
2256 parents: jQuery.parents,
2259 * Get a set of elements containing the unique next siblings of each of the
2260 * matched set of elements.
2262 * It only returns the very next sibling, not all next siblings.
2264 * @example $("p").next()
2265 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2266 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2270 * @cat DOM/Traversing
2274 * Get a set of elements containing the unique next siblings of each of the
2275 * matched set of elements, and filtered by an expression.
2277 * It only returns the very next sibling, not all next siblings.
2279 * @example $("p").next(".selected")
2280 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2281 * @result [ <p class="selected">Hello Again</p> ]
2285 * @param String expr An expression to filter the next Elements with
2286 * @cat DOM/Traversing
2288 next: "jQuery.sibling(a).next",
2291 * Get a set of elements containing the unique previous siblings of each of the
2292 * matched set of elements.
2294 * It only returns the immediately previous sibling, not all previous siblings.
2296 * @example $("p").previous()
2297 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2298 * @result [ <div><span>Hello Again</span></div> ]
2302 * @cat DOM/Traversing
2306 * Get a set of elements containing the unique previous siblings of each of the
2307 * matched set of elements, and filtered by an expression.
2309 * It only returns the immediately previous sibling, not all previous siblings.
2311 * @example $("p").previous(".selected")
2312 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2313 * @result [ <div><span>Hello</span></div> ]
2317 * @param String expr An expression to filter the previous Elements with
2318 * @cat DOM/Traversing
2320 prev: "jQuery.sibling(a).prev",
2323 * Get a set of elements containing all of the unique siblings of each of the
2324 * matched set of elements.
2326 * @example $("div").siblings()
2327 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2328 * @result [ <p>Hello</p>, <p>And Again</p> ]
2332 * @cat DOM/Traversing
2336 * Get a set of elements containing all of the unique siblings of each of the
2337 * matched set of elements, and filtered by an expression.
2339 * @example $("div").siblings(".selected")
2340 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2341 * @result [ <p class="selected">Hello Again</p> ]
2345 * @param String expr An expression to filter the sibling Elements with
2346 * @cat DOM/Traversing
2348 siblings: jQuery.sibling,
2352 * Get a set of elements containing all of the unique children of each of the
2353 * matched set of elements.
2355 * @example $("div").children()
2356 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2357 * @result [ <span>Hello Again</span> ]
2361 * @cat DOM/Traversing
2365 * Get a set of elements containing all of the unique children of each of the
2366 * matched set of elements, and filtered by an expression.
2368 * @example $("div").children(".selected")
2369 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2370 * @result [ <p class="selected">Hello Again</p> ]
2374 * @param String expr An expression to filter the child Elements with
2375 * @cat DOM/Traversing
2377 children: "a.childNodes"
2382 removeAttr: function( key ) {
2383 this.removeAttribute( key );
2387 * Displays each of the set of matched elements if they are hidden.
2389 * @example $("p").show()
2390 * @before <p style="display: none">Hello</p>
2391 * @result [ <p style="display: block">Hello</p> ]
2393 * @test var pass = true, div = $("div");
2394 * div.show().each(function(){
2395 * if ( this.style.display == "none" ) pass = false;
2397 * ok( pass, "Show" );
2404 this.style.display = this.oldblock ? this.oldblock : "";
2405 if ( jQuery.css(this,"display") == "none" )
2406 this.style.display = "block";
2410 * Hides each of the set of matched elements if they are shown.
2412 * @example $("p").hide()
2413 * @before <p>Hello</p>
2414 * @result [ <p style="display: none">Hello</p> ]
2416 * var pass = true, div = $("div");
2417 * div.hide().each(function(){
2418 * if ( this.style.display != "none" ) pass = false;
2420 * ok( pass, "Hide" );
2427 this.oldblock = this.oldblock || jQuery.css(this,"display");
2428 if ( this.oldblock == "none" )
2429 this.oldblock = "block";
2430 this.style.display = "none";
2434 * Toggles each of the set of matched elements. If they are shown,
2435 * toggle makes them hidden. If they are hidden, toggle
2438 * @example $("p").toggle()
2439 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2440 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2447 $(this)[ $(this).is(":hidden") ? "show" : "hide" ].apply( $(this), arguments );
2451 * Adds the specified class to each of the set of matched elements.
2453 * @example $("p").addClass("selected")
2454 * @before <p>Hello</p>
2455 * @result [ <p class="selected">Hello</p> ]
2457 * @test var div = $("div");
2458 * div.addClass("test");
2460 * for ( var i = 0; i < div.size(); i++ ) {
2461 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2463 * ok( pass, "Add Class" );
2467 * @param String class A CSS class to add to the elements
2470 addClass: function(c){
2471 jQuery.className.add(this,c);
2475 * Removes the specified class from the set of matched elements.
2477 * @example $("p").removeClass("selected")
2478 * @before <p class="selected">Hello</p>
2479 * @result [ <p>Hello</p> ]
2481 * @test var div = $("div").addClass("test");
2482 * div.removeClass("test");
2484 * for ( var i = 0; i < div.size(); i++ ) {
2485 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2487 * ok( pass, "Remove Class" );
2491 * @param String class A CSS class to remove from the elements
2494 removeClass: function(c){
2495 jQuery.className.remove(this,c);
2499 * Adds the specified class if it is present, removes it if it is
2502 * @example $("p").toggleClass("selected")
2503 * @before <p>Hello</p><p class="selected">Hello Again</p>
2504 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2508 * @param String class A CSS class with which to toggle the elements
2511 toggleClass: function( c ){
2512 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2516 * Removes all matched elements from the DOM. This does NOT remove them from the
2517 * jQuery object, allowing you to use the matched elements further.
2519 * @example $("p").remove();
2520 * @before <p>Hello</p> how are <p>you?</p>
2525 * @cat DOM/Manipulation
2529 * Removes only elements (out of the list of matched elements) that match
2530 * the specified jQuery expression. This does NOT remove them from the
2531 * jQuery object, allowing you to use the matched elements further.
2533 * @example $("p").remove(".hello");
2534 * @before <p class="hello">Hello</p> how are <p>you?</p>
2535 * @result how are <p>you?</p>
2539 * @param String expr A jQuery expression to filter elements by.
2540 * @cat DOM/Manipulation
2542 remove: function(a){
2543 if ( !a || jQuery.filter( [this], a ).r )
2544 this.parentNode.removeChild( this );
2548 * Removes all child nodes from the set of matched elements.
2550 * @example $("p").empty()
2551 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2552 * @result [ <p></p> ]
2556 * @cat DOM/Manipulation
2559 while ( this.firstChild )
2560 this.removeChild( this.firstChild );
2564 * Binds a particular event (like click) to a each of a set of match elements.
2566 * @example $("p").bind( "click", function() { alert("Hello"); } )
2567 * @before <p>Hello</p>
2568 * @result [ <p>Hello</p> ]
2570 * Cancel a default action and prevent it from bubbling by returning false
2571 * from your function.
2573 * @example $("form").bind( "submit", function() { return false; } )
2575 * Cancel a default action by using the preventDefault method.
2577 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2579 * Stop an event from bubbling by using the stopPropogation method.
2581 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2585 * @param String type An event type
2586 * @param Function fn A function to bind to the event on each of the set of matched elements
2589 bind: function( type, fn ) {
2590 if ( fn.constructor == String )
2591 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2592 jQuery.event.add( this, type, fn );
2596 * The opposite of bind, removes a bound event from each of the matched
2597 * elements. You must pass the identical function that was used in the original
2600 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2601 * @before <p onclick="alert('Hello');">Hello</p>
2602 * @result [ <p>Hello</p> ]
2606 * @param String type An event type
2607 * @param Function fn A function to unbind from the event on each of the set of matched elements
2612 * Removes all bound events of a particular type from each of the matched
2615 * @example $("p").unbind( "click" )
2616 * @before <p onclick="alert('Hello');">Hello</p>
2617 * @result [ <p>Hello</p> ]
2621 * @param String type An event type
2626 * Removes all bound events from each of the matched elements.
2628 * @example $("p").unbind()
2629 * @before <p onclick="alert('Hello');">Hello</p>
2630 * @result [ <p>Hello</p> ]
2636 unbind: function( type, fn ) {
2637 jQuery.event.remove( this, type, fn );
2641 * Trigger a type of event on every matched element.
2643 * @example $("p").trigger("click")
2644 * @before <p click="alert('hello')">Hello</p>
2645 * @result alert('hello')
2649 * @param String type An event type to trigger.
2652 trigger: function( type, data ) {
2653 jQuery.event.trigger( type, data, this );