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 t += r[i].nodeType != 1 ?
382 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
388 * Wrap all matched elements with a structure of other elements.
389 * This wrapping process is most useful for injecting additional
390 * stucture into a document, without ruining the original semantic
391 * qualities of a document.
393 * The way that is works is that it goes through the first element argument
394 * provided and finds the deepest element within the structure - it is that
395 * element that will en-wrap everything else.
397 * @example $("p").wrap("<div class='wrap'></div>");
398 * @before <p>Test Paragraph.</p>
399 * @result <div class='wrap'><p>Test Paragraph.</p></div>
403 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
404 * @any Element elem A DOM element that will be wrapped.
405 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
406 * @any Object obj Any object, converted to a string, then a text node.
407 * @cat DOM/Manipulation
410 // The elements to wrap the target around
411 var a = jQuery.clean(arguments);
413 // Wrap each of the matched elements individually
414 return this.each(function(){
415 // Clone the structure that we're using to wrap
416 var b = a[0].cloneNode(true);
418 // Insert it before the element to be wrapped
419 this.parentNode.insertBefore( b, this );
421 // Find he deepest point in the wrap structure
422 while ( b.firstChild )
425 // Move the matched element to within the wrap structure
426 b.appendChild( this );
431 * Append any number of elements to the inside of all matched elements.
432 * This operation is similar to doing an appendChild to all the
433 * specified elements, adding them into the document.
435 * @example $("p").append("<b>Hello</b>");
436 * @before <p>I would like to say: </p>
437 * @result <p>I would like to say: <b>Hello</b></p>
441 * @any String html A string of HTML, that will be created on the fly and appended to the target.
442 * @any Element elem A DOM element that will be appended.
443 * @any Array<Element> elems An array of elements, all of which will be appended.
444 * @any Object obj Any object, converted to a string, then a text node.
445 * @cat DOM/Manipulation
448 return this.domManip(arguments, true, 1, function(a){
449 this.appendChild( a );
454 * Prepend any number of elements to the inside of all matched elements.
455 * This operation is the best way to insert a set of elements inside, at the
456 * beginning, of all the matched element.
458 * @example $("p").prepend("<b>Hello</b>");
459 * @before <p>, how are you?</p>
460 * @result <p><b>Hello</b>, how are you?</p>
464 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
465 * @any Element elem A DOM element that will be prepended.
466 * @any Array<Element> elems An array of elements, all of which will be prepended.
467 * @any Object obj Any object, converted to a string, then a text node.
468 * @cat DOM/Manipulation
470 prepend: function() {
471 return this.domManip(arguments, true, -1, function(a){
472 this.insertBefore( a, this.firstChild );
477 * Insert any number of elements before each of the matched elements.
479 * @example $("p").before("<b>Hello</b>");
480 * @before <p>how are you?</p>
481 * @result <b>Hello</b><p>how are you?</p>
485 * @any String html A string of HTML, that will be created on the fly and inserted.
486 * @any Element elem A DOM element that will beinserted.
487 * @any Array<Element> elems An array of elements, all of which will be inserted.
488 * @any Object obj Any object, converted to a string, then a text node.
489 * @cat DOM/Manipulation
492 return this.domManip(arguments, false, 1, function(a){
493 this.parentNode.insertBefore( a, this );
498 * Insert any number of elements after each of the matched elements.
500 * @example $("p").after("<p>I'm doing fine.</p>");
501 * @before <p>How are you?</p>
502 * @result <p>How are you?</p><p>I'm doing fine.</p>
506 * @any String html A string of HTML, that will be created on the fly and inserted.
507 * @any Element elem A DOM element that will beinserted.
508 * @any Array<Element> elems An array of elements, all of which will be inserted.
509 * @any Object obj Any object, converted to a string, then a text node.
510 * @cat DOM/Manipulation
513 return this.domManip(arguments, false, -1, function(a){
514 this.parentNode.insertBefore( a, this.nextSibling );
519 * End the most recent 'destructive' operation, reverting the list of matched elements
520 * back to its previous state. After an end operation, the list of matched elements will
521 * revert to the last state of matched elements.
523 * @example $("p").find("span").end();
524 * @before <p><span>Hello</span>, how are you?</p>
525 * @result $("p").find("span").end() == [ <p>...</p> ]
529 * @cat DOM/Traversing
532 return this.get( this.stack.pop() );
536 * Searches for all elements that match the specified expression.
537 * This method is the optimal way of finding additional descendant
538 * elements with which to process.
540 * All searching is done using a jQuery expression. The expression can be
541 * written using CSS 1-3 Selector syntax, or basic XPath.
543 * @example $("p").find("span");
544 * @before <p><span>Hello</span>, how are you?</p>
545 * @result $("p").find("span") == [ <span>Hello</span> ]
549 * @param String expr An expression to search with.
550 * @cat DOM/Traversing
553 return this.pushStack( jQuery.map( this, function(a){
554 return jQuery.find(t,a);
558 clone: function(deep) {
559 return this.pushStack( jQuery.map( this, function(a){
560 return a.cloneNode( deep != undefined ? deep : true );
565 * Removes all elements from the set of matched elements that do not
566 * match the specified expression. This method is used to narrow down
567 * the results of a search.
569 * All searching is done using a jQuery expression. The expression
570 * can be written using CSS 1-3 Selector syntax, or basic XPath.
572 * @example $("p").filter(".selected")
573 * @before <p class="selected">Hello</p><p>How are you?</p>
574 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
578 * @param String expr An expression to search with.
579 * @cat DOM/Traversing
583 * Removes all elements from the set of matched elements that do not
584 * match at least one of the expressions passed to the function. This
585 * method is used when you want to filter the set of matched elements
586 * through more than one expression.
588 * Elements will be retained in the jQuery object if they match at
589 * least one of the expressions passed.
591 * @example $("p").filter([".selected", ":first"])
592 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
593 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
597 * @param Array<String> exprs A set of expressions to evaluate against
598 * @cat DOM/Traversing
600 filter: function(t) {
601 return this.pushStack(
602 t.constructor == Array &&
603 jQuery.map(this,function(a){
604 for ( var i = 0; i < t.length; i++ )
605 if ( jQuery.filter(t[i],[a]).r.length )
609 t.constructor == Boolean &&
610 ( t ? this.get() : [] ) ||
612 t.constructor == Function &&
613 jQuery.grep( this, t ) ||
615 jQuery.filter(t,this).r, arguments );
619 * Removes the specified Element from the set of matched elements. This
620 * method is used to remove a single Element from a jQuery object.
622 * @example $("p").not( document.getElementById("selected") )
623 * @before <p>Hello</p><p id="selected">Hello Again</p>
624 * @result [ <p>Hello</p> ]
628 * @param Element el An element to remove from the set
629 * @cat DOM/Traversing
633 * Removes elements matching the specified expression from the set
634 * of matched elements. This method is used to remove one or more
635 * elements from a jQuery object.
637 * @example $("p").not("#selected")
638 * @before <p>Hello</p><p id="selected">Hello Again</p>
639 * @result [ <p>Hello</p> ]
640 * @test cmpOK($("#main > p#ap > a").not("#google").length, "==", 2, ".not")
644 * @param String expr An expression with which to remove matching elements
645 * @cat DOM/Traversing
648 return this.pushStack( t.constructor == String ?
649 jQuery.filter(t,this,false).r :
650 jQuery.grep(this,function(a){ return a != t; }), arguments );
654 * Adds the elements matched by the expression to the jQuery object. This
655 * can be used to concatenate the result sets of two expressions.
657 * @example $("p").add("span")
658 * @before <p>Hello</p><p><span>Hello Again</span></p>
659 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
663 * @param String expr An expression whose matched elements are added
664 * @cat DOM/Traversing
668 * Adds each of the Elements in the array to the set of matched elements.
669 * This is used to add a set of Elements to a jQuery object.
671 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
672 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
673 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
677 * @param Array<Element> els An array of Elements to add
678 * @cat DOM/Traversing
682 * Adds a single Element to the set of matched elements. This is used to
683 * add a single Element to a jQuery object.
685 * @example $("p").add( document.getElementById("a") )
686 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
687 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
691 * @param Element el An Element to add
692 * @cat DOM/Traversing
695 return this.pushStack( jQuery.merge( this, t.constructor == String ?
696 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
700 * A wrapper function for each() to be used by append and prepend.
701 * Handles cases where you're trying to modify the inner contents of
702 * a table, when you actually need to work with the tbody.
705 * @param {String} expr The expression with which to filter
707 * @cat DOM/Traversing
710 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
719 * @param Boolean table
721 * @param Function fn The function doing the DOM manipulation.
724 domManip: function(args, table, dir, fn){
725 var clone = this.size() > 1;
726 var a = jQuery.clean(args);
728 return this.each(function(){
731 if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
732 var tbody = this.getElementsByTagName("tbody");
734 if ( !tbody.length ) {
735 obj = document.createElement("tbody");
736 this.appendChild( obj );
741 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
742 i != ( dir < 0 ? dir : a.length ); i += dir ) {
743 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
757 pushStack: function(a,args) {
758 var fn = args && args[args.length-1];
760 if ( !fn || fn.constructor != Function ) {
761 if ( !this.stack ) this.stack = [];
762 this.stack.push( this.get() );
765 var old = this.get();
767 if ( fn.constructor == Function )
768 return this.each( fn );
787 * Extend one object with another, returning the original,
788 * modified, object. This is a great utility for simple inheritance.
790 * @name jQuery.extend
791 * @param Object obj The object to extend
792 * @param Object prop The object that will be merged into the first.
796 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
797 if ( !prop ) { prop = obj; obj = this; }
798 for ( var i in prop ) obj[i] = prop[i];
809 jQuery.initDone = true;
811 jQuery.each( jQuery.macros.axis, function(i,n){
812 jQuery.fn[ i ] = function(a) {
813 var ret = jQuery.map(this,n);
814 if ( a && a.constructor == String )
815 ret = jQuery.filter(a,ret).r;
816 return this.pushStack( ret, arguments );
820 jQuery.each( jQuery.macros.to, function(i,n){
821 jQuery.fn[ i ] = function(){
823 return this.each(function(){
824 for ( var j = 0; j < a.length; j++ )
830 jQuery.each( jQuery.macros.each, function(i,n){
831 jQuery.fn[ i ] = function() {
832 return this.each( n, arguments );
836 jQuery.each( jQuery.macros.filter, function(i,n){
837 jQuery.fn[ n ] = function(num,fn) {
838 return this.filter( ":" + n + "(" + num + ")", fn );
842 jQuery.each( jQuery.macros.attr, function(i,n){
844 jQuery.fn[ i ] = function(h) {
845 return h == undefined ?
846 this.length ? this[0][n] : null :
851 jQuery.each( jQuery.macros.css, function(i,n){
852 jQuery.fn[ n ] = function(h) {
853 return h == undefined ?
854 ( this.length ? jQuery.css( this[0], n ) : null ) :
862 * A generic iterator function, which can be used to seemlessly
863 * iterate over both objects and arrays.
866 * @param Object obj The object, or array, to iterate over.
867 * @param Object fn The function that will be executed on every object.
871 each: function( obj, fn, args ) {
872 if ( obj.length == undefined )
874 fn.apply( obj[i], args || [i, obj[i]] );
876 for ( var i = 0; i < obj.length; i++ )
877 fn.apply( obj[i], args || [i, obj[i]] );
883 if (jQuery.className.has(o,c)) return;
884 o.className += ( o.className ? " " : "" ) + c;
886 remove: function(o,c){
887 o.className = !c ? "" :
889 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
892 if ( e.className != undefined )
894 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
899 * Swap in/out style options.
902 swap: function(e,o,f) {
904 e.style["old"+i] = e.style[i];
909 e.style[i] = e.style["old"+i];
913 if ( p == "height" || p == "width" ) {
914 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
917 old["padding" + d[i]] = 0;
918 old["border" + d[i] + "Width"] = 0;
921 jQuery.swap( e, old, function() {
922 if (jQuery.css(e,"display") != "none") {
923 oHeight = e.offsetHeight;
924 oWidth = e.offsetWidth;
926 e = $(e.cloneNode(true)).css({
927 visibility: "hidden", position: "absolute", display: "block"
928 }).prependTo("body")[0];
930 oHeight = e.clientHeight;
931 oWidth = e.clientWidth;
933 e.parentNode.removeChild(e);
937 return p == "height" ? oHeight : oWidth;
938 } else if ( p == "opacity" && jQuery.browser.msie )
939 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
941 return jQuery.curCSS( e, p );
944 curCSS: function(elem, prop, force) {
947 if (!force && elem.style[prop]) {
949 ret = elem.style[prop];
951 } else if (elem.currentStyle) {
953 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
954 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
956 } else if (document.defaultView && document.defaultView.getComputedStyle) {
958 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
959 var cur = document.defaultView.getComputedStyle(elem, null);
962 ret = cur.getPropertyValue(prop);
963 else if ( prop == 'display' )
966 jQuery.swap(elem, { display: 'block' }, function() {
967 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
977 for ( var i = 0; i < a.length; i++ ) {
978 if ( a[i].constructor == String ) {
982 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
984 a[i] = "<table>" + a[i] + "</table>";
985 } else if ( !a[i].indexOf("<tr") ) {
987 a[i] = "<table>" + a[i] + "</table>";
988 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
990 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
993 var div = document.createElement("div");
994 div.innerHTML = a[i];
997 div = div.firstChild;
998 if ( table != "thead" ) div = div.firstChild;
999 if ( table == "td" ) div = div.firstChild;
1002 for ( var j = 0; j < div.childNodes.length; j++ )
1003 r.push( div.childNodes[j] );
1004 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1005 for ( var k = 0; k < a[i].length; k++ )
1007 else if ( a[i] !== null )
1008 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
1014 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1015 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1023 last: "i==r.length-1",
1028 "first-child": "jQuery.sibling(a,0).cur",
1029 "last-child": "jQuery.sibling(a,0).last",
1030 "only-child": "jQuery.sibling(a).length==1",
1033 parent: "a.childNodes.length",
1034 empty: "!a.childNodes.length",
1037 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1040 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1041 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1044 enabled: "!a.disabled",
1045 disabled: "a.disabled",
1046 checked: "a.checked",
1047 selected: "a.selected"
1049 ".": "jQuery.className.has(a,m[2])",
1053 "^=": "!z.indexOf(m[4])",
1054 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1055 "*=": "z.indexOf(m[4])>=0",
1058 "[": "jQuery.find(m[2],a).length"
1062 "\\.\\.|/\\.\\.", "a.parentNode",
1063 ">|/", "jQuery.sibling(a.firstChild)",
1064 "\\+", "jQuery.sibling(a).next",
1067 var s = jQuery.sibling(a);
1069 for ( var i = s.n; i < s.length; i++ )
1077 * @test t( "Element Selector", "div", ["main","foo"] );
1078 * @test t( "Element Selector", "body", ["body"] );
1079 * @test t( "Element Selector", "html", ["html"] );
1080 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1081 * @test t( "Parent Element", "div div", ["foo"] );
1083 * @test t( "ID Selector", "#body", ["body"] );
1084 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1085 * @test t( "ID Selector w/ Element", "ul#first", [] );
1087 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1088 * @test t( "Class Selector", ".blog.link", ["simon"] );
1089 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1090 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1092 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1093 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1094 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1095 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1097 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1098 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
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 w/ Class", "p > a.blog", ["mark","simon"] );
1102 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1103 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1104 * @test t( "Adjacent", "a + a", ["groups"] );
1105 * @test t( "Adjacent", "a +a", ["groups"] );
1106 * @test t( "Adjacent", "a+ a", ["groups"] );
1107 * @test t( "Adjacent", "a+a", ["groups"] );
1108 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1109 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1110 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1111 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1112 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1113 * @test t( "Attribute Exists", "[@title]", ["google"] );
1114 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1115 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1116 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1117 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1118 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1119 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1121 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1122 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1123 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1124 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1125 * @test t( "Last Child", "p:last-child", ["sap"] );
1126 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1127 * @test t( "Empty", "ul:empty", ["firstUL"] );
1128 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1129 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1130 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1131 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1132 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1133 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1134 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1136 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1137 * @test t( "All Div Elements", "//div", ["main","foo"] );
1138 * @test t( "Absolute Path", "/html/body", ["body"] );
1139 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1140 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1141 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1142 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1143 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1144 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1145 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1146 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1147 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1148 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1149 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1151 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1152 * @test t( "First Element", "p:first", ["firstp"] );
1153 * @test t( "Last Element", "p:last", ["first"] );
1154 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1155 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1156 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1157 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1158 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1159 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1160 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1161 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1166 find: function( t, context ) {
1167 // Make sure that the context is a DOM Element
1168 if ( context && context.nodeType == undefined )
1171 // Set the correct context (if none is provided)
1172 context = context || jQuery.context || document;
1174 if ( t.constructor != String ) return [t];
1176 if ( !t.indexOf("//") ) {
1177 context = context.documentElement;
1178 t = t.substr(2,t.length);
1179 } else if ( !t.indexOf("/") ) {
1180 context = context.documentElement;
1181 t = t.substr(1,t.length);
1182 // FIX Assume the root element is right :(
1183 if ( t.indexOf("/") >= 1 )
1184 t = t.substr(t.indexOf("/"),t.length);
1187 var ret = [context];
1191 while ( t.length > 0 && last != t ) {
1195 t = jQuery.trim(t).replace( /^\/\//i, "" );
1197 var foundToken = false;
1199 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1200 var re = new RegExp("^(" + jQuery.token[i] + ")");
1204 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1205 t = jQuery.trim( t.replace( re, "" ) );
1210 if ( !foundToken ) {
1211 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1212 if ( ret[0] == context ) ret.shift();
1213 done = jQuery.merge( done, ret );
1214 r = ret = [context];
1215 t = " " + t.substr(1,t.length);
1217 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1218 var m = re2.exec(t);
1220 if ( m[1] == "#" ) {
1221 // Ummm, should make this work in all XML docs
1222 var oid = document.getElementById(m[2]);
1223 r = ret = oid ? [oid] : [];
1224 t = t.replace( re2, "" );
1226 if ( !m[2] || m[1] == "." ) m[2] = "*";
1228 for ( var i = 0; i < ret.length; i++ )
1229 r = jQuery.merge( r,
1231 jQuery.getAll(ret[i]) :
1232 ret[i].getElementsByTagName(m[2])
1239 var val = jQuery.filter(t,r);
1241 t = jQuery.trim(val.t);
1245 if ( ret && ret[0] == context ) ret.shift();
1246 done = jQuery.merge( done, ret );
1251 getAll: function(o,r) {
1253 var s = o.childNodes;
1254 for ( var i = 0; i < s.length; i++ )
1255 if ( s[i].nodeType == 1 ) {
1257 jQuery.getAll( s[i], r );
1262 attr: function(elem, name, value){
1265 "class": "className",
1266 "float": "cssFloat",
1267 innerHTML: "innerHTML",
1268 className: "className"
1272 if ( value != undefined ) elem[fix[name]] = value;
1273 return elem[fix[name]];
1274 } else if ( elem.getAttribute ) {
1275 if ( value != undefined ) elem.setAttribute( name, value );
1276 return elem.getAttribute( name, 2 );
1278 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1279 if ( value != undefined ) elem[name] = value;
1284 // The regular expressions that power the parsing engine
1286 // Match: [@value='test'], [@foo]
1287 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1289 // Match: [div], [div p]
1292 // Match: :contains('foo')
1293 [ "(:)S\\(Q\\)", 0 ],
1295 // Match: :even, :last-chlid
1299 filter: function(t,r,not) {
1300 // Figure out if we're doing regular, or inverse, filtering
1301 var g = not !== false ? jQuery.grep :
1302 function(a,f) {return jQuery.grep(a,f,true);};
1304 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1306 var p = jQuery.parse;
1308 for ( var i = 0; i < p.length; i++ ) {
1309 var re = new RegExp( "^" + p[i][0]
1311 // Look for a string-like sequence
1312 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1314 // Look for something (optionally) enclosed with quotes
1315 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1317 var m = re.exec( t );
1320 // Re-organize the match
1322 m = ["", m[1], m[3], m[2], m[4]];
1324 // Remove what we just matched
1325 t = t.replace( re, "" );
1331 // :not() is a special case that can be optomized by
1332 // keeping it out of the expression list
1333 if ( m[1] == ":" && m[2] == "not" )
1334 r = jQuery.filter(m[3],r,false).r;
1336 // Otherwise, find the expression to execute
1338 var f = jQuery.expr[m[1]];
1339 if ( f.constructor != String )
1340 f = jQuery.expr[m[1]][m[2]];
1342 // Build a custom macro to enclose it
1343 eval("f = function(a,i){" +
1344 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1345 "return " + f + "}");
1347 // Execute it against the current filter
1352 // Return an array of filtered elements (r)
1353 // and the modified expression string (t)
1354 return { r: r, t: t };
1358 * Remove the whitespace from the beginning and end of a string.
1363 * @param String str The string to trim.
1366 return t.replace(/^\s+|\s+$/g, "");
1370 * All ancestors of a given element.
1373 * @name jQuery.parents
1374 * @type Array<Element>
1375 * @param Element elem The element to find the ancestors of.
1377 parents: function( elem ){
1379 var cur = elem.parentNode;
1380 while ( cur && cur != document ) {
1381 matched.push( cur );
1382 cur = cur.parentNode;
1388 * All elements on a specified axis.
1391 * @name jQuery.sibling
1393 * @param Element elem The element to find all the siblings of (including itself).
1395 sibling: function(elem, pos, not) {
1398 var siblings = elem.parentNode.childNodes;
1399 for ( var i = 0; i < siblings.length; i++ ) {
1400 if ( not === true && siblings[i] == elem ) continue;
1402 if ( siblings[i].nodeType == 1 )
1403 elems.push( siblings[i] );
1404 if ( siblings[i] == elem )
1405 elems.n = elems.length - 1;
1408 return jQuery.extend( elems, {
1409 last: elems.n == elems.length - 1,
1410 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
1411 prev: elems[elems.n - 1],
1412 next: elems[elems.n + 1]
1417 * Merge two arrays together, removing all duplicates.
1420 * @name jQuery.merge
1422 * @param Array a The first array to merge.
1423 * @param Array b The second array to merge.
1425 merge: function(first, second) {
1428 // Move b over to the new array (this helps to avoid
1429 // StaticNodeList instances)
1430 for ( var k = 0; k < first.length; k++ )
1431 result[k] = first[k];
1433 // Now check for duplicates between a and b and only
1434 // add the unique items
1435 for ( var i = 0; i < second.length; i++ ) {
1436 var noCollision = true;
1438 // The collision-checking process
1439 for ( var j = 0; j < first.length; j++ )
1440 if ( second[i] == first[j] )
1441 noCollision = false;
1443 // If the item is unique, add it
1445 result.push( second[i] );
1452 * Remove items that aren't matched in an array. The function passed
1453 * in to this method will be passed two arguments: 'a' (which is the
1454 * array item) and 'i' (which is the index of the item in the array).
1459 * @param Array array The Array to find items in.
1460 * @param Function fn The function to process each item against.
1461 * @param Boolean inv Invert the selection - select the opposite of the function.
1463 grep: function(elems, fn, inv) {
1464 // If a string is passed in for the function, make a function
1465 // for it (a handy shortcut)
1466 if ( fn.constructor == String )
1467 fn = new Function("a","i","return " + fn);
1471 // Go through the array, only saving the items
1472 // that pass the validator function
1473 for ( var i = 0; i < elems.length; i++ )
1474 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1475 result.push( elems[i] );
1481 * Translate all items in array to another array of items. The translation function
1482 * that is provided to this method is passed one argument: 'a' (the item to be
1483 * translated). If an array is returned, that array is mapped out and merged into
1484 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1485 * from the array. Both of these changes imply that the size of the array may not
1486 * be the same size upon completion, as it was when it started.
1491 * @param Array array The Array to translate.
1492 * @param Function fn The function to process each item against.
1494 map: function(elems, fn) {
1495 // If a string is passed in for the function, make a function
1496 // for it (a handy shortcut)
1497 if ( fn.constructor == String )
1498 fn = new Function("a","return " + fn);
1502 // Go through the array, translating each of the items to their
1503 // new value (or values).
1504 for ( var i = 0; i < elems.length; i++ ) {
1505 var val = fn(elems[i],i);
1507 if ( val !== null && val != undefined ) {
1508 if ( val.constructor != Array ) val = [val];
1509 result = jQuery.merge( result, val );
1517 * A number of helper functions used for managing events.
1518 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1522 // Bind an event to an element
1523 // Original by Dean Edwards
1524 add: function(element, type, handler) {
1525 // For whatever reason, IE has trouble passing the window object
1526 // around, causing it to be cloned in the process
1527 if ( jQuery.browser.msie && element.setInterval != undefined )
1530 // Make sure that the function being executed has a unique ID
1531 if ( !handler.guid )
1532 handler.guid = this.guid++;
1534 // Init the element's event structure
1535 if (!element.events)
1536 element.events = {};
1538 // Get the current list of functions bound to this event
1539 var handlers = element.events[type];
1541 // If it hasn't been initialized yet
1543 // Init the event handler queue
1544 handlers = element.events[type] = {};
1546 // Remember an existing handler, if it's already there
1547 if (element["on" + type])
1548 handlers[0] = element["on" + type];
1551 // Add the function to the element's handler list
1552 handlers[handler.guid] = handler;
1554 // And bind the global event handler to the element
1555 element["on" + type] = this.handle;
1557 // Remember the function in a global list (for triggering)
1558 if (!this.global[type])
1559 this.global[type] = [];
1560 this.global[type].push( element );
1566 // Detach an event or set of events from an element
1567 remove: function(element, type, handler) {
1569 if (type && element.events[type])
1571 delete element.events[type][handler.guid];
1573 for ( var i in element.events[type] )
1574 delete element.events[type][i];
1576 for ( var j in element.events )
1577 this.remove( element, j );
1580 trigger: function(type,data,element) {
1581 // Touch up the incoming data
1584 // Handle a global trigger
1586 var g = this.global[type];
1588 for ( var i = 0; i < g.length; i++ )
1589 this.trigger( type, data, g[i] );
1591 // Handle triggering a single element
1592 } else if ( element["on" + type] ) {
1593 // Pass along a fake event
1594 data.unshift( this.fix({ type: type, target: element }) );
1596 // Trigger the event
1597 element["on" + type].apply( element, data );
1601 handle: function(event) {
1602 if ( typeof jQuery == "undefined" ) return;
1604 event = event || jQuery.event.fix( window.event );
1606 // If no correct event was found, fail
1607 if ( !event ) return;
1609 var returnValue = true;
1611 var c = this.events[event.type];
1613 for ( var j in c ) {
1614 if ( c[j].apply( this, [event] ) === false ) {
1615 event.preventDefault();
1616 event.stopPropagation();
1617 returnValue = false;
1624 fix: function(event) {
1626 event.preventDefault = function() {
1627 this.returnValue = false;
1630 event.stopPropagation = function() {
1631 this.cancelBubble = true;
1642 var b = navigator.userAgent.toLowerCase();
1644 // Figure out what browser is being used
1646 safari: /webkit/.test(b),
1647 opera: /opera/.test(b),
1648 msie: /msie/.test(b) && !/opera/.test(b),
1649 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1652 // Check to see if the W3C box model is being used
1653 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1659 * Append all of the matched elements to another, specified, set of elements.
1660 * This operation is, essentially, the reverse of doing a regular
1661 * $(A).append(B), in that instead of appending B to A, you're appending
1664 * @example $("p").appendTo("#foo");
1665 * @before <p>I would like to say: </p><div id="foo"></div>
1666 * @result <div id="foo"><p>I would like to say: </p></div>
1670 * @param String expr A jQuery expression of elements to match.
1671 * @cat DOM/Manipulation
1676 * Prepend all of the matched elements to another, specified, set of elements.
1677 * This operation is, essentially, the reverse of doing a regular
1678 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1681 * @example $("p").prependTo("#foo");
1682 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1683 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1687 * @param String expr A jQuery expression of elements to match.
1688 * @cat DOM/Manipulation
1690 prependTo: "prepend",
1693 * Insert all of the matched elements before another, specified, set of elements.
1694 * This operation is, essentially, the reverse of doing a regular
1695 * $(A).before(B), in that instead of inserting B before A, you're inserting
1698 * @example $("p").insertBefore("#foo");
1699 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1700 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1702 * @name insertBefore
1704 * @param String expr A jQuery expression of elements to match.
1705 * @cat DOM/Manipulation
1707 insertBefore: "before",
1710 * Insert all of the matched elements after another, specified, set of elements.
1711 * This operation is, essentially, the reverse of doing a regular
1712 * $(A).after(B), in that instead of inserting B after A, you're inserting
1715 * @example $("p").insertAfter("#foo");
1716 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1717 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1721 * @param String expr A jQuery expression of elements to match.
1722 * @cat DOM/Manipulation
1724 insertAfter: "after"
1728 * Get the current CSS width of the first matched element.
1730 * @example $("p").width();
1731 * @before <p>This is just a test.</p>
1740 * Set the CSS width of every matched element. Be sure to include
1741 * the "px" (or other unit of measurement) after the number that you
1742 * specify, otherwise you might get strange results.
1744 * @example $("p").width("20px");
1745 * @before <p>This is just a test.</p>
1746 * @result <p style="width:20px;">This is just a test.</p>
1750 * @param String val Set the CSS property to the specified value.
1755 * Get the current CSS height of the first matched element.
1757 * @example $("p").height();
1758 * @before <p>This is just a test.</p>
1767 * Set the CSS height of every matched element. Be sure to include
1768 * the "px" (or other unit of measurement) after the number that you
1769 * specify, otherwise you might get strange results.
1771 * @example $("p").height("20px");
1772 * @before <p>This is just a test.</p>
1773 * @result <p style="height:20px;">This is just a test.</p>
1777 * @param String val Set the CSS property to the specified value.
1782 * Get the current CSS top of the first matched element.
1784 * @example $("p").top();
1785 * @before <p>This is just a test.</p>
1794 * Set the CSS top of every matched element. Be sure to include
1795 * the "px" (or other unit of measurement) after the number that you
1796 * specify, otherwise you might get strange results.
1798 * @example $("p").top("20px");
1799 * @before <p>This is just a test.</p>
1800 * @result <p style="top:20px;">This is just a test.</p>
1804 * @param String val Set the CSS property to the specified value.
1809 * Get the current CSS left of the first matched element.
1811 * @example $("p").left();
1812 * @before <p>This is just a test.</p>
1821 * Set the CSS left of every matched element. Be sure to include
1822 * the "px" (or other unit of measurement) after the number that you
1823 * specify, otherwise you might get strange results.
1825 * @example $("p").left("20px");
1826 * @before <p>This is just a test.</p>
1827 * @result <p style="left:20px;">This is just a test.</p>
1831 * @param String val Set the CSS property to the specified value.
1836 * Get the current CSS position of the first matched element.
1838 * @example $("p").position();
1839 * @before <p>This is just a test.</p>
1848 * Set the CSS position of every matched element.
1850 * @example $("p").position("relative");
1851 * @before <p>This is just a test.</p>
1852 * @result <p style="position:relative;">This is just a test.</p>
1856 * @param String val Set the CSS property to the specified value.
1861 * Get the current CSS float of the first matched element.
1863 * @example $("p").float();
1864 * @before <p>This is just a test.</p>
1873 * Set the CSS float of every matched element.
1875 * @example $("p").float("left");
1876 * @before <p>This is just a test.</p>
1877 * @result <p style="float:left;">This is just a test.</p>
1881 * @param String val Set the CSS property to the specified value.
1886 * Get the current CSS overflow of the first matched element.
1888 * @example $("p").overflow();
1889 * @before <p>This is just a test.</p>
1898 * Set the CSS overflow of every matched element.
1900 * @example $("p").overflow("auto");
1901 * @before <p>This is just a test.</p>
1902 * @result <p style="overflow:auto;">This is just a test.</p>
1906 * @param String val Set the CSS property to the specified value.
1911 * Get the current CSS color of the first matched element.
1913 * @example $("p").color();
1914 * @before <p>This is just a test.</p>
1923 * Set the CSS color of every matched element.
1925 * @example $("p").color("blue");
1926 * @before <p>This is just a test.</p>
1927 * @result <p style="color:blue;">This is just a test.</p>
1931 * @param String val Set the CSS property to the specified value.
1936 * Get the current CSS background of the first matched element.
1938 * @example $("p").background();
1939 * @before <p>This is just a test.</p>
1948 * Set the CSS background of every matched element.
1950 * @example $("p").background("blue");
1951 * @before <p>This is just a test.</p>
1952 * @result <p style="background:blue;">This is just a test.</p>
1956 * @param String val Set the CSS property to the specified value.
1960 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1962 filter: [ "eq", "lt", "gt", "contains" ],
1966 * Get the current value of the first matched element.
1968 * @example $("input").val();
1969 * @before <input type="text" value="some text"/>
1970 * @result "some text"
1974 * @cat DOM/Attributes
1978 * Set the value of every matched element.
1980 * @example $("input").value("test");
1981 * @before <input type="text" value="some text"/>
1982 * @result <input type="text" value="test"/>
1986 * @param String val Set the property to the specified value.
1987 * @cat DOM/Attributes
1992 * Get the html contents of the first matched element.
1994 * @example $("div").html();
1995 * @before <div><input/></div>
2000 * @cat DOM/Attributes
2004 * Set the html contents of every matched element.
2006 * @example $("div").html("<b>new stuff</b>");
2007 * @before <div><input/></div>
2008 * @result <div><b>new stuff</b></div>
2010 * @test var div = $("div");
2011 * div.html("<b>test</b>");
2013 * for ( var i = 0; i < div.size(); i++ ) {
2014 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2016 * ok( pass, "Set HTML" );
2020 * @param String val Set the html contents to the specified value.
2021 * @cat DOM/Attributes
2026 * Get the current id of the first matched element.
2028 * @example $("input").id();
2029 * @before <input type="text" id="test" value="some text"/>
2034 * @cat DOM/Attributes
2038 * Set the id of every matched element.
2040 * @example $("input").id("newid");
2041 * @before <input type="text" id="test" value="some text"/>
2042 * @result <input type="text" id="newid" value="some text"/>
2046 * @param String val Set the property to the specified value.
2047 * @cat DOM/Attributes
2052 * Get the current title of the first matched element.
2054 * @example $("img").title();
2055 * @before <img src="test.jpg" title="my image"/>
2056 * @result "my image"
2060 * @cat DOM/Attributes
2064 * Set the title of every matched element.
2066 * @example $("img").title("new title");
2067 * @before <img src="test.jpg" title="my image"/>
2068 * @result <img src="test.jpg" title="new image"/>
2072 * @param String val Set the property to the specified value.
2073 * @cat DOM/Attributes
2078 * Get the current name of the first matched element.
2080 * @example $("input").name();
2081 * @before <input type="text" name="username"/>
2082 * @result "username"
2086 * @cat DOM/Attributes
2090 * Set the name of every matched element.
2092 * @example $("input").name("user");
2093 * @before <input type="text" name="username"/>
2094 * @result <input type="text" name="user"/>
2098 * @param String val Set the property to the specified value.
2099 * @cat DOM/Attributes
2104 * Get the current href of the first matched element.
2106 * @example $("a").href();
2107 * @before <a href="test.html">my link</a>
2108 * @result "test.html"
2112 * @cat DOM/Attributes
2116 * Set the href of every matched element.
2118 * @example $("a").href("test2.html");
2119 * @before <a href="test.html">my link</a>
2120 * @result <a href="test2.html">my link</a>
2124 * @param String val Set the property to the specified value.
2125 * @cat DOM/Attributes
2130 * Get the current src of the first matched element.
2132 * @example $("img").src();
2133 * @before <img src="test.jpg" title="my image"/>
2134 * @result "test.jpg"
2138 * @cat DOM/Attributes
2142 * Set the src of every matched element.
2144 * @example $("img").src("test2.jpg");
2145 * @before <img src="test.jpg" title="my image"/>
2146 * @result <img src="test2.jpg" title="my image"/>
2150 * @param String val Set the property to the specified value.
2151 * @cat DOM/Attributes
2156 * Get the current rel of the first matched element.
2158 * @example $("a").rel();
2159 * @before <a href="test.html" rel="nofollow">my link</a>
2160 * @result "nofollow"
2164 * @cat DOM/Attributes
2168 * Set the rel of every matched element.
2170 * @example $("a").rel("nofollow");
2171 * @before <a href="test.html">my link</a>
2172 * @result <a href="test.html" rel="nofollow">my link</a>
2176 * @param String val Set the property to the specified value.
2177 * @cat DOM/Attributes
2184 * Get a set of elements containing the unique parents of the matched
2187 * @example $("p").parent()
2188 * @before <div><p>Hello</p><p>Hello</p></div>
2189 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2193 * @cat DOM/Traversing
2197 * Get a set of elements containing the unique parents of the matched
2198 * set of elements, and filtered by an expression.
2200 * @example $("p").parent(".selected")
2201 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2202 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2206 * @param String expr An expression to filter the parents with
2207 * @cat DOM/Traversing
2209 parent: "a.parentNode",
2212 * Get a set of elements containing the unique ancestors of the matched
2213 * set of elements (except for the root element).
2215 * @example $("span").ancestors()
2216 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2217 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2221 * @cat DOM/Traversing
2225 * Get a set of elements containing the unique ancestors of the matched
2226 * set of elements, and filtered by an expression.
2228 * @example $("span").ancestors("p")
2229 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2230 * @result [ <p><span>Hello</span></p> ]
2234 * @param String expr An expression to filter the ancestors with
2235 * @cat DOM/Traversing
2237 ancestors: jQuery.parents,
2240 * Get a set of elements containing the unique ancestors of the matched
2241 * set of elements (except for the root element).
2243 * @example $("span").ancestors()
2244 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2245 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2249 * @cat DOM/Traversing
2253 * Get a set of elements containing the unique ancestors of the matched
2254 * set of elements, and filtered by an expression.
2256 * @example $("span").ancestors("p")
2257 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2258 * @result [ <p><span>Hello</span></p> ]
2262 * @param String expr An expression to filter the ancestors with
2263 * @cat DOM/Traversing
2265 parents: jQuery.parents,
2268 * Get a set of elements containing the unique next siblings of each of the
2269 * matched set of elements.
2271 * It only returns the very next sibling, not all next siblings.
2273 * @example $("p").next()
2274 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2275 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2279 * @cat DOM/Traversing
2283 * Get a set of elements containing the unique next siblings of each of the
2284 * matched set of elements, and filtered by an expression.
2286 * It only returns the very next sibling, not all next siblings.
2288 * @example $("p").next(".selected")
2289 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2290 * @result [ <p class="selected">Hello Again</p> ]
2294 * @param String expr An expression to filter the next Elements with
2295 * @cat DOM/Traversing
2297 next: "jQuery.sibling(a).next",
2300 * Get a set of elements containing the unique previous siblings of each of the
2301 * matched set of elements.
2303 * It only returns the immediately previous sibling, not all previous siblings.
2305 * @example $("p").previous()
2306 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2307 * @result [ <div><span>Hello Again</span></div> ]
2311 * @cat DOM/Traversing
2315 * Get a set of elements containing the unique previous siblings of each of the
2316 * matched set of elements, and filtered by an expression.
2318 * It only returns the immediately previous sibling, not all previous siblings.
2320 * @example $("p").previous(".selected")
2321 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2322 * @result [ <div><span>Hello</span></div> ]
2326 * @param String expr An expression to filter the previous Elements with
2327 * @cat DOM/Traversing
2329 prev: "jQuery.sibling(a).prev",
2332 * Get a set of elements containing all of the unique siblings of each of the
2333 * matched set of elements.
2335 * @example $("div").siblings()
2336 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2337 * @result [ <p>Hello</p>, <p>And Again</p> ]
2341 * @cat DOM/Traversing
2345 * Get a set of elements containing all of the unique siblings of each of the
2346 * matched set of elements, and filtered by an expression.
2348 * @example $("div").siblings(".selected")
2349 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2350 * @result [ <p class="selected">Hello Again</p> ]
2354 * @param String expr An expression to filter the sibling Elements with
2355 * @cat DOM/Traversing
2357 siblings: jQuery.sibling,
2361 * Get a set of elements containing all of the unique children of each of the
2362 * matched set of elements.
2364 * @example $("div").children()
2365 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2366 * @result [ <span>Hello Again</span> ]
2370 * @cat DOM/Traversing
2374 * Get a set of elements containing all of the unique children of each of the
2375 * matched set of elements, and filtered by an expression.
2377 * @example $("div").children(".selected")
2378 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2379 * @result [ <p class="selected">Hello Again</p> ]
2383 * @param String expr An expression to filter the child Elements with
2384 * @cat DOM/Traversing
2386 children: "jQuery.sibling(a.firstChild)"
2391 removeAttr: function( key ) {
2392 this.removeAttribute( key );
2396 * Displays each of the set of matched elements if they are hidden.
2398 * @example $("p").show()
2399 * @before <p style="display: none">Hello</p>
2400 * @result [ <p style="display: block">Hello</p> ]
2402 * @test var pass = true, div = $("div");
2403 * div.show().each(function(){
2404 * if ( this.style.display == "none" ) pass = false;
2406 * ok( pass, "Show" );
2413 this.style.display = this.oldblock ? this.oldblock : "";
2414 if ( jQuery.css(this,"display") == "none" )
2415 this.style.display = "block";
2419 * Hides each of the set of matched elements if they are shown.
2421 * @example $("p").hide()
2422 * @before <p>Hello</p>
2423 * @result [ <p style="display: none">Hello</p> ]
2425 * var pass = true, div = $("div");
2426 * div.hide().each(function(){
2427 * if ( this.style.display != "none" ) pass = false;
2429 * ok( pass, "Hide" );
2436 this.oldblock = this.oldblock || jQuery.css(this,"display");
2437 if ( this.oldblock == "none" )
2438 this.oldblock = "block";
2439 this.style.display = "none";
2443 * Toggles each of the set of matched elements. If they are shown,
2444 * toggle makes them hidden. If they are hidden, toggle
2447 * @example $("p").toggle()
2448 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2449 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2456 $(this)[ $(this).is(":hidden") ? "show" : "hide" ].apply( $(this), arguments );
2460 * Adds the specified class to each of the set of matched elements.
2462 * @example $("p").addClass("selected")
2463 * @before <p>Hello</p>
2464 * @result [ <p class="selected">Hello</p> ]
2466 * @test var div = $("div");
2467 * div.addClass("test");
2469 * for ( var i = 0; i < div.size(); i++ ) {
2470 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2472 * ok( pass, "Add Class" );
2476 * @param String class A CSS class to add to the elements
2479 addClass: function(c){
2480 jQuery.className.add(this,c);
2484 * Removes the specified class from the set of matched elements.
2486 * @example $("p").removeClass("selected")
2487 * @before <p class="selected">Hello</p>
2488 * @result [ <p>Hello</p> ]
2490 * @test var div = $("div").addClass("test");
2491 * div.removeClass("test");
2493 * for ( var i = 0; i < div.size(); i++ ) {
2494 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2496 * ok( pass, "Remove Class" );
2500 * @param String class A CSS class to remove from the elements
2503 removeClass: function(c){
2504 jQuery.className.remove(this,c);
2508 * Adds the specified class if it is present, removes it if it is
2511 * @example $("p").toggleClass("selected")
2512 * @before <p>Hello</p><p class="selected">Hello Again</p>
2513 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2517 * @param String class A CSS class with which to toggle the elements
2520 toggleClass: function( c ){
2521 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2525 * Removes all matched elements from the DOM. This does NOT remove them from the
2526 * jQuery object, allowing you to use the matched elements further.
2528 * @example $("p").remove();
2529 * @before <p>Hello</p> how are <p>you?</p>
2534 * @cat DOM/Manipulation
2538 * Removes only elements (out of the list of matched elements) that match
2539 * the specified jQuery expression. This does NOT remove them from the
2540 * jQuery object, allowing you to use the matched elements further.
2542 * @example $("p").remove(".hello");
2543 * @before <p class="hello">Hello</p> how are <p>you?</p>
2544 * @result how are <p>you?</p>
2548 * @param String expr A jQuery expression to filter elements by.
2549 * @cat DOM/Manipulation
2551 remove: function(a){
2552 if ( !a || jQuery.filter( [this], a ).r )
2553 this.parentNode.removeChild( this );
2557 * Removes all child nodes from the set of matched elements.
2559 * @example $("p").empty()
2560 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2561 * @result [ <p></p> ]
2565 * @cat DOM/Manipulation
2568 while ( this.firstChild )
2569 this.removeChild( this.firstChild );
2573 * Binds a particular event (like click) to a each of a set of match elements.
2575 * @example $("p").bind( "click", function() { alert("Hello"); } )
2576 * @before <p>Hello</p>
2577 * @result [ <p>Hello</p> ]
2579 * Cancel a default action and prevent it from bubbling by returning false
2580 * from your function.
2582 * @example $("form").bind( "submit", function() { return false; } )
2584 * Cancel a default action by using the preventDefault method.
2586 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2588 * Stop an event from bubbling by using the stopPropogation method.
2590 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2594 * @param String type An event type
2595 * @param Function fn A function to bind to the event on each of the set of matched elements
2598 bind: function( type, fn ) {
2599 if ( fn.constructor == String )
2600 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2601 jQuery.event.add( this, type, fn );
2605 * The opposite of bind, removes a bound event from each of the matched
2606 * elements. You must pass the identical function that was used in the original
2609 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2610 * @before <p onclick="alert('Hello');">Hello</p>
2611 * @result [ <p>Hello</p> ]
2615 * @param String type An event type
2616 * @param Function fn A function to unbind from the event on each of the set of matched elements
2621 * Removes all bound events of a particular type from each of the matched
2624 * @example $("p").unbind( "click" )
2625 * @before <p onclick="alert('Hello');">Hello</p>
2626 * @result [ <p>Hello</p> ]
2630 * @param String type An event type
2635 * Removes all bound events from each of the matched elements.
2637 * @example $("p").unbind()
2638 * @before <p onclick="alert('Hello');">Hello</p>
2639 * @result [ <p>Hello</p> ]
2645 unbind: function( type, fn ) {
2646 jQuery.event.remove( this, type, fn );
2650 * Trigger a type of event on every matched element.
2652 * @example $("p").trigger("click")
2653 * @before <p click="alert('hello')">Hello</p>
2654 * @result alert('hello')
2658 * @param String type An event type to trigger.
2661 trigger: function( type, data ) {
2662 jQuery.event.trigger( type, data, this );