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
72 if ( typeof $ != "undefined" )
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(){
197 * this.src = "test.jpg";
199 * @before <img/> <img/>
200 * @result <img src="test.jpg"/> <img src="test.jpg"/>
202 * @example $("img").each(function(i){
203 * alert( "Image #" + i + " is " + this );
205 * @before <img/> <img/>
206 * @result <img src="test.jpg"/> <img src="test.jpg"/>
208 * @test var div = $("div");
209 * div.each(function(){this.foo = 'zoo';});
211 * for ( var i = 0; i < div.size(); i++ ) {
212 * if ( div.get(i).foo != "zoo" ) pass = false;
214 * ok( pass, "Execute a function, Relative" );
218 * @param Function fn A function to execute
221 each: function( fn, args ) {
222 return jQuery.each( this, fn, args );
225 index: function( obj ) {
227 this.each(function(i){
228 if ( this == obj ) pos = i;
234 * Access a property on the first matched element.
235 * This method makes it easy to retreive a property value
236 * from the first matched element.
238 * @example $("img").attr("src");
239 * @before <img src="test.jpg"/>
244 * @param String name The name of the property to access.
249 * Set a hash of key/value object properties to all matched elements.
250 * This serves as the best way to set a large number of properties
251 * on all matched elements.
253 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
255 * @result <img src="test.jpg" alt="Test Image"/>
257 * @test var pass = true;
258 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
259 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
261 * ok( pass, "Set Multiple Attributes" );
265 * @param Hash prop A set of key/value pairs to set as object properties.
270 * Set a single property to a value, on all matched elements.
272 * @example $("img").attr("src","test.jpg");
274 * @result <img src="test.jpg"/>
276 * @test var div = $("div");
277 * div.attr("foo", "bar");
279 * for ( var i = 0; i < div.size(); i++ ) {
280 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
282 * ok( pass, "Set Attribute" );
286 * @param String key The name of the property to set.
287 * @param Object value The value to set the property to.
290 attr: function( key, value, type ) {
291 // Check to see if we're setting style values
292 return key.constructor != String || value != undefined ?
293 this.each(function(){
294 // See if we're setting a hash of styles
295 if ( value == undefined )
296 // Set all the styles
297 for ( var prop in key )
299 type ? this.style : this,
303 // See if we're setting a single key/value style
306 type ? this.style : this,
311 // Look for the case where we're accessing a style value
312 jQuery[ type || "attr" ]( this[0], key );
316 * Access a style property on the first matched element.
317 * This method makes it easy to retreive a style property value
318 * from the first matched element.
320 * @example $("p").css("red");
321 * @before <p style="color:red;">Test Paragraph.</p>
326 * @param String name The name of the property to access.
331 * Set a hash of key/value style properties to all matched elements.
332 * This serves as the best way to set a large number of style properties
333 * on all matched elements.
335 * @example $("p").css({ color: "red", background: "blue" });
336 * @before <p>Test Paragraph.</p>
337 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
341 * @param Hash prop A set of key/value pairs to set as style properties.
346 * Set a single style property to a value, on all matched elements.
348 * @example $("p").css("color","red");
349 * @before <p>Test Paragraph.</p>
350 * @result <p style="color:red;">Test Paragraph.</p>
354 * @param String key The name of the property to set.
355 * @param Object value The value to set the property to.
358 css: function( key, value ) {
359 return this.attr( key, value, "curCSS" );
363 * Retreive the text contents of all matched elements. The result is
364 * a string that contains the combined text contents of all matched
365 * elements. This method works on both HTML and XML documents.
367 * @example $("p").text();
368 * @before <p>Test Paragraph.</p>
369 * @result Test Paragraph.
378 for ( var j = 0; j < e.length; j++ ) {
379 var r = e[j].childNodes;
380 for ( var i = 0; i < r.length; i++ )
381 if ( r[i].nodeType != 8 )
382 t += r[i].nodeType != 1 ?
383 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
389 * Wrap all matched elements with a structure of other elements.
390 * This wrapping process is most useful for injecting additional
391 * stucture into a document, without ruining the original semantic
392 * qualities of a document.
394 * The way that is works is that it goes through the first element argument
395 * provided and finds the deepest element within the structure - it is that
396 * element that will en-wrap everything else.
398 * @example $("p").wrap("<div class='wrap'></div>");
399 * @before <p>Test Paragraph.</p>
400 * @result <div class='wrap'><p>Test Paragraph.</p></div>
404 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
405 * @any Element elem A DOM element that will be wrapped.
406 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
407 * @any Object obj Any object, converted to a string, then a text node.
408 * @cat DOM/Manipulation
411 // The elements to wrap the target around
412 var a = jQuery.clean(arguments);
414 // Wrap each of the matched elements individually
415 return this.each(function(){
416 // Clone the structure that we're using to wrap
417 var b = a[0].cloneNode(true);
419 // Insert it before the element to be wrapped
420 this.parentNode.insertBefore( b, this );
422 // Find he deepest point in the wrap structure
423 while ( b.firstChild )
426 // Move the matched element to within the wrap structure
427 b.appendChild( this );
432 * Append any number of elements to the inside of all matched elements.
433 * This operation is similar to doing an appendChild to all the
434 * specified elements, adding them into the document.
436 * @example $("p").append("<b>Hello</b>");
437 * @before <p>I would like to say: </p>
438 * @result <p>I would like to say: <b>Hello</b></p>
442 * @any String html A string of HTML, that will be created on the fly and appended to the target.
443 * @any Element elem A DOM element that will be appended.
444 * @any Array<Element> elems An array of elements, all of which will be appended.
445 * @any Object obj Any object, converted to a string, then a text node.
446 * @cat DOM/Manipulation
449 return this.domManip(arguments, true, 1, function(a){
450 this.appendChild( a );
455 * Prepend any number of elements to the inside of all matched elements.
456 * This operation is the best way to insert a set of elements inside, at the
457 * beginning, of all the matched element.
459 * @example $("p").prepend("<b>Hello</b>");
460 * @before <p>, how are you?</p>
461 * @result <p><b>Hello</b>, how are you?</p>
465 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
466 * @any Element elem A DOM element that will be prepended.
467 * @any Array<Element> elems An array of elements, all of which will be prepended.
468 * @any Object obj Any object, converted to a string, then a text node.
469 * @cat DOM/Manipulation
471 prepend: function() {
472 return this.domManip(arguments, true, -1, function(a){
473 this.insertBefore( a, this.firstChild );
478 * Insert any number of elements before each of the matched elements.
480 * @example $("p").before("<b>Hello</b>");
481 * @before <p>how are you?</p>
482 * @result <b>Hello</b><p>how are you?</p>
486 * @any String html A string of HTML, that will be created on the fly and inserted.
487 * @any Element elem A DOM element that will beinserted.
488 * @any Array<Element> elems An array of elements, all of which will be inserted.
489 * @any Object obj Any object, converted to a string, then a text node.
490 * @cat DOM/Manipulation
493 return this.domManip(arguments, false, 1, function(a){
494 this.parentNode.insertBefore( a, this );
499 * Insert any number of elements after each of the matched elements.
501 * @example $("p").after("<p>I'm doing fine.</p>");
502 * @before <p>How are you?</p>
503 * @result <p>How are you?</p><p>I'm doing fine.</p>
507 * @any String html A string of HTML, that will be created on the fly and inserted.
508 * @any Element elem A DOM element that will beinserted.
509 * @any Array<Element> elems An array of elements, all of which will be inserted.
510 * @any Object obj Any object, converted to a string, then a text node.
511 * @cat DOM/Manipulation
514 return this.domManip(arguments, false, -1, function(a){
515 this.parentNode.insertBefore( a, this.nextSibling );
520 * End the most recent 'destructive' operation, reverting the list of matched elements
521 * back to its previous state. After an end operation, the list of matched elements will
522 * revert to the last state of matched elements.
524 * @example $("p").find("span").end();
525 * @before <p><span>Hello</span>, how are you?</p>
526 * @result $("p").find("span").end() == [ <p>...</p> ]
530 * @cat DOM/Traversing
533 return this.get( this.stack.pop() );
537 * Searches for all elements that match the specified expression.
538 * This method is the optimal way of finding additional descendant
539 * elements with which to process.
541 * All searching is done using a jQuery expression. The expression can be
542 * written using CSS 1-3 Selector syntax, or basic XPath.
544 * @example $("p").find("span");
545 * @before <p><span>Hello</span>, how are you?</p>
546 * @result $("p").find("span") == [ <span>Hello</span> ]
550 * @param String expr An expression to search with.
551 * @cat DOM/Traversing
554 return this.pushStack( jQuery.map( this, function(a){
555 return jQuery.find(t,a);
559 clone: function(deep) {
560 return this.pushStack( jQuery.map( this, function(a){
561 return a.cloneNode( deep != undefined ? deep : true );
566 * Removes all elements from the set of matched elements that do not
567 * match the specified expression. This method is used to narrow down
568 * the results of a search.
570 * All searching is done using a jQuery expression. The expression
571 * can be written using CSS 1-3 Selector syntax, or basic XPath.
573 * @example $("p").filter(".selected")
574 * @before <p class="selected">Hello</p><p>How are you?</p>
575 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
579 * @param String expr An expression to search with.
580 * @cat DOM/Traversing
584 * Removes all elements from the set of matched elements that do not
585 * match at least one of the expressions passed to the function. This
586 * method is used when you want to filter the set of matched elements
587 * through more than one expression.
589 * Elements will be retained in the jQuery object if they match at
590 * least one of the expressions passed.
592 * @example $("p").filter([".selected", ":first"])
593 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
594 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
598 * @param Array<String> exprs A set of expressions to evaluate against
599 * @cat DOM/Traversing
601 filter: function(t) {
602 return this.pushStack(
603 t.constructor == Array &&
604 jQuery.map(this,function(a){
605 for ( var i = 0; i < t.length; i++ )
606 if ( jQuery.filter(t[i],[a]).r.length )
610 t.constructor == Boolean &&
611 ( t ? this.get() : [] ) ||
613 t.constructor == Function &&
614 jQuery.grep( this, t ) ||
616 jQuery.filter(t,this).r, arguments );
620 * Removes the specified Element from the set of matched elements. This
621 * method is used to remove a single Element from a jQuery object.
623 * @example $("p").not( document.getElementById("selected") )
624 * @before <p>Hello</p><p id="selected">Hello Again</p>
625 * @result [ <p>Hello</p> ]
629 * @param Element el An element to remove from the set
630 * @cat DOM/Traversing
634 * Removes elements matching the specified expression from the set
635 * of matched elements. This method is used to remove one or more
636 * elements from a jQuery object.
638 * @example $("p").not("#selected")
639 * @before <p>Hello</p><p id="selected">Hello Again</p>
640 * @result [ <p>Hello</p> ]
641 * @test cmpOK($("#main > p#ap > a").not("#google").length, "==", 2, ".not")
645 * @param String expr An expression with which to remove matching elements
646 * @cat DOM/Traversing
649 return this.pushStack( t.constructor == String ?
650 jQuery.filter(t,this,false).r :
651 jQuery.grep(this,function(a){ return a != t; }), arguments );
655 * Adds the elements matched by the expression to the jQuery object. This
656 * can be used to concatenate the result sets of two expressions.
658 * @example $("p").add("span")
659 * @before <p>Hello</p><p><span>Hello Again</span></p>
660 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
664 * @param String expr An expression whose matched elements are added
665 * @cat DOM/Traversing
669 * Adds each of the Elements in the array to the set of matched elements.
670 * This is used to add a set of Elements to a jQuery object.
672 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
673 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
674 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
678 * @param Array<Element> els An array of Elements to add
679 * @cat DOM/Traversing
683 * Adds a single Element to the set of matched elements. This is used to
684 * add a single Element to a jQuery object.
686 * @example $("p").add( document.getElementById("a") )
687 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
688 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
692 * @param Element el An Element to add
693 * @cat DOM/Traversing
696 return this.pushStack( jQuery.merge( this, t.constructor == String ?
697 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
701 * A wrapper function for each() to be used by append and prepend.
702 * Handles cases where you're trying to modify the inner contents of
703 * a table, when you actually need to work with the tbody.
706 * @param {String} expr The expression with which to filter
708 * @cat DOM/Traversing
711 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
720 * @param Boolean table
722 * @param Function fn The function doing the DOM manipulation.
725 domManip: function(args, table, dir, fn){
726 var clone = this.size() > 1;
727 var a = jQuery.clean(args);
729 return this.each(function(){
732 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
733 var tbody = this.getElementsByTagName("tbody");
735 if ( !tbody.length ) {
736 obj = document.createElement("tbody");
737 this.appendChild( obj );
742 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
743 i != ( dir < 0 ? dir : a.length ); i += dir ) {
744 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
758 pushStack: function(a,args) {
759 var fn = args && args[args.length-1];
761 if ( !fn || fn.constructor != Function ) {
762 if ( !this.stack ) this.stack = [];
763 this.stack.push( this.get() );
766 var old = this.get();
768 if ( fn.constructor == Function )
769 return this.each( fn );
788 * Extend one object with another, returning the original,
789 * modified, object. This is a great utility for simple inheritance.
791 * @name jQuery.extend
792 * @param Object obj The object to extend
793 * @param Object prop The object that will be merged into the first.
797 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
798 if ( !prop ) { prop = obj; obj = this; }
799 for ( var i in prop ) obj[i] = prop[i];
810 jQuery.initDone = true;
812 jQuery.each( jQuery.macros.axis, function(i,n){
813 jQuery.fn[ i ] = function(a) {
814 var ret = jQuery.map(this,n);
815 if ( a && a.constructor == String )
816 ret = jQuery.filter(a,ret).r;
817 return this.pushStack( ret, arguments );
821 jQuery.each( jQuery.macros.to, function(i,n){
822 jQuery.fn[ i ] = function(){
824 return this.each(function(){
825 for ( var j = 0; j < a.length; j++ )
831 jQuery.each( jQuery.macros.each, function(i,n){
832 jQuery.fn[ i ] = function() {
833 return this.each( n, arguments );
837 jQuery.each( jQuery.macros.filter, function(i,n){
838 jQuery.fn[ n ] = function(num,fn) {
839 return this.filter( ":" + n + "(" + num + ")", fn );
843 jQuery.each( jQuery.macros.attr, function(i,n){
845 jQuery.fn[ i ] = function(h) {
846 return h == undefined ?
847 this.length ? this[0][n] : null :
852 jQuery.each( jQuery.macros.css, function(i,n){
853 jQuery.fn[ n ] = function(h) {
854 return h == undefined ?
855 ( this.length ? jQuery.css( this[0], n ) : null ) :
863 * A generic iterator function, which can be used to seemlessly
864 * iterate over both objects and arrays.
867 * @param Object obj The object, or array, to iterate over.
868 * @param Object fn The function that will be executed on every object.
872 each: function( obj, fn, args ) {
873 if ( obj.length == undefined )
875 fn.apply( obj[i], args || [i, obj[i]] );
877 for ( var i = 0; i < obj.length; i++ )
878 fn.apply( obj[i], args || [i, obj[i]] );
884 if (jQuery.className.has(o,c)) return;
885 o.className += ( o.className ? " " : "" ) + c;
887 remove: function(o,c){
888 o.className = !c ? "" :
890 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
893 if ( e.className != undefined )
895 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
900 * Swap in/out style options.
903 swap: function(e,o,f) {
905 e.style["old"+i] = e.style[i];
910 e.style[i] = e.style["old"+i];
914 if ( p == "height" || p == "width" ) {
915 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
918 old["padding" + d[i]] = 0;
919 old["border" + d[i] + "Width"] = 0;
922 jQuery.swap( e, old, function() {
923 if (jQuery.css(e,"display") != "none") {
924 oHeight = e.offsetHeight;
925 oWidth = e.offsetWidth;
927 e = $(e.cloneNode(true)).css({
928 visibility: "hidden", position: "absolute", display: "block"
929 }).prependTo("body")[0];
931 oHeight = e.clientHeight;
932 oWidth = e.clientWidth;
934 e.parentNode.removeChild(e);
938 return p == "height" ? oHeight : oWidth;
939 } else if ( p == "opacity" && jQuery.browser.msie )
940 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
942 return jQuery.curCSS( e, p );
945 curCSS: function(elem, prop, force) {
948 if (!force && elem.style[prop]) {
950 ret = elem.style[prop];
952 } else if (elem.currentStyle) {
954 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
955 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
957 } else if (document.defaultView && document.defaultView.getComputedStyle) {
959 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
960 var cur = document.defaultView.getComputedStyle(elem, null);
963 ret = cur.getPropertyValue(prop);
964 else if ( prop == 'display' )
967 jQuery.swap(elem, { display: 'block' }, function() {
968 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
978 for ( var i = 0; i < a.length; i++ ) {
979 if ( a[i].constructor == String ) {
983 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
985 a[i] = "<table>" + a[i] + "</table>";
986 } else if ( !a[i].indexOf("<tr") ) {
988 a[i] = "<table>" + a[i] + "</table>";
989 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
991 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
994 var div = document.createElement("div");
995 div.innerHTML = a[i];
998 div = div.firstChild;
999 if ( table != "thead" ) div = div.firstChild;
1000 if ( table == "td" ) div = div.firstChild;
1003 for ( var j = 0; j < div.childNodes.length; j++ )
1004 r.push( div.childNodes[j] );
1005 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1006 for ( var k = 0; k < a[i].length; k++ )
1008 else if ( a[i] !== null )
1009 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1015 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1016 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1024 last: "i==r.length-1",
1029 "nth-child": "jQuery.sibling(a,m[3]).cur",
1030 "first-child": "jQuery.sibling(a,0).cur",
1031 "last-child": "jQuery.sibling(a,0).last",
1032 "only-child": "jQuery.sibling(a).length==1",
1035 parent: "a.childNodes.length",
1036 empty: "!a.childNodes.length",
1039 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1042 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1043 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1046 enabled: "!a.disabled",
1047 disabled: "a.disabled",
1048 checked: "a.checked",
1049 selected: "a.selected"
1051 ".": "jQuery.className.has(a,m[2])",
1055 "^=": "!z.indexOf(m[4])",
1056 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1057 "*=": "z.indexOf(m[4])>=0",
1060 "[": "jQuery.find(m[2],a).length"
1064 "\\.\\.|/\\.\\.", "a.parentNode",
1065 ">|/", "jQuery.sibling(a.firstChild)",
1066 "\\+", "jQuery.sibling(a).next",
1069 var s = jQuery.sibling(a);
1071 for ( var i = s.n; i < s.length; i++ )
1079 * @test t( "Element Selector", "div", ["main","foo"] );
1080 * @test t( "Element Selector", "body", ["body"] );
1081 * @test t( "Element Selector", "html", ["html"] );
1082 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1083 * @test t( "Parent Element", "div div", ["foo"] );
1085 * @test t( "ID Selector", "#body", ["body"] );
1086 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1087 * @test t( "ID Selector w/ Element", "ul#first", [] );
1089 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1090 * @test t( "Class Selector", ".blog.link", ["simon"] );
1091 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1092 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1094 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1095 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1096 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1097 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1099 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1100 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1101 * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1102 * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1103 * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1104 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1105 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1106 * @test t( "Adjacent", "a + a", ["groups"] );
1107 * @test t( "Adjacent", "a +a", ["groups"] );
1108 * @test t( "Adjacent", "a+ a", ["groups"] );
1109 * @test t( "Adjacent", "a+a", ["groups"] );
1110 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1111 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1112 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1113 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1114 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1115 * @test t( "Attribute Exists", "[@title]", ["google"] );
1116 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1117 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1118 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1119 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1120 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1121 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1123 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1124 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1125 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1126 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1127 * @test t( "Last Child", "p:last-child", ["sap"] );
1128 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1129 * @test t( "Empty", "ul:empty", ["firstUL"] );
1130 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1131 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1132 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1133 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1134 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1135 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1136 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1138 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1139 * @test t( "All Div Elements", "//div", ["main","foo"] );
1140 * @test t( "Absolute Path", "/html/body", ["body"] );
1141 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1142 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1143 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1144 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1145 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1146 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1147 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1148 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1149 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1150 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1151 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1153 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1154 * @test t( "First Element", "p:first", ["firstp"] );
1155 * @test t( "Last Element", "p:last", ["first"] );
1156 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1157 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1158 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1159 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1160 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1161 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1162 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1163 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1168 find: function( t, context ) {
1169 // Make sure that the context is a DOM Element
1170 if ( context && context.nodeType == undefined )
1173 // Set the correct context (if none is provided)
1174 context = context || jQuery.context || document;
1176 if ( t.constructor != String ) return [t];
1178 if ( !t.indexOf("//") ) {
1179 context = context.documentElement;
1180 t = t.substr(2,t.length);
1181 } else if ( !t.indexOf("/") ) {
1182 context = context.documentElement;
1183 t = t.substr(1,t.length);
1184 // FIX Assume the root element is right :(
1185 if ( t.indexOf("/") >= 1 )
1186 t = t.substr(t.indexOf("/"),t.length);
1189 var ret = [context];
1193 while ( t.length > 0 && last != t ) {
1197 t = jQuery.trim(t).replace( /^\/\//i, "" );
1199 var foundToken = false;
1201 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1202 if ( foundToken ) continue;
1204 var re = new RegExp("^(" + jQuery.token[i] + ")");
1208 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1209 t = jQuery.trim( t.replace( re, "" ) );
1214 if ( !foundToken ) {
1215 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1216 if ( ret[0] == context ) ret.shift();
1217 done = jQuery.merge( done, ret );
1218 r = ret = [context];
1219 t = " " + t.substr(1,t.length);
1221 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1222 var m = re2.exec(t);
1224 if ( m[1] == "#" ) {
1225 // Ummm, should make this work in all XML docs
1226 var oid = document.getElementById(m[2]);
1227 r = ret = oid ? [oid] : [];
1228 t = t.replace( re2, "" );
1230 if ( !m[2] || m[1] == "." ) m[2] = "*";
1232 for ( var i = 0; i < ret.length; i++ )
1233 r = jQuery.merge( r,
1235 jQuery.getAll(ret[i]) :
1236 ret[i].getElementsByTagName(m[2])
1242 var val = jQuery.filter(t,r);
1244 t = jQuery.trim(val.t);
1249 if ( ret && ret[0] == context ) ret.shift();
1250 done = jQuery.merge( done, ret );
1255 getAll: function(o,r) {
1257 var s = o.childNodes;
1258 for ( var i = 0; i < s.length; i++ )
1259 if ( s[i].nodeType == 1 ) {
1261 jQuery.getAll( s[i], r );
1266 attr: function(elem, name, value){
1269 "class": "className",
1270 "float": "cssFloat",
1271 innerHTML: "innerHTML",
1272 className: "className",
1274 disabled: "disabled"
1278 if ( value != undefined ) elem[fix[name]] = value;
1279 return elem[fix[name]];
1280 } else if ( elem.getAttribute ) {
1281 if ( value != undefined ) elem.setAttribute( name, value );
1282 return elem.getAttribute( name, 2 );
1284 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1285 if ( value != undefined ) elem[name] = value;
1290 // The regular expressions that power the parsing engine
1292 // Match: [@value='test'], [@foo]
1293 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1295 // Match: [div], [div p]
1298 // Match: :contains('foo')
1299 [ "(:)S\\(Q\\)", 0 ],
1301 // Match: :even, :last-chlid
1305 filter: function(t,r,not) {
1306 // Figure out if we're doing regular, or inverse, filtering
1307 var g = not !== false ? jQuery.grep :
1308 function(a,f) {return jQuery.grep(a,f,true);};
1310 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1312 var p = jQuery.parse;
1314 for ( var i = 0; i < p.length; i++ ) {
1315 var re = new RegExp( "^" + p[i][0]
1317 // Look for a string-like sequence
1318 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1320 // Look for something (optionally) enclosed with quotes
1321 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1323 var m = re.exec( t );
1326 // Re-organize the match
1328 m = ["", m[1], m[3], m[2], m[4]];
1330 // Remove what we just matched
1331 t = t.replace( re, "" );
1337 // :not() is a special case that can be optomized by
1338 // keeping it out of the expression list
1339 if ( m[1] == ":" && m[2] == "not" )
1340 r = jQuery.filter(m[3],r,false).r;
1342 // Otherwise, find the expression to execute
1344 var f = jQuery.expr[m[1]];
1345 if ( f.constructor != String )
1346 f = jQuery.expr[m[1]][m[2]];
1348 // Build a custom macro to enclose it
1349 eval("f = function(a,i){" +
1350 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1351 "return " + f + "}");
1353 // Execute it against the current filter
1358 // Return an array of filtered elements (r)
1359 // and the modified expression string (t)
1360 return { r: r, t: t };
1364 * Remove the whitespace from the beginning and end of a string.
1369 * @param String str The string to trim.
1372 return t.replace(/^\s+|\s+$/g, "");
1376 * All ancestors of a given element.
1379 * @name jQuery.parents
1380 * @type Array<Element>
1381 * @param Element elem The element to find the ancestors of.
1383 parents: function( elem ){
1385 var cur = elem.parentNode;
1386 while ( cur && cur != document ) {
1387 matched.push( cur );
1388 cur = cur.parentNode;
1394 * All elements on a specified axis.
1397 * @name jQuery.sibling
1399 * @param Element elem The element to find all the siblings of (including itself).
1401 sibling: function(elem, pos, not) {
1404 var siblings = elem.parentNode.childNodes;
1405 for ( var i = 0; i < siblings.length; i++ ) {
1406 if ( not === true && siblings[i] == elem ) continue;
1408 if ( siblings[i].nodeType == 1 )
1409 elems.push( siblings[i] );
1410 if ( siblings[i] == elem )
1411 elems.n = elems.length - 1;
1414 return jQuery.extend( elems, {
1415 last: elems.n == elems.length - 1,
1416 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1417 prev: elems[elems.n - 1],
1418 next: elems[elems.n + 1]
1423 * Merge two arrays together, removing all duplicates.
1426 * @name jQuery.merge
1428 * @param Array a The first array to merge.
1429 * @param Array b The second array to merge.
1431 merge: function(first, second) {
1434 // Move b over to the new array (this helps to avoid
1435 // StaticNodeList instances)
1436 for ( var k = 0; k < first.length; k++ )
1437 result[k] = first[k];
1439 // Now check for duplicates between a and b and only
1440 // add the unique items
1441 for ( var i = 0; i < second.length; i++ ) {
1442 var noCollision = true;
1444 // The collision-checking process
1445 for ( var j = 0; j < first.length; j++ )
1446 if ( second[i] == first[j] )
1447 noCollision = false;
1449 // If the item is unique, add it
1451 result.push( second[i] );
1458 * Remove items that aren't matched in an array. The function passed
1459 * in to this method will be passed two arguments: 'a' (which is the
1460 * array item) and 'i' (which is the index of the item in the array).
1465 * @param Array array The Array to find items in.
1466 * @param Function fn The function to process each item against.
1467 * @param Boolean inv Invert the selection - select the opposite of the function.
1469 grep: function(elems, fn, inv) {
1470 // If a string is passed in for the function, make a function
1471 // for it (a handy shortcut)
1472 if ( fn.constructor == String )
1473 fn = new Function("a","i","return " + fn);
1477 // Go through the array, only saving the items
1478 // that pass the validator function
1479 for ( var i = 0; i < elems.length; i++ )
1480 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1481 result.push( elems[i] );
1487 * Translate all items in array to another array of items. The translation function
1488 * that is provided to this method is passed one argument: 'a' (the item to be
1489 * translated). If an array is returned, that array is mapped out and merged into
1490 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1491 * from the array. Both of these changes imply that the size of the array may not
1492 * be the same size upon completion, as it was when it started.
1497 * @param Array array The Array to translate.
1498 * @param Function fn The function to process each item against.
1500 map: function(elems, fn) {
1501 // If a string is passed in for the function, make a function
1502 // for it (a handy shortcut)
1503 if ( fn.constructor == String )
1504 fn = new Function("a","return " + fn);
1508 // Go through the array, translating each of the items to their
1509 // new value (or values).
1510 for ( var i = 0; i < elems.length; i++ ) {
1511 var val = fn(elems[i],i);
1513 if ( val !== null && val != undefined ) {
1514 if ( val.constructor != Array ) val = [val];
1515 result = jQuery.merge( result, val );
1523 * A number of helper functions used for managing events.
1524 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1528 // Bind an event to an element
1529 // Original by Dean Edwards
1530 add: function(element, type, handler) {
1531 // For whatever reason, IE has trouble passing the window object
1532 // around, causing it to be cloned in the process
1533 if ( jQuery.browser.msie && element.setInterval != undefined )
1536 // Make sure that the function being executed has a unique ID
1537 if ( !handler.guid )
1538 handler.guid = this.guid++;
1540 // Init the element's event structure
1541 if (!element.events)
1542 element.events = {};
1544 // Get the current list of functions bound to this event
1545 var handlers = element.events[type];
1547 // If it hasn't been initialized yet
1549 // Init the event handler queue
1550 handlers = element.events[type] = {};
1552 // Remember an existing handler, if it's already there
1553 if (element["on" + type])
1554 handlers[0] = element["on" + type];
1557 // Add the function to the element's handler list
1558 handlers[handler.guid] = handler;
1560 // And bind the global event handler to the element
1561 element["on" + type] = this.handle;
1563 // Remember the function in a global list (for triggering)
1564 if (!this.global[type])
1565 this.global[type] = [];
1566 this.global[type].push( element );
1572 // Detach an event or set of events from an element
1573 remove: function(element, type, handler) {
1575 if (type && element.events[type])
1577 delete element.events[type][handler.guid];
1579 for ( var i in element.events[type] )
1580 delete element.events[type][i];
1582 for ( var j in element.events )
1583 this.remove( element, j );
1586 trigger: function(type,data,element) {
1587 // Touch up the incoming data
1590 // Handle a global trigger
1592 var g = this.global[type];
1594 for ( var i = 0; i < g.length; i++ )
1595 this.trigger( type, data, g[i] );
1597 // Handle triggering a single element
1598 } else if ( element["on" + type] ) {
1599 // Pass along a fake event
1600 data.unshift( this.fix({ type: type, target: element }) );
1602 // Trigger the event
1603 element["on" + type].apply( element, data );
1607 handle: function(event) {
1608 if ( typeof jQuery == "undefined" ) return;
1610 event = event || jQuery.event.fix( window.event );
1612 // If no correct event was found, fail
1613 if ( !event ) return;
1615 var returnValue = true;
1617 var c = this.events[event.type];
1619 for ( var j in c ) {
1620 if ( c[j].apply( this, [event] ) === false ) {
1621 event.preventDefault();
1622 event.stopPropagation();
1623 returnValue = false;
1630 fix: function(event) {
1632 event.preventDefault = function() {
1633 this.returnValue = false;
1636 event.stopPropagation = function() {
1637 this.cancelBubble = true;
1648 var b = navigator.userAgent.toLowerCase();
1650 // Figure out what browser is being used
1652 safari: /webkit/.test(b),
1653 opera: /opera/.test(b),
1654 msie: /msie/.test(b) && !/opera/.test(b),
1655 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1658 // Check to see if the W3C box model is being used
1659 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1665 * Append all of the matched elements to another, specified, set of elements.
1666 * This operation is, essentially, the reverse of doing a regular
1667 * $(A).append(B), in that instead of appending B to A, you're appending
1670 * @example $("p").appendTo("#foo");
1671 * @before <p>I would like to say: </p><div id="foo"></div>
1672 * @result <div id="foo"><p>I would like to say: </p></div>
1676 * @param String expr A jQuery expression of elements to match.
1677 * @cat DOM/Manipulation
1682 * Prepend all of the matched elements to another, specified, set of elements.
1683 * This operation is, essentially, the reverse of doing a regular
1684 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1687 * @example $("p").prependTo("#foo");
1688 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1689 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1693 * @param String expr A jQuery expression of elements to match.
1694 * @cat DOM/Manipulation
1696 prependTo: "prepend",
1699 * Insert all of the matched elements before another, specified, set of elements.
1700 * This operation is, essentially, the reverse of doing a regular
1701 * $(A).before(B), in that instead of inserting B before A, you're inserting
1704 * @example $("p").insertBefore("#foo");
1705 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1706 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1708 * @name insertBefore
1710 * @param String expr A jQuery expression of elements to match.
1711 * @cat DOM/Manipulation
1713 insertBefore: "before",
1716 * Insert all of the matched elements after another, specified, set of elements.
1717 * This operation is, essentially, the reverse of doing a regular
1718 * $(A).after(B), in that instead of inserting B after A, you're inserting
1721 * @example $("p").insertAfter("#foo");
1722 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1723 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1727 * @param String expr A jQuery expression of elements to match.
1728 * @cat DOM/Manipulation
1730 insertAfter: "after"
1734 * Get the current CSS width of the first matched element.
1736 * @example $("p").width();
1737 * @before <p>This is just a test.</p>
1746 * Set the CSS width of every matched element. Be sure to include
1747 * the "px" (or other unit of measurement) after the number that you
1748 * specify, otherwise you might get strange results.
1750 * @example $("p").width("20px");
1751 * @before <p>This is just a test.</p>
1752 * @result <p style="width:20px;">This is just a test.</p>
1756 * @param String val Set the CSS property to the specified value.
1761 * Get the current CSS height of the first matched element.
1763 * @example $("p").height();
1764 * @before <p>This is just a test.</p>
1773 * Set the CSS height of every matched element. Be sure to include
1774 * the "px" (or other unit of measurement) after the number that you
1775 * specify, otherwise you might get strange results.
1777 * @example $("p").height("20px");
1778 * @before <p>This is just a test.</p>
1779 * @result <p style="height:20px;">This is just a test.</p>
1783 * @param String val Set the CSS property to the specified value.
1788 * Get the current CSS top of the first matched element.
1790 * @example $("p").top();
1791 * @before <p>This is just a test.</p>
1800 * Set the CSS top of every matched element. Be sure to include
1801 * the "px" (or other unit of measurement) after the number that you
1802 * specify, otherwise you might get strange results.
1804 * @example $("p").top("20px");
1805 * @before <p>This is just a test.</p>
1806 * @result <p style="top:20px;">This is just a test.</p>
1810 * @param String val Set the CSS property to the specified value.
1815 * Get the current CSS left of the first matched element.
1817 * @example $("p").left();
1818 * @before <p>This is just a test.</p>
1827 * Set the CSS left of every matched element. Be sure to include
1828 * the "px" (or other unit of measurement) after the number that you
1829 * specify, otherwise you might get strange results.
1831 * @example $("p").left("20px");
1832 * @before <p>This is just a test.</p>
1833 * @result <p style="left:20px;">This is just a test.</p>
1837 * @param String val Set the CSS property to the specified value.
1842 * Get the current CSS position of the first matched element.
1844 * @example $("p").position();
1845 * @before <p>This is just a test.</p>
1854 * Set the CSS position of every matched element.
1856 * @example $("p").position("relative");
1857 * @before <p>This is just a test.</p>
1858 * @result <p style="position:relative;">This is just a test.</p>
1862 * @param String val Set the CSS property to the specified value.
1867 * Get the current CSS float of the first matched element.
1869 * @example $("p").float();
1870 * @before <p>This is just a test.</p>
1879 * Set the CSS float of every matched element.
1881 * @example $("p").float("left");
1882 * @before <p>This is just a test.</p>
1883 * @result <p style="float:left;">This is just a test.</p>
1887 * @param String val Set the CSS property to the specified value.
1892 * Get the current CSS overflow of the first matched element.
1894 * @example $("p").overflow();
1895 * @before <p>This is just a test.</p>
1904 * Set the CSS overflow of every matched element.
1906 * @example $("p").overflow("auto");
1907 * @before <p>This is just a test.</p>
1908 * @result <p style="overflow:auto;">This is just a test.</p>
1912 * @param String val Set the CSS property to the specified value.
1917 * Get the current CSS color of the first matched element.
1919 * @example $("p").color();
1920 * @before <p>This is just a test.</p>
1929 * Set the CSS color of every matched element.
1931 * @example $("p").color("blue");
1932 * @before <p>This is just a test.</p>
1933 * @result <p style="color:blue;">This is just a test.</p>
1937 * @param String val Set the CSS property to the specified value.
1942 * Get the current CSS background of the first matched element.
1944 * @example $("p").background();
1945 * @before <p>This is just a test.</p>
1954 * Set the CSS background of every matched element.
1956 * @example $("p").background("blue");
1957 * @before <p>This is just a test.</p>
1958 * @result <p style="background:blue;">This is just a test.</p>
1962 * @param String val Set the CSS property to the specified value.
1966 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1968 filter: [ "eq", "lt", "gt", "contains" ],
1972 * Get the current value of the first matched element.
1974 * @example $("input").val();
1975 * @before <input type="text" value="some text"/>
1976 * @result "some text"
1980 * @cat DOM/Attributes
1984 * Set the value of every matched element.
1986 * @example $("input").value("test");
1987 * @before <input type="text" value="some text"/>
1988 * @result <input type="text" value="test"/>
1992 * @param String val Set the property to the specified value.
1993 * @cat DOM/Attributes
1998 * Get the html contents of the first matched element.
2000 * @example $("div").html();
2001 * @before <div><input/></div>
2006 * @cat DOM/Attributes
2010 * Set the html contents of every matched element.
2012 * @example $("div").html("<b>new stuff</b>");
2013 * @before <div><input/></div>
2014 * @result <div><b>new stuff</b></div>
2016 * @test var div = $("div");
2017 * div.html("<b>test</b>");
2019 * for ( var i = 0; i < div.size(); i++ ) {
2020 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2022 * ok( pass, "Set HTML" );
2026 * @param String val Set the html contents to the specified value.
2027 * @cat DOM/Attributes
2032 * Get the current id of the first matched element.
2034 * @example $("input").id();
2035 * @before <input type="text" id="test" value="some text"/>
2040 * @cat DOM/Attributes
2044 * Set the id of every matched element.
2046 * @example $("input").id("newid");
2047 * @before <input type="text" id="test" value="some text"/>
2048 * @result <input type="text" id="newid" value="some text"/>
2052 * @param String val Set the property to the specified value.
2053 * @cat DOM/Attributes
2058 * Get the current title of the first matched element.
2060 * @example $("img").title();
2061 * @before <img src="test.jpg" title="my image"/>
2062 * @result "my image"
2066 * @cat DOM/Attributes
2070 * Set the title of every matched element.
2072 * @example $("img").title("new title");
2073 * @before <img src="test.jpg" title="my image"/>
2074 * @result <img src="test.jpg" title="new image"/>
2078 * @param String val Set the property to the specified value.
2079 * @cat DOM/Attributes
2084 * Get the current name of the first matched element.
2086 * @example $("input").name();
2087 * @before <input type="text" name="username"/>
2088 * @result "username"
2092 * @cat DOM/Attributes
2096 * Set the name of every matched element.
2098 * @example $("input").name("user");
2099 * @before <input type="text" name="username"/>
2100 * @result <input type="text" name="user"/>
2104 * @param String val Set the property to the specified value.
2105 * @cat DOM/Attributes
2110 * Get the current href of the first matched element.
2112 * @example $("a").href();
2113 * @before <a href="test.html">my link</a>
2114 * @result "test.html"
2118 * @cat DOM/Attributes
2122 * Set the href of every matched element.
2124 * @example $("a").href("test2.html");
2125 * @before <a href="test.html">my link</a>
2126 * @result <a href="test2.html">my link</a>
2130 * @param String val Set the property to the specified value.
2131 * @cat DOM/Attributes
2136 * Get the current src of the first matched element.
2138 * @example $("img").src();
2139 * @before <img src="test.jpg" title="my image"/>
2140 * @result "test.jpg"
2144 * @cat DOM/Attributes
2148 * Set the src of every matched element.
2150 * @example $("img").src("test2.jpg");
2151 * @before <img src="test.jpg" title="my image"/>
2152 * @result <img src="test2.jpg" title="my image"/>
2156 * @param String val Set the property to the specified value.
2157 * @cat DOM/Attributes
2162 * Get the current rel of the first matched element.
2164 * @example $("a").rel();
2165 * @before <a href="test.html" rel="nofollow">my link</a>
2166 * @result "nofollow"
2170 * @cat DOM/Attributes
2174 * Set the rel of every matched element.
2176 * @example $("a").rel("nofollow");
2177 * @before <a href="test.html">my link</a>
2178 * @result <a href="test.html" rel="nofollow">my link</a>
2182 * @param String val Set the property to the specified value.
2183 * @cat DOM/Attributes
2190 * Get a set of elements containing the unique parents of the matched
2193 * @example $("p").parent()
2194 * @before <div><p>Hello</p><p>Hello</p></div>
2195 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2199 * @cat DOM/Traversing
2203 * Get a set of elements containing the unique parents of the matched
2204 * set of elements, and filtered by an expression.
2206 * @example $("p").parent(".selected")
2207 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2208 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2212 * @param String expr An expression to filter the parents with
2213 * @cat DOM/Traversing
2215 parent: "a.parentNode",
2218 * Get a set of elements containing the unique ancestors of the matched
2219 * set of elements (except for the root element).
2221 * @example $("span").ancestors()
2222 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2223 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2227 * @cat DOM/Traversing
2231 * Get a set of elements containing the unique ancestors of the matched
2232 * set of elements, and filtered by an expression.
2234 * @example $("span").ancestors("p")
2235 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2236 * @result [ <p><span>Hello</span></p> ]
2240 * @param String expr An expression to filter the ancestors with
2241 * @cat DOM/Traversing
2243 ancestors: jQuery.parents,
2246 * Get a set of elements containing the unique ancestors of the matched
2247 * set of elements (except for the root element).
2249 * @example $("span").ancestors()
2250 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2251 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2255 * @cat DOM/Traversing
2259 * Get a set of elements containing the unique ancestors of the matched
2260 * set of elements, and filtered by an expression.
2262 * @example $("span").ancestors("p")
2263 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2264 * @result [ <p><span>Hello</span></p> ]
2268 * @param String expr An expression to filter the ancestors with
2269 * @cat DOM/Traversing
2271 parents: jQuery.parents,
2274 * Get a set of elements containing the unique next siblings of each of the
2275 * matched set of elements.
2277 * It only returns the very next sibling, not all next siblings.
2279 * @example $("p").next()
2280 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2281 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2285 * @cat DOM/Traversing
2289 * Get a set of elements containing the unique next siblings of each of the
2290 * matched set of elements, and filtered by an expression.
2292 * It only returns the very next sibling, not all next siblings.
2294 * @example $("p").next(".selected")
2295 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2296 * @result [ <p class="selected">Hello Again</p> ]
2300 * @param String expr An expression to filter the next Elements with
2301 * @cat DOM/Traversing
2303 next: "jQuery.sibling(a).next",
2306 * Get a set of elements containing the unique previous siblings of each of the
2307 * matched set of elements.
2309 * It only returns the immediately previous sibling, not all previous siblings.
2311 * @example $("p").previous()
2312 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2313 * @result [ <div><span>Hello Again</span></div> ]
2317 * @cat DOM/Traversing
2321 * Get a set of elements containing the unique previous siblings of each of the
2322 * matched set of elements, and filtered by an expression.
2324 * It only returns the immediately previous sibling, not all previous siblings.
2326 * @example $("p").previous(".selected")
2327 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2328 * @result [ <div><span>Hello</span></div> ]
2332 * @param String expr An expression to filter the previous Elements with
2333 * @cat DOM/Traversing
2335 prev: "jQuery.sibling(a).prev",
2338 * Get a set of elements containing all of the unique siblings of each of the
2339 * matched set of elements.
2341 * @example $("div").siblings()
2342 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2343 * @result [ <p>Hello</p>, <p>And Again</p> ]
2347 * @cat DOM/Traversing
2351 * Get a set of elements containing all of the unique siblings of each of the
2352 * matched set of elements, and filtered by an expression.
2354 * @example $("div").siblings(".selected")
2355 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2356 * @result [ <p class="selected">Hello Again</p> ]
2360 * @param String expr An expression to filter the sibling Elements with
2361 * @cat DOM/Traversing
2363 siblings: jQuery.sibling,
2367 * Get a set of elements containing all of the unique children of each of the
2368 * matched set of elements.
2370 * @example $("div").children()
2371 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2372 * @result [ <span>Hello Again</span> ]
2376 * @cat DOM/Traversing
2380 * Get a set of elements containing all of the unique children of each of the
2381 * matched set of elements, and filtered by an expression.
2383 * @example $("div").children(".selected")
2384 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2385 * @result [ <p class="selected">Hello Again</p> ]
2389 * @param String expr An expression to filter the child Elements with
2390 * @cat DOM/Traversing
2392 children: "jQuery.sibling(a.firstChild)"
2397 removeAttr: function( key ) {
2398 this.removeAttribute( key );
2402 * Displays each of the set of matched elements if they are hidden.
2404 * @example $("p").show()
2405 * @before <p style="display: none">Hello</p>
2406 * @result [ <p style="display: block">Hello</p> ]
2408 * @test var pass = true, div = $("div");
2409 * div.show().each(function(){
2410 * if ( this.style.display == "none" ) pass = false;
2412 * ok( pass, "Show" );
2419 this.style.display = this.oldblock ? this.oldblock : "";
2420 if ( jQuery.css(this,"display") == "none" )
2421 this.style.display = "block";
2425 * Hides each of the set of matched elements if they are shown.
2427 * @example $("p").hide()
2428 * @before <p>Hello</p>
2429 * @result [ <p style="display: none">Hello</p> ]
2431 * var pass = true, div = $("div");
2432 * div.hide().each(function(){
2433 * if ( this.style.display != "none" ) pass = false;
2435 * ok( pass, "Hide" );
2442 this.oldblock = this.oldblock || jQuery.css(this,"display");
2443 if ( this.oldblock == "none" )
2444 this.oldblock = "block";
2445 this.style.display = "none";
2449 * Toggles each of the set of matched elements. If they are shown,
2450 * toggle makes them hidden. If they are hidden, toggle
2453 * @example $("p").toggle()
2454 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2455 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2462 $(this)[ $(this).is(":hidden") ? "show" : "hide" ].apply( $(this), arguments );
2466 * Adds the specified class to each of the set of matched elements.
2468 * @example $("p").addClass("selected")
2469 * @before <p>Hello</p>
2470 * @result [ <p class="selected">Hello</p> ]
2472 * @test var div = $("div");
2473 * div.addClass("test");
2475 * for ( var i = 0; i < div.size(); i++ ) {
2476 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2478 * ok( pass, "Add Class" );
2482 * @param String class A CSS class to add to the elements
2485 addClass: function(c){
2486 jQuery.className.add(this,c);
2490 * Removes the specified class from the set of matched elements.
2492 * @example $("p").removeClass("selected")
2493 * @before <p class="selected">Hello</p>
2494 * @result [ <p>Hello</p> ]
2496 * @test var div = $("div").addClass("test");
2497 * div.removeClass("test");
2499 * for ( var i = 0; i < div.size(); i++ ) {
2500 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2502 * ok( pass, "Remove Class" );
2506 * @param String class A CSS class to remove from the elements
2509 removeClass: function(c){
2510 jQuery.className.remove(this,c);
2514 * Adds the specified class if it is present, removes it if it is
2517 * @example $("p").toggleClass("selected")
2518 * @before <p>Hello</p><p class="selected">Hello Again</p>
2519 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2523 * @param String class A CSS class with which to toggle the elements
2526 toggleClass: function( c ){
2527 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2531 * Removes all matched elements from the DOM. This does NOT remove them from the
2532 * jQuery object, allowing you to use the matched elements further.
2534 * @example $("p").remove();
2535 * @before <p>Hello</p> how are <p>you?</p>
2540 * @cat DOM/Manipulation
2544 * Removes only elements (out of the list of matched elements) that match
2545 * the specified jQuery expression. This does NOT remove them from the
2546 * jQuery object, allowing you to use the matched elements further.
2548 * @example $("p").remove(".hello");
2549 * @before <p class="hello">Hello</p> how are <p>you?</p>
2550 * @result how are <p>you?</p>
2554 * @param String expr A jQuery expression to filter elements by.
2555 * @cat DOM/Manipulation
2557 remove: function(a){
2558 if ( !a || jQuery.filter( a, [this] ).r )
2559 this.parentNode.removeChild( this );
2563 * Removes all child nodes from the set of matched elements.
2565 * @example $("p").empty()
2566 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2567 * @result [ <p></p> ]
2571 * @cat DOM/Manipulation
2574 while ( this.firstChild )
2575 this.removeChild( this.firstChild );
2579 * Binds a particular event (like click) to a each of a set of match elements.
2581 * @example $("p").bind( "click", function() { alert("Hello"); } )
2582 * @before <p>Hello</p>
2583 * @result [ <p>Hello</p> ]
2585 * Cancel a default action and prevent it from bubbling by returning false
2586 * from your function.
2588 * @example $("form").bind( "submit", function() { return false; } )
2590 * Cancel a default action by using the preventDefault method.
2592 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2594 * Stop an event from bubbling by using the stopPropogation method.
2596 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2600 * @param String type An event type
2601 * @param Function fn A function to bind to the event on each of the set of matched elements
2604 bind: function( type, fn ) {
2605 if ( fn.constructor == String )
2606 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2607 jQuery.event.add( this, type, fn );
2611 * The opposite of bind, removes a bound event from each of the matched
2612 * elements. You must pass the identical function that was used in the original
2615 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2616 * @before <p onclick="alert('Hello');">Hello</p>
2617 * @result [ <p>Hello</p> ]
2621 * @param String type An event type
2622 * @param Function fn A function to unbind from the event on each of the set of matched elements
2627 * Removes all bound events of a particular type from each of the matched
2630 * @example $("p").unbind( "click" )
2631 * @before <p onclick="alert('Hello');">Hello</p>
2632 * @result [ <p>Hello</p> ]
2636 * @param String type An event type
2641 * Removes all bound events from each of the matched elements.
2643 * @example $("p").unbind()
2644 * @before <p onclick="alert('Hello');">Hello</p>
2645 * @result [ <p>Hello</p> ]
2651 unbind: function( type, fn ) {
2652 jQuery.event.remove( this, type, fn );
2656 * Trigger a type of event on every matched element.
2658 * @example $("p").trigger("click")
2659 * @before <p click="alert('hello')">Hello</p>
2660 * @result alert('hello')
2664 * @param String type An event type to trigger.
2667 trigger: function( type, data ) {
2668 jQuery.event.trigger( type, data, this );