2 * jQuery - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Licensed under the MIT License:
6 * http://www.opensource.org/licenses/mit-license.php
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
18 * @test ok( Array.prototype.push, "Array.push()" );
19 * @test ok( Function.prototype.apply, "Function.apply()" );
20 * @test ok( document.getElementById, "getElementById" );
21 * @test ok( document.getElementsByTagName, "getElementsByTagName" );
22 * @test ok( RegExp, "RegExp" );
23 * @test ok( jQuery, "jQuery" );
24 * @test ok( $, "$()" );
30 function jQuery(a,c) {
32 // Initalize the extra macro functions
33 if ( !jQuery.initDone ) jQuery.init();
35 // Shortcut for document ready (because $(document).each() is silly)
36 if ( a && a.constructor == Function && jQuery.fn.ready )
37 return jQuery(document).ready(a);
39 // Make sure t hat a selection was provided
40 a = a || jQuery.context || document;
43 * Handle support for overriding other $() functions. Way too many libraries
44 * provide this function to simply ignore it and overwrite it.
47 // Check to see if this is a possible collision case
48 if ( jQuery._$ && !c && a.constructor == String &&
50 // Make sure that the expression is a colliding one
51 !/[^a-zA-Z0-9_-]/.test(a) &&
53 // and that there are no elements that match it
54 // (this is the one truly ambiguous case)
55 !document.getElementsByTagName(a).length )
57 // Use the default method, in case it works some voodoo
58 return jQuery._$( a );
61 // Watch for when a jQuery object is passed as the selector
65 // Watch for when a jQuery object is passed at the context
67 return jQuery(c.get()).find(a);
69 // If the context is global, return a new object
71 return new jQuery(a,c);
73 // Handle HTML strings
74 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
75 if ( m ) a = jQuery.clean( [ m[1] ] );
77 // Watch for when an array is passed in
78 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
79 // Assume that it is an array of DOM Elements
80 jQuery.merge( a, [] ) :
82 // Find the matching elements and save them for later
83 jQuery.find( a, c ) );
85 var fn = arguments[ arguments.length - 1 ];
86 if ( fn && fn.constructor == Function )
90 // Map over the $ in case of overwrite
94 // Map the jQuery namespace to the '$' one
97 jQuery.fn = jQuery.prototype = {
99 * The current SVN version of jQuery.
110 * The number of elements currently matched.
112 * @example $("img").length;
113 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
116 * @test cmpOK( $("div").length, "==", 2, "Get Number of Elements Found" );
125 * The number of elements currently matched.
127 * @example $("img").size();
128 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
131 * @test cmpOK( $("div").size(), "==", 2, "Get Number of Elements Found" );
142 * Access all matched elements. This serves as a backwards-compatible
143 * way of accessing all matched elements (other than the jQuery object
144 * itself, which is, in fact, an array of elements).
146 * @example $("img").get();
147 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
148 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
150 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
153 * @type Array<Element>
158 * Access a single matched element. num is used to access the
159 * Nth element matched.
161 * @example $("img").get(1);
162 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
163 * @result [ <img src="test1.jpg"/> ]
165 * @test cmpOK( $("div").get(0), "==", document.getElementById("main"), "Get A Single Element" );
169 * @param Number num Access the element in the Nth position.
174 * Set the jQuery object to an array of elements.
176 * @example $("img").get([ document.body ]);
177 * @result $("img").get() == [ document.body ]
182 * @param Elements elems An array of elements
185 get: function( num ) {
186 // Watch for when an array (of elements) is passed in
187 if ( num && num.constructor == Array ) {
189 // Use a tricky hack to make the jQuery object
190 // look and feel like an array
192 [].push.apply( this, num );
196 return num == undefined ?
198 // Return a 'clean' array
199 jQuery.map( this, function(a){ return a } ) :
201 // Return just the object
206 * Execute a function within the context of every matched element.
207 * This means that every time the passed-in function is executed
208 * (which is once for every element matched) the 'this' keyword
209 * points to the specific element.
211 * Additionally, the function, when executed, is passed a single
212 * argument representing the position of the element in the matched
215 * @example $("img").each(function(){ this.src = "test.jpg"; });
216 * @before <img/> <img/>
217 * @result <img src="test.jpg"/> <img src="test.jpg"/>
219 * @test var div = $("div");
220 * div.each(function(){this.foo = 'zoo';});
222 * for ( var i = 0; i < div.size(); i++ ) {
223 * if ( div.get(i).foo != "zoo" ) pass = false;
225 * ok( pass, "Execute a function, Relative" );
229 * @param Function fn A function to execute
232 each: function( fn, args ) {
233 return jQuery.each( this, fn, args );
237 * Access a property on the first matched element.
238 * This method makes it easy to retreive a property value
239 * from the first matched element.
241 * @example $("img").attr("src");
242 * @before <img src="test.jpg"/>
247 * @param String name The name of the property to access.
252 * Set a hash of key/value object properties to all matched elements.
253 * This serves as the best way to set a large number of properties
254 * on all matched elements.
256 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
258 * @result <img src="test.jpg" alt="Test Image"/>
260 * @test var div = $("div");
261 * div.attr({foo: 'baz', zoo: 'ping'});
263 * for ( var i = 0; i < div.size(); i++ ) {
264 * if ( div.get(i).foo != "baz" && div.get(i).zoo != "ping" ) pass = false;
266 * ok( pass, "Set Multiple Attributes" );
270 * @param Hash prop A set of key/value pairs to set as object properties.
275 * Set a single property to a value, on all matched elements.
277 * @example $("img").attr("src","test.jpg");
279 * @result <img src="test.jpg"/>
281 * @test var div = $("div");
282 * div.attr("foo", "bar");
284 * for ( var i = 0; i < div.size(); i++ ) {
285 * if ( div.get(i).foo != "bar" ) pass = false;
287 * ok( pass, "Set Attribute" );
291 * @param String key The name of the property to set.
292 * @param Object value The value to set the property to.
295 attr: function( key, value, type ) {
296 // Check to see if we're setting style values
297 return key.constructor != String || value != undefined ?
298 this.each(function(){
299 // See if we're setting a hash of styles
300 if ( value == undefined )
301 // Set all the styles
302 for ( var prop in key )
304 type ? this.style : this,
308 // See if we're setting a single key/value style
311 type ? this.style : this,
316 // Look for the case where we're accessing a style value
317 jQuery[ type || "attr" ]( this[0], key );
321 * Access a style property on the first matched element.
322 * This method makes it easy to retreive a style property value
323 * from the first matched element.
325 * @example $("p").css("red");
326 * @before <p style="color:red;">Test Paragraph.</p>
331 * @param String name The name of the property to access.
336 * Set a hash of key/value style properties to all matched elements.
337 * This serves as the best way to set a large number of style properties
338 * on all matched elements.
340 * @example $("p").css({ color: "red", background: "blue" });
341 * @before <p>Test Paragraph.</p>
342 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
346 * @param Hash prop A set of key/value pairs to set as style properties.
351 * Set a single style property to a value, on all matched elements.
353 * @example $("p").css("color","red");
354 * @before <p>Test Paragraph.</p>
355 * @result <p style="color:red;">Test Paragraph.</p>
359 * @param String key The name of the property to set.
360 * @param Object value The value to set the property to.
363 css: function( key, value ) {
364 return this.attr( key, value, "curCSS" );
368 * Retreive the text contents of all matched elements. The result is
369 * a string that contains the combined text contents of all matched
370 * elements. This method works on both HTML and XML documents.
372 * @example $("p").text();
373 * @before <p>Test Paragraph.</p>
374 * @result Test Paragraph.
383 for ( var j = 0; j < e.length; j++ ) {
384 var r = e[j].childNodes;
385 for ( var i = 0; i < r.length; i++ )
386 t += r[i].nodeType != 1 ?
387 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
393 * Wrap all matched elements with a structure of other elements.
394 * This wrapping process is most useful for injecting additional
395 * stucture into a document, without ruining the original semantic
396 * qualities of a document.
398 * The way that is works is that it goes through the first element argument
399 * provided and finds the deepest element within the structure - it is that
400 * element that will en-wrap everything else.
402 * @example $("p").wrap("<div class='wrap'></div>");
403 * @before <p>Test Paragraph.</p>
404 * @result <div class='wrap'><p>Test Paragraph.</p></div>
408 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
409 * @any Element elem A DOM element that will be wrapped.
410 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
411 * @any Object obj Any object, converted to a string, then a text node.
412 * @cat DOM/Manipulation
415 // The elements to wrap the target around
416 var a = jQuery.clean(arguments);
418 // Wrap each of the matched elements individually
419 return this.each(function(){
420 // Clone the structure that we're using to wrap
421 var b = a[0].cloneNode(true);
423 // Insert it before the element to be wrapped
424 this.parentNode.insertBefore( b, this );
426 // Find he deepest point in the wrap structure
427 while ( b.firstChild )
430 // Move the matched element to within the wrap structure
431 b.appendChild( this );
436 * Append any number of elements to the inside of all matched elements.
437 * This operation is similar to doing an appendChild to all the
438 * specified elements, adding them into the document.
440 * @example $("p").append("<b>Hello</b>");
441 * @before <p>I would like to say: </p>
442 * @result <p>I would like to say: <b>Hello</b></p>
446 * @any String html A string of HTML, that will be created on the fly and appended to the target.
447 * @any Element elem A DOM element that will be appended.
448 * @any Array<Element> elems An array of elements, all of which will be appended.
449 * @any Object obj Any object, converted to a string, then a text node.
450 * @cat DOM/Manipulation
453 return this.domManip(arguments, true, 1, function(a){
454 this.appendChild( a );
459 * Prepend any number of elements to the inside of all matched elements.
460 * This operation is the best way to insert a set of elements inside, at the
461 * beginning, of all the matched element.
463 * @example $("p").prepend("<b>Hello</b>");
464 * @before <p>, how are you?</p>
465 * @result <p><b>Hello</b>, how are you?</p>
469 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
470 * @any Element elem A DOM element that will be prepended.
471 * @any Array<Element> elems An array of elements, all of which will be prepended.
472 * @any Object obj Any object, converted to a string, then a text node.
473 * @cat DOM/Manipulation
475 prepend: function() {
476 return this.domManip(arguments, true, -1, function(a){
477 this.insertBefore( a, this.firstChild );
482 * Insert any number of elements before each of the matched elements.
484 * @example $("p").before("<b>Hello</b>");
485 * @before <p>how are you?</p>
486 * @result <b>Hello</b><p>how are you?</p>
490 * @any String html A string of HTML, that will be created on the fly and inserted.
491 * @any Element elem A DOM element that will beinserted.
492 * @any Array<Element> elems An array of elements, all of which will be inserted.
493 * @any Object obj Any object, converted to a string, then a text node.
494 * @cat DOM/Manipulation
497 return this.domManip(arguments, false, 1, function(a){
498 this.parentNode.insertBefore( a, this );
503 * Insert any number of elements after each of the matched elements.
505 * @example $("p").after("<p>I'm doing fine.</p>");
506 * @before <p>How are you?</p>
507 * @result <p>How are you?</p><p>I'm doing fine.</p>
511 * @any String html A string of HTML, that will be created on the fly and inserted.
512 * @any Element elem A DOM element that will beinserted.
513 * @any Array<Element> elems An array of elements, all of which will be inserted.
514 * @any Object obj Any object, converted to a string, then a text node.
515 * @cat DOM/Manipulation
518 return this.domManip(arguments, false, -1, function(a){
519 this.parentNode.insertBefore( a, this.nextSibling );
524 * End the most recent 'destructive' operation, reverting the list of matched elements
525 * back to its previous state. After an end operation, the list of matched elements will
526 * revert to the last state of matched elements.
528 * @example $("p").find("span").end();
529 * @before <p><span>Hello</span>, how are you?</p>
530 * @result $("p").find("span").end() == [ <p>...</p> ]
534 * @cat DOM/Traversing
537 return this.get( this.stack.pop() );
541 * Searches for all elements that match the specified expression.
542 * This method is the optimal way of finding additional descendant
543 * elements with which to process.
545 * All searching is done using a jQuery expression. The expression can be
546 * written using CSS 1-3 Selector syntax, or basic XPath.
548 * @example $("p").find("span");
549 * @before <p><span>Hello</span>, how are you?</p>
550 * @result $("p").find("span") == [ <span>Hello</span> ]
554 * @param String expr An expression to search with.
555 * @cat DOM/Traversing
558 return this.pushStack( jQuery.map( this, function(a){
559 return jQuery.find(t,a);
564 * Removes all elements from the set of matched elements that do not
565 * match the specified expression. This method is used to narrow down
566 * the results of a search.
568 * All searching is done using a jQuery expression. The expression
569 * can be written using CSS 1-3 Selector syntax, or basic XPath.
571 * @example $("p").filter(".selected")
572 * @before <p class="selected">Hello</p><p>How are you?</p>
573 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
577 * @param String expr An expression to search with.
578 * @cat DOM/Traversing
582 * Removes all elements from the set of matched elements that do not
583 * match at least one of the expressions passed to the function. This
584 * method is used when you want to filter the set of matched elements
585 * through more than one expression.
587 * Elements will be retained in the jQuery object if they match at
588 * least one of the expressions passed.
590 * @example $("p").filter([".selected", ":first"])
591 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
592 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
596 * @param Array<String> exprs A set of expressions to evaluate against
597 * @cat DOM/Traversing
599 filter: function(t) {
600 return this.pushStack(
601 t.constructor == Array &&
602 jQuery.map(this,function(a){
603 for ( var i = 0; i < t.length; i++ )
604 if ( jQuery.filter(t[i],[a]).r.length )
608 t.constructor == Boolean &&
609 ( t ? this.get() : [] ) ||
611 t.constructor == Function &&
612 jQuery.grep( this, t ) ||
614 jQuery.filter(t,this).r, arguments );
618 * Removes the specified Element from the set of matched elements. This
619 * method is used to remove a single Element from a jQuery object.
621 * @example $("p").not( document.getElementById("selected") )
622 * @before <p>Hello</p><p id="selected">Hello Again</p>
623 * @result [ <p>Hello</p> ]
627 * @param Element el An element to remove from the set
628 * @cat DOM/Traversing
632 * Removes elements matching the specified expression from the set
633 * of matched elements. This method is used to remove one or more
634 * elements from a jQuery object.
636 * @example $("p").not("#selected")
637 * @before <p>Hello</p><p id="selected">Hello Again</p>
638 * @result [ <p>Hello</p> ]
642 * @param String expr An expression with which to remove matching elements
643 * @cat DOM/Traversing
646 return this.pushStack( t.constructor == String ?
647 jQuery.filter(t,this,false).r :
648 jQuery.grep(this,function(a){ return a != t; }), arguments );
652 * Adds the elements matched by the expression to the jQuery object. This
653 * can be used to concatenate the result sets of two expressions.
655 * @example $("p").add("span")
656 * @before <p>Hello</p><p><span>Hello Again</span></p>
657 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
661 * @param String expr An expression whose matched elements are added
662 * @cat DOM/Traversing
666 * Adds each of the Elements in the array to the set of matched elements.
667 * This is used to add a set of Elements to a jQuery object.
669 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
670 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
671 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
675 * @param Array<Element> els An array of Elements to add
680 * Adds a single Element to the set of matched elements. This is used to
681 * add a single Element to a jQuery object.
683 * @example $("p").add( document.getElementById("a") )
684 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
685 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
689 * @param Element el An Element to add
693 return this.pushStack( jQuery.merge( this, t.constructor == String ?
694 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
698 * A wrapper function for each() to be used by append and prepend.
699 * Handles cases where you're trying to modify the inner contents of
700 * a table, when you actually need to work with the tbody.
703 * @param {String} expr The expression with which to filter
708 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
717 * @param Boolean table
719 * @param Function fn The function doing the DOM manipulation.
722 domManip: function(args, table, dir, fn){
723 var clone = this.size() > 1;
724 var a = jQuery.clean(args);
726 return this.each(function(){
729 if ( table && this.nodeName == "TABLE" ) {
730 var tbody = this.getElementsByTagName("tbody");
732 if ( !tbody.length ) {
733 obj = document.createElement("tbody");
734 this.appendChild( obj );
739 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
740 i != ( dir < 0 ? dir : a.length ); i += dir ) {
741 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
755 pushStack: function(a,args) {
756 var fn = args && args[args.length-1];
758 if ( !fn || fn.constructor != Function ) {
759 if ( !this.stack ) this.stack = [];
760 this.stack.push( this.get() );
763 var old = this.get();
765 if ( fn.constructor == Function )
766 return this.each( fn );
785 * Extend one object with another, returning the original,
786 * modified, object. This is a great utility for simple inheritance.
788 * @name jQuery.extend
789 * @param Object obj The object to extend
790 * @param Object prop The object that will be merged into the first.
794 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
795 if ( !prop ) { prop = obj; obj = this; }
796 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[ i ] = 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"), "");
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 jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
928 oHeight = e.clientHeight;
929 oWidth = e.clientWidth;
933 return p == "height" ? oHeight : oWidth;
934 } else if ( p == "opacity" && jQuery.browser.msie )
935 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
937 return jQuery.curCSS( e, p );
940 curCSS: function(e,p,force) {
943 if (!force && e.style[p])
945 else if (e.currentStyle) {
946 p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
947 r = e.currentStyle[p];
948 } else if (document.defaultView && document.defaultView.getComputedStyle) {
949 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
950 var s = document.defaultView.getComputedStyle(e,"");
951 r = s ? s.getPropertyValue(p) : null;
959 for ( var i = 0; i < a.length; i++ ) {
960 if ( a[i].constructor == String ) {
962 if ( !a[i].indexOf("<tr") ) {
964 a[i] = "<table>" + a[i] + "</table>";
965 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
967 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
970 var div = document.createElement("div");
971 div.innerHTML = a[i];
974 div = div.firstChild.firstChild;
975 if ( td ) div = div.firstChild;
978 for ( var j = 0; j < div.childNodes.length; j++ )
979 r.push( div.childNodes[j] );
980 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
981 for ( var k = 0; k < a[i].length; k++ )
983 else if ( a[i] !== null )
984 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
990 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
991 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
999 last: "i==r.length-1",
1004 "first-child": "jQuery.sibling(a,0).cur",
1005 "last-child": "jQuery.sibling(a,0).last",
1006 "only-child": "jQuery.sibling(a).length==1",
1009 parent: "a.childNodes.length",
1010 empty: "!a.childNodes.length",
1013 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
1016 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1017 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1020 enabled: "!a.disabled",
1021 disabled: "a.disabled",
1022 checked: "a.checked"
1024 ".": "jQuery.className.has(a,m[2])",
1028 "^=": "!z.indexOf(m[4])",
1029 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
1030 "*=": "z.indexOf(m[4])>=0",
1033 "[": "jQuery.find(m[2],a).length"
1037 "\\.\\.|/\\.\\.", "a.parentNode",
1038 ">|/", "jQuery.sibling(a.firstChild)",
1039 "\\+", "jQuery.sibling(a).next",
1042 var s = jQuery.sibling(a);
1044 for ( var i = s.n; i < s.length; i++ )
1052 * @test t( "Element Selector", "div", ["main","foo"] );
1053 * @test t( "Element Selector", "body", ["body"] );
1054 * @test t( "Element Selector", "html", ["html"] );
1055 * @test cmpOK( $("*").size(), ">=", 30, "Element Selector" );
1056 * @test t( "Parent Element", "div div", ["foo"] );
1058 * @test t( "ID Selector", "#body", ["body"] );
1059 * @test t( "ID Selector w/ Element", "body#body", ["body"] );
1060 * @test t( "ID Selector w/ Element", "ul#first", [] );
1062 * @test t( "Class Selector", ".blog", ["mark","simon"] );
1063 * @test t( "Class Selector", ".blog.link", ["simon"] );
1064 * @test t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1065 * @test t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1067 * @test t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1068 * @test t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1069 * @test t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1070 * @test t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1072 * @test t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1073 * @test t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1074 * @test t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1075 * @test t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1076 * @test t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1077 * @test t( "All Children", "code > *", ["anchor1","anchor2"] );
1078 * @test t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1079 * @test t( "Adjacent", "a + a", ["groups"] );
1080 * @test t( "Adjacent", "a +a", ["groups"] );
1081 * @test t( "Adjacent", "a+ a", ["groups"] );
1082 * @test t( "Adjacent", "a+a", ["groups"] );
1083 * @test t( "Adjacent", "p + p", ["ap","en","sap"] );
1084 * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1085 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1086 * @test t( "Attribute Exists", "a[@title]", ["google"] );
1087 * @test t( "Attribute Exists", "*[@title]", ["google"] );
1088 * @test t( "Attribute Exists", "[@title]", ["google"] );
1089 * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1090 * @test t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1091 * @test t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1092 * @test t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1093 * @test t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1094 * @test t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1096 * @test t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1097 * @test t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1098 * @test t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1099 * @test t( "First Child", "p:first-child", ["firstp","sndp"] );
1100 * @test t( "Last Child", "p:last-child", ["sap"] );
1101 * @test t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1102 * @test t( "Empty", "ul:empty", ["firstUL"] );
1103 * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
1104 * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
1105 * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1106 * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1107 * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1108 * @test t( "Element Preceded By", "p ~ div", ["foo"] );
1109 * @test t( "Not", "a.blog:not(.link)", ["mark"] );
1111 * @test cmpOK( jQuery.find("//*").length, ">=", 30, "All Elements (//*)" );
1112 * @test t( "All Div Elements", "//div", ["main","foo"] );
1113 * @test t( "Absolute Path", "/html/body", ["body"] );
1114 * @test t( "Absolute Path w/ *", "/* /body", ["body"] );
1115 * @test t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1116 * @test t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1117 * @test t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1118 * @test t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1119 * @test t( "Attribute Exists", "//a[@title]", ["google"] );
1120 * @test t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1121 * @test t( "Parent Axis", "//p/..", ["main","foo"] );
1122 * @test t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1123 * @test t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1124 * @test t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1126 * @test t( "nth Element", "p:nth(1)", ["ap"] );
1127 * @test t( "First Element", "p:first", ["firstp"] );
1128 * @test t( "Last Element", "p:last", ["first"] );
1129 * @test t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1130 * @test t( "Odd Elements", "p:odd", ["ap","en","first"] );
1131 * @test t( "Position Equals", "p:eq(1)", ["ap"] );
1132 * @test t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1133 * @test t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1134 * @test t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1135 * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] );
1136 * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1141 find: function( t, context ) {
1142 // Make sure that the context is a DOM Element
1143 if ( context && context.nodeType == undefined )
1146 // Set the correct context (if none is provided)
1147 context = context || jQuery.context || document;
1149 if ( t.constructor != String ) return [t];
1151 if ( !t.indexOf("//") ) {
1152 context = context.documentElement;
1153 t = t.substr(2,t.length);
1154 } else if ( !t.indexOf("/") ) {
1155 context = context.documentElement;
1156 t = t.substr(1,t.length);
1157 // FIX Assume the root element is right :(
1158 if ( t.indexOf("/") >= 1 )
1159 t = t.substr(t.indexOf("/"),t.length);
1162 var ret = [context];
1166 while ( t.length > 0 && last != t ) {
1170 t = jQuery.trim(t).replace( /^\/\//i, "" );
1172 var foundToken = false;
1174 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1175 var re = new RegExp("^(" + jQuery.token[i] + ")");
1179 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1180 t = jQuery.trim( t.replace( re, "" ) );
1185 if ( !foundToken ) {
1186 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1187 if ( ret[0] == context ) ret.shift();
1188 done = jQuery.merge( done, ret );
1189 r = ret = [context];
1190 t = " " + t.substr(1,t.length);
1192 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1193 var m = re2.exec(t);
1195 if ( m[1] == "#" ) {
1196 // Ummm, should make this work in all XML docs
1197 var oid = document.getElementById(m[2]);
1198 r = ret = oid ? [oid] : [];
1199 t = t.replace( re2, "" );
1201 if ( !m[2] || m[1] == "." ) m[2] = "*";
1203 for ( var i = 0; i < ret.length; i++ )
1204 r = jQuery.merge( r,
1206 jQuery.getAll(ret[i]) :
1207 ret[i].getElementsByTagName(m[2])
1214 var val = jQuery.filter(t,r);
1216 t = jQuery.trim(val.t);
1220 if ( ret && ret[0] == context ) ret.shift();
1221 done = jQuery.merge( done, ret );
1226 getAll: function(o,r) {
1228 var s = o.childNodes;
1229 for ( var i = 0; i < s.length; i++ )
1230 if ( s[i].nodeType == 1 ) {
1232 jQuery.getAll( s[i], r );
1237 attr: function(o,a,v){
1238 if ( a && a.constructor == String ) {
1241 "class": "className",
1245 a = (fix[a] && fix[a].replace && fix[a] || a)
1246 .replace(/-([a-z])/ig,function(z,b){
1247 return b.toUpperCase();
1250 if ( v != undefined ) {
1252 if ( o.setAttribute && a != "disabled" )
1253 o.setAttribute(a,v);
1256 return o[a] || o.getAttribute && o.getAttribute(a) || "";
1261 // The regular expressions that power the parsing engine
1263 // Match: [@value='test'], [@foo]
1264 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1266 // Match: [div], [div p]
1269 // Match: :contains('foo')
1270 [ "(:)S\\(Q\\)", 0 ],
1272 // Match: :even, :last-chlid
1276 filter: function(t,r,not) {
1277 // Figure out if we're doing regular, or inverse, filtering
1278 var g = not !== false ? jQuery.grep :
1279 function(a,f) {return jQuery.grep(a,f,true);};
1281 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1283 var p = jQuery.parse;
1285 for ( var i = 0; i < p.length; i++ ) {
1286 var re = new RegExp( "^" + p[i][0]
1288 // Look for a string-like sequence
1289 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1291 // Look for something (optionally) enclosed with quotes
1292 .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
1294 var m = re.exec( t );
1297 // Re-organize the match
1299 m = ["", m[1], m[3], m[2], m[4]];
1301 // Remove what we just matched
1302 t = t.replace( re, "" );
1308 // :not() is a special case that can be optomized by
1309 // keeping it out of the expression list
1310 if ( m[1] == ":" && m[2] == "not" )
1311 r = jQuery.filter(m[3],r,false).r;
1313 // Otherwise, find the expression to execute
1315 var f = jQuery.expr[m[1]];
1316 if ( f.constructor != String )
1317 f = jQuery.expr[m[1]][m[2]];
1319 // Build a custom macro to enclose it
1320 eval("f = function(a,i){" +
1321 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1322 "return " + f + "}");
1324 // Execute it against the current filter
1329 // Return an array of filtered elements (r)
1330 // and the modified expression string (t)
1331 return { r: r, t: t };
1335 * Remove the whitespace from the beginning and end of a string.
1340 * @param String str The string to trim.
1343 return t.replace(/^\s+|\s+$/g, "");
1347 * All ancestors of a given element.
1350 * @name jQuery.parents
1351 * @type Array<Element>
1352 * @param Element elem The element to find the ancestors of.
1354 parents: function(a){
1356 var c = a.parentNode;
1357 while ( c && c != document ) {
1365 * All elements on a specified axis.
1368 * @name jQuery.sibling
1370 * @param Element elem The element to find all the siblings of (including itself).
1372 sibling: function(a,n) {
1374 var tmp = a.parentNode.childNodes;
1375 for ( var i = 0; i < tmp.length; i++ ) {
1376 if ( tmp[i].nodeType == 1 )
1377 type.push( tmp[i] );
1379 type.n = type.length - 1;
1381 type.last = type.n == type.length - 1;
1383 n == "even" && type.n % 2 == 0 ||
1384 n == "odd" && type.n % 2 ||
1386 type.prev = type[type.n - 1];
1387 type.next = type[type.n + 1];
1392 * Merge two arrays together, removing all duplicates.
1395 * @name jQuery.merge
1397 * @param Array a The first array to merge.
1398 * @param Array b The second array to merge.
1400 merge: function(a,b) {
1403 // Move b over to the new array (this helps to avoid
1404 // StaticNodeList instances)
1405 for ( var k = 0; k < a.length; k++ )
1408 // Now check for duplicates between a and b and only
1409 // add the unique items
1410 for ( var i = 0; i < b.length; i++ ) {
1413 // The collision-checking process
1414 for ( var j = 0; j < a.length; j++ )
1418 // If the item is unique, add it
1427 * Remove items that aren't matched in an array. The function passed
1428 * in to this method will be passed two arguments: 'a' (which is the
1429 * array item) and 'i' (which is the index of the item in the array).
1434 * @param Array array The Array to find items in.
1435 * @param Function fn The function to process each item against.
1436 * @param Boolean inv Invert the selection - select the opposite of the function.
1438 grep: function(a,f,s) {
1439 // If a string is passed in for the function, make a function
1440 // for it (a handy shortcut)
1441 if ( f.constructor == String )
1442 f = new Function("a","i","return " + f);
1446 // Go through the array, only saving the items
1447 // that pass the validator function
1448 for ( var i = 0; i < a.length; i++ )
1449 if ( !s && f(a[i],i) || s && !f(a[i],i) )
1456 * Translate all items in array to another array of items. The translation function
1457 * that is provided to this method is passed one argument: 'a' (the item to be
1458 * translated). If an array is returned, that array is mapped out and merged into
1459 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1460 * from the array. Both of these changes imply that the size of the array may not
1461 * be the same size upon completion, as it was when it started.
1466 * @param Array array The Array to translate.
1467 * @param Function fn The function to process each item against.
1469 map: function(a,f) {
1470 // If a string is passed in for the function, make a function
1471 // for it (a handy shortcut)
1472 if ( f.constructor == String )
1473 f = new Function("a","return " + f);
1477 // Go through the array, translating each of the items to their
1478 // new value (or values).
1479 for ( var i = 0; i < a.length; i++ ) {
1481 if ( t !== null && t != undefined ) {
1482 if ( t.constructor != Array ) t = [t];
1483 r = jQuery.merge( r, t );
1490 * A number of helper functions used for managing events.
1491 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1495 // Bind an event to an element
1496 // Original by Dean Edwards
1497 add: function(element, type, handler) {
1498 // For whatever reason, IE has trouble passing the window object
1499 // around, causing it to be cloned in the process
1500 if ( jQuery.browser.msie && element.setInterval != undefined )
1503 // Make sure that the function being executed has a unique ID
1504 if ( !handler.guid )
1505 handler.guid = this.guid++;
1507 // Init the element's event structure
1508 if (!element.events)
1509 element.events = {};
1511 // Get the current list of functions bound to this event
1512 var handlers = element.events[type];
1514 // If it hasn't been initialized yet
1516 // Init the event handler queue
1517 handlers = element.events[type] = {};
1519 // Remember an existing handler, if it's already there
1520 if (element["on" + type])
1521 handlers[0] = element["on" + type];
1524 // Add the function to the element's handler list
1525 handlers[handler.guid] = handler;
1527 // And bind the global event handler to the element
1528 element["on" + type] = this.handle;
1530 // Remember the function in a global list (for triggering)
1531 if (!this.global[type])
1532 this.global[type] = [];
1533 this.global[type].push( element );
1539 // Detach an event or set of events from an element
1540 remove: function(element, type, handler) {
1542 if (type && element.events[type])
1544 delete element.events[type][handler.guid];
1546 for ( var i in element.events[type] )
1547 delete element.events[type][i];
1549 for ( var j in element.events )
1550 this.remove( element, j );
1553 trigger: function(type,data,element) {
1554 // Touch up the incoming data
1557 // Handle a global trigger
1559 var g = this.global[type];
1561 for ( var i = 0; i < g.length; i++ )
1562 this.trigger( type, data, g[i] );
1564 // Handle triggering a single element
1565 } else if ( element["on" + type] ) {
1566 // Pass along a fake event
1567 data.unshift( this.fix({ type: type, target: element }) );
1569 // Trigger the event
1570 element["on" + type].apply( element, data );
1574 handle: function(event) {
1575 if ( typeof jQuery == "undefined" ) return;
1577 event = event || jQuery.event.fix( window.event );
1579 // If no correct event was found, fail
1580 if ( !event ) return;
1582 var returnValue = true;
1584 var c = this.events[event.type];
1586 for ( var j in c ) {
1587 if ( c[j].apply( this, [event] ) === false ) {
1588 event.preventDefault();
1589 event.stopPropagation();
1590 returnValue = false;
1597 fix: function(event) {
1599 event.preventDefault = function() {
1600 this.returnValue = false;
1603 event.stopPropagation = function() {
1604 this.cancelBubble = true;
1615 var b = navigator.userAgent.toLowerCase();
1617 // Figure out what browser is being used
1619 safari: /webkit/.test(b),
1620 opera: /opera/.test(b),
1621 msie: /msie/.test(b) && !/opera/.test(b),
1622 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1625 // Check to see if the W3C box model is being used
1626 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1632 * Append all of the matched elements to another, specified, set of elements.
1633 * This operation is, essentially, the reverse of doing a regular
1634 * $(A).append(B), in that instead of appending B to A, you're appending
1637 * @example $("p").appendTo("#foo");
1638 * @before <p>I would like to say: </p><div id="foo"></div>
1639 * @result <div id="foo"><p>I would like to say: </p></div>
1643 * @param String expr A jQuery expression of elements to match.
1644 * @cat DOM/Manipulation
1649 * Prepend all of the matched elements to another, specified, set of elements.
1650 * This operation is, essentially, the reverse of doing a regular
1651 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1654 * @example $("p").prependTo("#foo");
1655 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1656 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1660 * @param String expr A jQuery expression of elements to match.
1661 * @cat DOM/Manipulation
1663 prependTo: "prepend",
1666 * Insert all of the matched elements before another, specified, set of elements.
1667 * This operation is, essentially, the reverse of doing a regular
1668 * $(A).before(B), in that instead of inserting B before A, you're inserting
1671 * @example $("p").insertBefore("#foo");
1672 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1673 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1675 * @name insertBefore
1677 * @param String expr A jQuery expression of elements to match.
1678 * @cat DOM/Manipulation
1680 insertBefore: "before",
1683 * Insert all of the matched elements after another, specified, set of elements.
1684 * This operation is, essentially, the reverse of doing a regular
1685 * $(A).after(B), in that instead of inserting B after A, you're inserting
1688 * @example $("p").insertAfter("#foo");
1689 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1690 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1694 * @param String expr A jQuery expression of elements to match.
1695 * @cat DOM/Manipulation
1697 insertAfter: "after"
1701 * Get the current CSS width of the first matched element.
1703 * @example $("p").width();
1704 * @before <p>This is just a test.</p>
1713 * Set the CSS width of every matched element. Be sure to include
1714 * the "px" (or other unit of measurement) after the number that you
1715 * specify, otherwise you might get strange results.
1717 * @example $("p").width("20px");
1718 * @before <p>This is just a test.</p>
1719 * @result <p style="width:20px;">This is just a test.</p>
1723 * @param String val Set the CSS property to the specified value.
1728 * Get the current CSS height of the first matched element.
1730 * @example $("p").height();
1731 * @before <p>This is just a test.</p>
1740 * Set the CSS height 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").height("20px");
1745 * @before <p>This is just a test.</p>
1746 * @result <p style="height:20px;">This is just a test.</p>
1750 * @param String val Set the CSS property to the specified value.
1755 * Get the current CSS top of the first matched element.
1757 * @example $("p").top();
1758 * @before <p>This is just a test.</p>
1767 * Set the CSS top 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").top("20px");
1772 * @before <p>This is just a test.</p>
1773 * @result <p style="top:20px;">This is just a test.</p>
1777 * @param String val Set the CSS property to the specified value.
1782 * Get the current CSS left of the first matched element.
1784 * @example $("p").left();
1785 * @before <p>This is just a test.</p>
1794 * Set the CSS left 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").left("20px");
1799 * @before <p>This is just a test.</p>
1800 * @result <p style="left:20px;">This is just a test.</p>
1804 * @param String val Set the CSS property to the specified value.
1809 * Get the current CSS position of the first matched element.
1811 * @example $("p").position();
1812 * @before <p>This is just a test.</p>
1821 * Set the CSS position of every matched element.
1823 * @example $("p").position("relative");
1824 * @before <p>This is just a test.</p>
1825 * @result <p style="position:relative;">This is just a test.</p>
1829 * @param String val Set the CSS property to the specified value.
1834 * Get the current CSS float of the first matched element.
1836 * @example $("p").float();
1837 * @before <p>This is just a test.</p>
1846 * Set the CSS float of every matched element.
1848 * @example $("p").float("left");
1849 * @before <p>This is just a test.</p>
1850 * @result <p style="float:left;">This is just a test.</p>
1854 * @param String val Set the CSS property to the specified value.
1859 * Get the current CSS overflow of the first matched element.
1861 * @example $("p").overflow();
1862 * @before <p>This is just a test.</p>
1871 * Set the CSS overflow of every matched element.
1873 * @example $("p").overflow("auto");
1874 * @before <p>This is just a test.</p>
1875 * @result <p style="overflow:auto;">This is just a test.</p>
1879 * @param String val Set the CSS property to the specified value.
1884 * Get the current CSS color of the first matched element.
1886 * @example $("p").color();
1887 * @before <p>This is just a test.</p>
1896 * Set the CSS color of every matched element.
1898 * @example $("p").color("blue");
1899 * @before <p>This is just a test.</p>
1900 * @result <p style="color:blue;">This is just a test.</p>
1904 * @param String val Set the CSS property to the specified value.
1909 * Get the current CSS background of the first matched element.
1911 * @example $("p").background();
1912 * @before <p>This is just a test.</p>
1921 * Set the CSS background of every matched element.
1923 * @example $("p").background("blue");
1924 * @before <p>This is just a test.</p>
1925 * @result <p style="background:blue;">This is just a test.</p>
1929 * @param String val Set the CSS property to the specified value.
1933 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1935 filter: [ "eq", "lt", "gt", "contains" ],
1939 * Get the current value of the first matched element.
1941 * @example $("input").val();
1942 * @before <input type="text" value="some text"/>
1943 * @result "some text"
1947 * @cat DOM/Attributes
1951 * Set the value of every matched element.
1953 * @example $("input").value("test");
1954 * @before <input type="text" value="some text"/>
1955 * @result <input type="text" value="test"/>
1959 * @param String val Set the property to the specified value.
1960 * @cat DOM/Attributes
1965 * Get the html contents of the first matched element.
1967 * @example $("div").html();
1968 * @before <div><input/></div>
1973 * @cat DOM/Attributes
1977 * Set the html contents of every matched element.
1979 * @example $("div").html("<b>new stuff</b>");
1980 * @before <div><input/></div>
1981 * @result <div><b>new stuff</b></div>
1983 * @test var div = $("div");
1984 * div.html("<b>test</b>");
1986 * for ( var i = 0; i < div.size(); i++ ) {
1987 * if ( div.get(i).childNodes.length == 0 ) pass = false;
1989 * ok( pass, "Set HTML" );
1993 * @param String val Set the html contents to the specified value.
1994 * @cat DOM/Attributes
1999 * Get the current id of the first matched element.
2001 * @example $("input").id();
2002 * @before <input type="text" id="test" value="some text"/>
2007 * @cat DOM/Attributes
2011 * Set the id of every matched element.
2013 * @example $("input").id("newid");
2014 * @before <input type="text" id="test" value="some text"/>
2015 * @result <input type="text" id="newid" value="some text"/>
2019 * @param String val Set the property to the specified value.
2020 * @cat DOM/Attributes
2025 * Get the current title of the first matched element.
2027 * @example $("img").title();
2028 * @before <img src="test.jpg" title="my image"/>
2029 * @result "my image"
2033 * @cat DOM/Attributes
2037 * Set the title of every matched element.
2039 * @example $("img").title("new title");
2040 * @before <img src="test.jpg" title="my image"/>
2041 * @result <img src="test.jpg" title="new image"/>
2045 * @param String val Set the property to the specified value.
2046 * @cat DOM/Attributes
2051 * Get the current name of the first matched element.
2053 * @example $("input").name();
2054 * @before <input type="text" name="username"/>
2055 * @result "username"
2059 * @cat DOM/Attributes
2063 * Set the name of every matched element.
2065 * @example $("input").name("user");
2066 * @before <input type="text" name="username"/>
2067 * @result <input type="text" name="user"/>
2071 * @param String val Set the property to the specified value.
2072 * @cat DOM/Attributes
2077 * Get the current href of the first matched element.
2079 * @example $("a").href();
2080 * @before <a href="test.html">my link</a>
2081 * @result "test.html"
2085 * @cat DOM/Attributes
2089 * Set the href of every matched element.
2091 * @example $("a").href("test2.html");
2092 * @before <a href="test.html">my link</a>
2093 * @result <a href="test2.html">my link</a>
2097 * @param String val Set the property to the specified value.
2098 * @cat DOM/Attributes
2103 * Get the current src of the first matched element.
2105 * @example $("img").src();
2106 * @before <img src="test.jpg" title="my image"/>
2107 * @result "test.jpg"
2111 * @cat DOM/Attributes
2115 * Set the src of every matched element.
2117 * @example $("img").src("test2.jpg");
2118 * @before <img src="test.jpg" title="my image"/>
2119 * @result <img src="test2.jpg" title="my image"/>
2123 * @param String val Set the property to the specified value.
2124 * @cat DOM/Attributes
2129 * Get the current rel of the first matched element.
2131 * @example $("a").rel();
2132 * @before <a href="test.html" rel="nofollow">my link</a>
2133 * @result "nofollow"
2137 * @cat DOM/Attributes
2141 * Set the rel of every matched element.
2143 * @example $("a").rel("nofollow");
2144 * @before <a href="test.html">my link</a>
2145 * @result <a href="test.html" rel="nofollow">my link</a>
2149 * @param String val Set the property to the specified value.
2150 * @cat DOM/Attributes
2157 * Get a set of elements containing the unique parents of the matched
2160 * @example $("p").parent()
2161 * @before <div><p>Hello</p><p>Hello</p></div>
2162 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2166 * @cat DOM/Traversing
2170 * Get a set of elements containing the unique parents of the matched
2171 * set of elements, and filtered by an expression.
2173 * @example $("p").parent(".selected")
2174 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2175 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2179 * @param String expr An expression to filter the parents with
2180 * @cat DOM/Traversing
2182 parent: "a.parentNode",
2185 * Get a set of elements containing the unique ancestors of the matched
2188 * @example $("span").ancestors()
2189 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2190 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2194 * @cat DOM/Traversing
2198 * Get a set of elements containing the unique ancestors of the matched
2199 * set of elements, and filtered by an expression.
2201 * @example $("span").ancestors("p")
2202 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2203 * @result [ <p><span>Hello</span></p> ]
2207 * @param String expr An expression to filter the ancestors with
2208 * @cat DOM/Traversing
2210 ancestors: jQuery.parents,
2213 * Get a set of elements containing the unique ancestors of the matched
2216 * @example $("span").ancestors()
2217 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2218 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2222 * @cat DOM/Traversing
2226 * Get a set of elements containing the unique ancestors of the matched
2227 * set of elements, and filtered by an expression.
2229 * @example $("span").ancestors("p")
2230 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2231 * @result [ <p><span>Hello</span></p> ]
2235 * @param String expr An expression to filter the ancestors with
2236 * @cat DOM/Traversing
2238 parents: jQuery.parents,
2241 * Get a set of elements containing the unique next siblings of each of the
2242 * matched set of elements.
2244 * It only returns the very next sibling, not all next siblings.
2246 * @example $("p").next()
2247 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2248 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2252 * @cat DOM/Traversing
2256 * Get a set of elements containing the unique next siblings of each of the
2257 * matched set of elements, and filtered by an expression.
2259 * It only returns the very next sibling, not all next siblings.
2261 * @example $("p").next(".selected")
2262 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2263 * @result [ <p class="selected">Hello Again</p> ]
2267 * @param String expr An expression to filter the next Elements with
2268 * @cat DOM/Traversing
2270 next: "jQuery.sibling(a).next",
2273 * Get a set of elements containing the unique previous siblings of each of the
2274 * matched set of elements.
2276 * It only returns the immediately previous sibling, not all previous siblings.
2278 * @example $("p").previous()
2279 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2280 * @result [ <div><span>Hello Again</span></div> ]
2284 * @cat DOM/Traversing
2288 * Get a set of elements containing the unique previous siblings of each of the
2289 * matched set of elements, and filtered by an expression.
2291 * It only returns the immediately previous sibling, not all previous siblings.
2293 * @example $("p").previous(".selected")
2294 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2295 * @result [ <div><span>Hello</span></div> ]
2299 * @param String expr An expression to filter the previous Elements with
2300 * @cat DOM/Traversing
2302 prev: "jQuery.sibling(a).prev",
2305 * Get a set of elements containing all of the unique siblings of each of the
2306 * matched set of elements.
2308 * @example $("div").siblings()
2309 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2310 * @result [ <p>Hello</p>, <p>And Again</p> ]
2314 * @cat DOM/Traversing
2318 * Get a set of elements containing all of the unique siblings of each of the
2319 * matched set of elements, and filtered by an expression.
2321 * @example $("div").siblings(".selected")
2322 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2323 * @result [ <p class="selected">Hello Again</p> ]
2327 * @param String expr An expression to filter the sibling Elements with
2328 * @cat DOM/Traversing
2330 siblings: jQuery.sibling,
2334 * Get a set of elements containing all of the unique children of each of the
2335 * matched set of elements.
2337 * @example $("div").children()
2338 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2339 * @result [ <span>Hello Again</span> ]
2343 * @cat DOM/Traversing
2347 * Get a set of elements containing all of the unique children of each of the
2348 * matched set of elements, and filtered by an expression.
2350 * @example $("div").children(".selected")
2351 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2352 * @result [ <p class="selected">Hello Again</p> ]
2356 * @param String expr An expression to filter the child Elements with
2357 * @cat DOM/Traversing
2359 children: "a.childNodes"
2364 * Displays each of the set of matched elements if they are hidden.
2366 * @example $("p").show()
2367 * @before <p style="display: none">Hello</p>
2368 * @result [ <p style="display: block">Hello</p> ]
2370 * @test var pass = true, div = $("div");
2371 * div.show().each(function(){
2372 * if ( this.style.display == "none" ) pass = false;
2374 * ok( pass, "Show" );
2381 this.style.display = this.oldblock ? this.oldblock : "";
2382 if ( jQuery.css(this,"display") == "none" )
2383 this.style.display = "block";
2387 * Hides each of the set of matched elements if they are shown.
2389 * @example $("p").hide()
2390 * @before <p>Hello</p>
2391 * @result [ <p style="display: none">Hello</p> ]
2393 * var pass = true, div = $("div");
2394 * div.hide().each(function(){
2395 * if ( this.style.display != "none" ) pass = false;
2397 * ok( pass, "Hide" );
2404 this.oldblock = this.oldblock || jQuery.css(this,"display");
2405 if ( this.oldblock == "none" )
2406 this.oldblock = "block";
2407 this.style.display = "none";
2411 * Toggles each of the set of matched elements. If they are shown,
2412 * toggle makes them hidden. If they are hidden, toggle
2415 * @example $("p").toggle()
2416 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2417 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2423 _toggle: function(){
2424 var d = jQuery.css(this,"display");
2425 $(this)[ !d || d == "none" ? "show" : "hide" ]();
2429 * Adds the specified class to each of the set of matched elements.
2431 * @example $("p").addClass("selected")
2432 * @before <p>Hello</p>
2433 * @result [ <p class="selected">Hello</p> ]
2435 * @test var div = $("div");
2436 * div.addClass("test");
2438 * for ( var i = 0; i < div.size(); i++ ) {
2439 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
2441 * ok( pass, "Add Class" );
2445 * @param String class A CSS class to add to the elements
2448 addClass: function(c){
2449 jQuery.className.add(this,c);
2453 * Removes the specified class from the set of matched elements.
2455 * @example $("p").removeClass("selected")
2456 * @before <p class="selected">Hello</p>
2457 * @result [ <p>Hello</p> ]
2459 * @test var div = $("div").addClass("test");
2460 * div.removeClass("test");
2462 * for ( var i = 0; i < div.size(); i++ ) {
2463 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
2465 * ok( pass, "Remove Class" );
2469 * @param String class A CSS class to remove from the elements
2472 removeClass: function(c){
2473 jQuery.className.remove(this,c);
2477 * Adds the specified class if it is present, removes it if it is
2480 * @example $("p").toggleClass("selected")
2481 * @before <p>Hello</p><p class="selected">Hello Again</p>
2482 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2486 * @param String class A CSS class with which to toggle the elements
2489 toggleClass: function( c ){
2490 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2494 * Removes all matched elements from the DOM. This does NOT remove them from the
2495 * jQuery object, allowing you to use the matched elements further.
2497 * @example $("p").remove();
2498 * @before <p>Hello</p> how are <p>you?</p>
2503 * @cat DOM/Manipulation
2507 * Removes only elements (out of the list of matched elements) that match
2508 * the specified jQuery expression. This does NOT remove them from the
2509 * jQuery object, allowing you to use the matched elements further.
2511 * @example $("p").remove(".hello");
2512 * @before <p class="hello">Hello</p> how are <p>you?</p>
2513 * @result how are <p>you?</p>
2517 * @param String expr A jQuery expression to filter elements by.
2518 * @cat DOM/Manipulation
2520 remove: function(a){
2521 if ( !a || jQuery.filter( [this], a ).r )
2522 this.parentNode.removeChild( this );
2526 * Removes all child nodes from the set of matched elements.
2528 * @example $("p").empty()
2529 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2530 * @result [ <p></p> ]
2534 * @cat DOM/Manipulation
2537 while ( this.firstChild )
2538 this.removeChild( this.firstChild );
2542 * Binds a particular event (like click) to a each of a set of match elements.
2544 * @example $("p").bind( "click", function() { alert("Hello"); } )
2545 * @before <p>Hello</p>
2546 * @result [ <p>Hello</p> ]
2548 * Cancel a default action and prevent it from bubbling by returning false
2549 * from your function.
2551 * @example $("form").bind( "submit", function() { return false; } )
2553 * Cancel a default action by using the preventDefault method.
2555 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2557 * Stop an event from bubbling by using the stopPropogation method.
2559 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2563 * @param String type An event type
2564 * @param Function fn A function to bind to the event on each of the set of matched elements
2567 bind: function( type, fn ) {
2568 if ( fn.constructor == String )
2569 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2570 jQuery.event.add( this, type, fn );
2574 * The opposite of bind, removes a bound event from each of the matched
2575 * elements. You must pass the identical function that was used in the original
2578 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2579 * @before <p onclick="alert('Hello');">Hello</p>
2580 * @result [ <p>Hello</p> ]
2584 * @param String type An event type
2585 * @param Function fn A function to unbind from the event on each of the set of matched elements
2590 * Removes all bound events of a particular type from each of the matched
2593 * @example $("p").unbind( "click" )
2594 * @before <p onclick="alert('Hello');">Hello</p>
2595 * @result [ <p>Hello</p> ]
2599 * @param String type An event type
2604 * Removes all bound events from each of the matched elements.
2606 * @example $("p").unbind()
2607 * @before <p onclick="alert('Hello');">Hello</p>
2608 * @result [ <p>Hello</p> ]
2614 unbind: function( type, fn ) {
2615 jQuery.event.remove( this, type, fn );
2619 * Trigger a type of event on every matched element.
2621 * @example $("p").trigger("click")
2622 * @before <p click="alert('hello')">Hello</p>
2623 * @result alert('hello')
2627 * @param String type An event type to trigger.
2630 trigger: function( type, data ) {
2631 jQuery.event.trigger( type, data, this );