2 * jQuery @VERSION - 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
23 var jQuery = function(a,c) {
25 // Shortcut for document ready
26 if ( a && typeof a == "function" && jQuery.fn.ready && !a.nodeType && a[0] == undefined ) // Safari reports typeof on DOM NodeLists as a function
27 return jQuery(document).ready(a);
29 // Make sure that a selection was provided
32 // Watch for when a jQuery object is passed as the selector
34 return jQuery( jQuery.makeArray( a ) );
36 // Watch for when a jQuery object is passed at the context
38 return jQuery( c ).find(a);
40 // If the context is global, return a new object
42 return new jQuery(a,c);
44 // Handle HTML strings
45 if ( typeof a == "string" ) {
46 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
47 if ( m ) a = jQuery.clean( [ m[1] ] );
50 // Watch for when an array is passed in
51 this.set( a.constructor == Array || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType ?
52 // Assume that it is an array of DOM Elements
53 jQuery.makeArray( a ) :
55 // Find the matching elements and save them for later
56 jQuery.find( a, c ) );
58 // See if an extra function was provided
59 var fn = arguments[ arguments.length - 1 ];
61 // If so, execute it in context
62 if ( fn && typeof fn == "function" )
68 // Map over the $ in case of overwrite
69 if ( typeof $ != "undefined" )
72 // Map the jQuery namespace to the '$' one
76 * This function accepts a string containing a CSS or
77 * basic XPath selector which is then used to match a set of elements.
79 * The core functionality of jQuery centers around this function.
80 * Everything in jQuery is based upon this, or uses this in some way.
81 * The most basic use of this function is to pass in an expression
82 * (usually consisting of CSS or XPath), which then finds all matching
85 * By default, $() looks for DOM elements within the context of the
86 * current HTML document.
88 * @example $("div > p")
89 * @desc This finds all p elements that are children of a div element.
90 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
91 * @result [ <p>two</p> ]
93 * @example $("input:radio", document.forms[0])
94 * @desc Searches for all inputs of type radio within the first form in the document
96 * @example $("div", xml.responseXML)
97 * @desc This finds all div elements within the specified XML document.
100 * @param String expr An expression to search with
101 * @param Element context (optional) A DOM Element, or Document, representing the base context.
105 * @see $(Element<Array>)
109 * This function accepts a string of raw HTML.
111 * The HTML string is different from the traditional selectors in that
112 * it creates the DOM elements representing that HTML string, on the fly,
113 * to be (assumedly) inserted into the document later.
115 * @example $("<div><p>Hello</p></div>").appendTo("#body")
116 * @desc Creates a div element (and all of its contents) dynamically,
117 * and appends it to the element with the ID of body. Internally, an
118 * element is created and it's innerHTML property set to the given markup.
119 * It is therefore both quite flexible and limited.
122 * @param String html A string of HTML to create on the fly.
128 * Wrap jQuery functionality around a specific DOM Element.
129 * This function also accepts XML Documents and Window objects
130 * as valid arguments (even though they are not DOM Elements).
132 * @example $(document).find("div > p")
133 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
134 * @result [ <p>two</p> ]
136 * @example $(document.body).background( "black" );
137 * @desc Sets the background color of the page to black.
140 * @param Element elem A DOM element to be encapsulated by a jQuery object.
146 * Wrap jQuery functionality around a set of DOM Elements.
148 * @example $( myForm.elements ).hide()
149 * @desc Hides all the input elements within a form
152 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
158 * A shorthand for $(document).ready(), allowing you to bind a function
159 * to be executed when the DOM document has finished loading. This function
160 * behaves just like $(document).ready(), in that it should be used to wrap
161 * all of the other $() operations on your page. While this function is,
162 * technically, chainable - there really isn't much use for chaining against it.
163 * You can have as many $(document).ready events on your page as you like.
165 * See ready(Function) for details about the ready event.
167 * @example $(function(){
168 * // Document is ready
170 * @desc Executes the function when the DOM is ready to be used.
173 * @param Function fn The function to execute when the DOM is ready.
179 * A means of creating a cloned copy of a jQuery object. This function
180 * copies the set of matched elements from one jQuery object and creates
181 * another, new, jQuery object containing the same elements.
183 * @example var div = $("div");
184 * $( div ).find("p");
185 * @desc Locates all p elements with all div elements, without disrupting the original jQuery object contained in 'div' (as would normally be the case if a simple div.find("p") was done).
188 * @param jQuery obj The jQuery object to be cloned.
193 jQuery.fn = jQuery.prototype = {
195 * The current version of jQuery.
206 * The number of elements currently matched.
208 * @example $("img").length;
209 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
219 * The number of elements currently matched.
221 * @example $("img").size();
222 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
234 * Access all matched elements. This serves as a backwards-compatible
235 * way of accessing all matched elements (other than the jQuery object
236 * itself, which is, in fact, an array of elements).
238 * @example $("img").get();
239 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
240 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
243 * @type Array<Element>
248 * Access a single matched element. num is used to access the
249 * Nth element matched.
251 * @example $("img").get(1);
252 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
253 * @result [ <img src="test1.jpg"/> ]
257 * @param Number num Access the element in the Nth position.
260 get: function( num ) {
261 return num == undefined ?
263 // Return a 'clean' array
264 jQuery.makeArray( this ) :
266 // Return just the object
271 * Set the jQuery object to an array of elements.
273 * @example $("img").set([ document.body ]);
274 * @result $("img").set() == [ document.body ]
279 * @param Elements elems An array of elements
282 set: function( array ) {
283 // Use a tricky hack to make the jQuery object
284 // look and feel like an array
286 [].push.apply( this, array );
291 * Execute a function within the context of every matched element.
292 * This means that every time the passed-in function is executed
293 * (which is once for every element matched) the 'this' keyword
294 * points to the specific element.
296 * Additionally, the function, when executed, is passed a single
297 * argument representing the position of the element in the matched
300 * @example $("img").each(function(i){
301 * this.src = "test" + i + ".jpg";
303 * @before <img/> <img/>
304 * @result <img src="test0.jpg"/> <img src="test1.jpg"/>
305 * @desc Iterates over two images and sets their src property
309 * @param Function fn A function to execute
312 each: function( fn, args ) {
313 return jQuery.each( this, fn, args );
317 * Searches every matched element for the object and returns
318 * the index of the element, if found, starting with zero.
319 * Returns -1 if the object wasn't found.
321 * @example $("*").index(document.getElementById('foobar'))
322 * @before <div id="foobar"></div><b></b><span id="foo"></span>
325 * @example $("*").index(document.getElementById('foo'))
326 * @before <div id="foobar"></div><b></b><span id="foo"></span>
329 * @example $("*").index(document.getElementById('bar'))
330 * @before <div id="foobar"></div><b></b><span id="foo"></span>
335 * @param Object obj Object to search for
338 index: function( obj ) {
340 this.each(function(i){
341 if ( this == obj ) pos = i;
347 * Access a property on the first matched element.
348 * This method makes it easy to retrieve a property value
349 * from the first matched element.
351 * @example $("img").attr("src");
352 * @before <img src="test.jpg"/>
357 * @param String name The name of the property to access.
362 * Set a hash of key/value object properties to all matched elements.
363 * This serves as the best way to set a large number of properties
364 * on all matched elements.
366 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
368 * @result <img src="test.jpg" alt="Test Image"/>
372 * @param Hash prop A set of key/value pairs to set as object properties.
377 * Set a single property to a value, on all matched elements.
379 * Note that you can't set the name property of input elements in IE.
380 * Use $(html) or $().append(html) or $().html(html) to create elements
381 * on the fly including the name property.
383 * @example $("img").attr("src","test.jpg");
385 * @result <img src="test.jpg"/>
389 * @param String key The name of the property to set.
390 * @param Object value The value to set the property to.
393 attr: function( key, value, type ) {
394 // Check to see if we're setting style values
395 return typeof key != "string" || value != undefined ?
396 this.each(function(){
397 // See if we're setting a hash of styles
398 if ( value == undefined )
399 // Set all the styles
400 for ( var prop in key )
402 type ? this.style : this,
406 // See if we're setting a single key/value style
409 type ? this.style : this,
414 // Look for the case where we're accessing a style value
415 jQuery[ type || "attr" ]( this[0], key );
419 * Access a style property on the first matched element.
420 * This method makes it easy to retrieve a style property value
421 * from the first matched element.
423 * @example $("p").css("color");
424 * @before <p style="color:red;">Test Paragraph.</p>
426 * @desc Retrieves the color style of the first paragraph
428 * @example $("p").css("fontWeight");
429 * @before <p style="font-weight: bold;">Test Paragraph.</p>
431 * @desc Retrieves the font-weight style of the first paragraph.
432 * Note that for all style properties with a dash (like 'font-weight'), you have to
433 * write it in camelCase. In other words: Every time you have a '-' in a
434 * property, remove it and replace the next character with an uppercase
435 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
436 * borderStyle, borderBottomWidth etc.
440 * @param String name The name of the property to access.
445 * Set a hash of key/value style properties to all matched elements.
446 * This serves as the best way to set a large number of style properties
447 * on all matched elements.
449 * @example $("p").css({ color: "red", background: "blue" });
450 * @before <p>Test Paragraph.</p>
451 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
455 * @param Hash prop A set of key/value pairs to set as style properties.
460 * Set a single style property to a value, on all matched elements.
462 * @example $("p").css("color","red");
463 * @before <p>Test Paragraph.</p>
464 * @result <p style="color:red;">Test Paragraph.</p>
465 * @desc Changes the color of all paragraphs to red
469 * @param String key The name of the property to set.
470 * @param Object value The value to set the property to.
473 css: function( key, value ) {
474 return this.attr( key, value, "curCSS" );
478 * Retrieve the text contents of all matched elements. The result is
479 * a string that contains the combined text contents of all matched
480 * elements. This method works on both HTML and XML documents.
482 * @example $("p").text();
483 * @before <p>Test Paragraph.</p>
484 * @result Test Paragraph.
492 * Set the text contents of all matched elements. This has the same
493 * effect as calling .html() with your specified string.
495 * @example $("p").text("Some new text.");
496 * @before <p>Test Paragraph.</p>
497 * @result <p>Some new text.</p>
499 * @param String val The text value to set the contents of the element to.
506 // A surprisingly high number of people expect the
507 // .text() method to do this, so lets do it!
508 if ( typeof e == "string" )
509 return this.html( e );
513 for ( var j = 0; j < e.length; j++ ) {
514 var r = e[j].childNodes;
515 for ( var i = 0; i < r.length; i++ )
516 if ( r[i].nodeType != 8 )
517 t += r[i].nodeType != 1 ?
518 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
524 * Wrap all matched elements with a structure of other elements.
525 * This wrapping process is most useful for injecting additional
526 * stucture into a document, without ruining the original semantic
527 * qualities of a document.
529 * This works by going through the first element
530 * provided (which is generated, on the fly, from the provided HTML)
531 * and finds the deepest ancestor element within its
532 * structure - it is that element that will en-wrap everything else.
534 * This does not work with elements that contain text. Any necessary text
535 * must be added after the wrapping is done.
537 * @example $("p").wrap("<div class='wrap'></div>");
538 * @before <p>Test Paragraph.</p>
539 * @result <div class='wrap'><p>Test Paragraph.</p></div>
543 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
544 * @cat DOM/Manipulation
548 * Wrap all matched elements with a structure of other elements.
549 * This wrapping process is most useful for injecting additional
550 * stucture into a document, without ruining the original semantic
551 * qualities of a document.
553 * This works by going through the first element
554 * provided and finding the deepest ancestor element within its
555 * structure - it is that element that will en-wrap everything else.
557 * This does not work with elements that contain text. Any necessary text
558 * must be added after the wrapping is done.
560 * @example $("p").wrap( document.getElementById('content') );
561 * @before <p>Test Paragraph.</p><div id="content"></div>
562 * @result <div id="content"><p>Test Paragraph.</p></div>
566 * @param Element elem A DOM element that will be wrapped.
567 * @cat DOM/Manipulation
570 // The elements to wrap the target around
571 var a = jQuery.clean(arguments);
573 // Wrap each of the matched elements individually
574 return this.each(function(){
575 // Clone the structure that we're using to wrap
576 var b = a[0].cloneNode(true);
578 // Insert it before the element to be wrapped
579 this.parentNode.insertBefore( b, this );
581 // Find the deepest point in the wrap structure
582 while ( b.firstChild )
585 // Move the matched element to within the wrap structure
586 b.appendChild( this );
591 * Append any number of elements to the inside of every matched elements,
592 * generated from the provided HTML.
593 * This operation is similar to doing an appendChild to all the
594 * specified elements, adding them into the document.
596 * @example $("p").append("<b>Hello</b>");
597 * @before <p>I would like to say: </p>
598 * @result <p>I would like to say: <b>Hello</b></p>
602 * @param String html A string of HTML, that will be created on the fly and appended to the target.
603 * @cat DOM/Manipulation
607 * Append an element to the inside of all matched elements.
608 * This operation is similar to doing an appendChild to all the
609 * specified elements, adding them into the document.
611 * @example $("p").append( $("#foo")[0] );
612 * @before <p>I would like to say: </p><b id="foo">Hello</b>
613 * @result <p>I would like to say: <b id="foo">Hello</b></p>
617 * @param Element elem A DOM element that will be appended.
618 * @cat DOM/Manipulation
622 * Append any number of elements to the inside of all matched elements.
623 * This operation is similar to doing an appendChild to all the
624 * specified elements, adding them into the document.
626 * @example $("p").append( $("b") );
627 * @before <p>I would like to say: </p><b>Hello</b>
628 * @result <p>I would like to say: <b>Hello</b></p>
632 * @param Array<Element> elems An array of elements, all of which will be appended.
633 * @cat DOM/Manipulation
636 return this.domManip(arguments, true, 1, function(a){
637 this.appendChild( a );
642 * Prepend any number of elements to the inside of every matched elements,
643 * generated from the provided HTML.
644 * This operation is the best way to insert dynamically created elements
645 * inside, at the beginning, of all the matched element.
647 * @example $("p").prepend("<b>Hello</b>");
648 * @before <p>I would like to say: </p>
649 * @result <p><b>Hello</b>I would like to say: </p>
653 * @param String html A string of HTML, that will be created on the fly and appended to the target.
654 * @cat DOM/Manipulation
658 * Prepend an element to the inside of all matched elements.
659 * This operation is the best way to insert an element inside, at the
660 * beginning, of all the matched element.
662 * @example $("p").prepend( $("#foo")[0] );
663 * @before <p>I would like to say: </p><b id="foo">Hello</b>
664 * @result <p><b id="foo">Hello</b>I would like to say: </p>
668 * @param Element elem A DOM element that will be appended.
669 * @cat DOM/Manipulation
673 * Prepend any number of elements to the inside of all matched elements.
674 * This operation is the best way to insert a set of elements inside, at the
675 * beginning, of all the matched element.
677 * @example $("p").prepend( $("b") );
678 * @before <p>I would like to say: </p><b>Hello</b>
679 * @result <p><b>Hello</b>I would like to say: </p>
683 * @param Array<Element> elems An array of elements, all of which will be appended.
684 * @cat DOM/Manipulation
686 prepend: function() {
687 return this.domManip(arguments, true, -1, function(a){
688 this.insertBefore( a, this.firstChild );
693 * Insert any number of dynamically generated elements before each of the
696 * @example $("p").before("<b>Hello</b>");
697 * @before <p>I would like to say: </p>
698 * @result <b>Hello</b><p>I would like to say: </p>
702 * @param String html A string of HTML, that will be created on the fly and appended to the target.
703 * @cat DOM/Manipulation
707 * Insert an element before each of the matched elements.
709 * @example $("p").before( $("#foo")[0] );
710 * @before <p>I would like to say: </p><b id="foo">Hello</b>
711 * @result <b id="foo">Hello</b><p>I would like to say: </p>
715 * @param Element elem A DOM element that will be appended.
716 * @cat DOM/Manipulation
720 * Insert any number of elements before each of the matched elements.
722 * @example $("p").before( $("b") );
723 * @before <p>I would like to say: </p><b>Hello</b>
724 * @result <b>Hello</b><p>I would like to say: </p>
728 * @param Array<Element> elems An array of elements, all of which will be appended.
729 * @cat DOM/Manipulation
732 return this.domManip(arguments, false, 1, function(a){
733 this.parentNode.insertBefore( a, this );
738 * Insert any number of dynamically generated elements after each of the
741 * @example $("p").after("<b>Hello</b>");
742 * @before <p>I would like to say: </p>
743 * @result <p>I would like to say: </p><b>Hello</b>
747 * @param String html A string of HTML, that will be created on the fly and appended to the target.
748 * @cat DOM/Manipulation
752 * Insert an element after each of the matched elements.
754 * @example $("p").after( $("#foo")[0] );
755 * @before <b id="foo">Hello</b><p>I would like to say: </p>
756 * @result <p>I would like to say: </p><b id="foo">Hello</b>
760 * @param Element elem A DOM element that will be appended.
761 * @cat DOM/Manipulation
765 * Insert any number of elements after each of the matched elements.
767 * @example $("p").after( $("b") );
768 * @before <b>Hello</b><p>I would like to say: </p>
769 * @result <p>I would like to say: </p><b>Hello</b>
773 * @param Array<Element> elems An array of elements, all of which will be appended.
774 * @cat DOM/Manipulation
777 return this.domManip(arguments, false, -1, function(a){
778 this.parentNode.insertBefore( a, this.nextSibling );
783 * End the most recent 'destructive' operation, reverting the list of matched elements
784 * back to its previous state. After an end operation, the list of matched elements will
785 * revert to the last state of matched elements.
787 * @example $("p").find("span").end();
788 * @before <p><span>Hello</span>, how are you?</p>
789 * @result $("p").find("span").end() == [ <p>...</p> ]
793 * @cat DOM/Traversing
796 if( !(this.stack && this.stack.length) )
798 return this.set( this.stack.pop() );
802 * Searches for all elements that match the specified expression.
803 * This method is the optimal way of finding additional descendant
804 * elements with which to process.
806 * All searching is done using a jQuery expression. The expression can be
807 * written using CSS 1-3 Selector syntax, or basic XPath.
809 * @example $("p").find("span");
810 * @before <p><span>Hello</span>, how are you?</p>
811 * @result $("p").find("span") == [ <span>Hello</span> ]
815 * @param String expr An expression to search with.
816 * @cat DOM/Traversing
819 return this.pushStack( jQuery.map( this, function(a){
820 return jQuery.find(t,a);
825 * Create cloned copies of all matched DOM Elements. This does
826 * not create a cloned copy of this particular jQuery object,
827 * instead it creates duplicate copies of all DOM Elements.
828 * This is useful for moving copies of the elements to another
829 * location in the DOM.
831 * @example $("b").clone().prependTo("p");
832 * @before <b>Hello</b><p>, how are you?</p>
833 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
837 * @cat DOM/Manipulation
839 clone: function(deep) {
840 return this.pushStack( jQuery.map( this, function(a){
841 return a.cloneNode( deep != undefined ? deep : true );
846 * Removes all elements from the set of matched elements that do not
847 * match the specified expression. This method is used to narrow down
848 * the results of a search.
850 * All searching is done using a jQuery expression. The expression
851 * can be written using CSS 1-3 Selector syntax, or basic XPath.
853 * @example $("p").filter(".selected")
854 * @before <p class="selected">Hello</p><p>How are you?</p>
855 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
859 * @param String expr An expression to search with.
860 * @cat DOM/Traversing
864 * Removes all elements from the set of matched elements that do not
865 * match at least one of the expressions passed to the function. This
866 * method is used when you want to filter the set of matched elements
867 * through more than one expression.
869 * Elements will be retained in the jQuery object if they match at
870 * least one of the expressions passed.
872 * @example $("p").filter([".selected", ":first"])
873 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
874 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
878 * @param Array<String> exprs A set of expressions to evaluate against
879 * @cat DOM/Traversing
881 filter: function(t) {
882 return this.pushStack(
883 t.constructor == Array &&
884 jQuery.map(this,function(a){
885 for ( var i = 0; i < t.length; i++ )
886 if ( jQuery.filter(t[i],[a]).r.length )
891 t.constructor == Boolean &&
892 ( t ? this.get() : [] ) ||
894 typeof t == "function" &&
895 jQuery.grep( this, t ) ||
897 jQuery.filter(t,this).r, arguments );
901 * Removes the specified Element from the set of matched elements. This
902 * method is used to remove a single Element from a jQuery object.
904 * @example $("p").not( document.getElementById("selected") )
905 * @before <p>Hello</p><p id="selected">Hello Again</p>
906 * @result [ <p>Hello</p> ]
910 * @param Element el An element to remove from the set
911 * @cat DOM/Traversing
915 * Removes elements matching the specified expression from the set
916 * of matched elements. This method is used to remove one or more
917 * elements from a jQuery object.
919 * @example $("p").not("#selected")
920 * @before <p>Hello</p><p id="selected">Hello Again</p>
921 * @result [ <p>Hello</p> ]
925 * @param String expr An expression with which to remove matching elements
926 * @cat DOM/Traversing
929 return this.pushStack( typeof t == "string" ?
930 jQuery.filter(t,this,true).r :
931 jQuery.grep(this,function(a){ return a != t; }), arguments );
935 * Adds the elements matched by the expression to the jQuery object. This
936 * can be used to concatenate the result sets of two expressions.
938 * @example $("p").add("span")
939 * @before <p>Hello</p><p><span>Hello Again</span></p>
940 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
944 * @param String expr An expression whose matched elements are added
945 * @cat DOM/Traversing
949 * Adds each of the Elements in the array to the set of matched elements.
950 * This is used to add a set of Elements to a jQuery object.
952 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
953 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
954 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
958 * @param Array<Element> els An array of Elements to add
959 * @cat DOM/Traversing
963 * Adds a single Element to the set of matched elements. This is used to
964 * add a single Element to a jQuery object.
966 * @example $("p").add( document.getElementById("a") )
967 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
968 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
972 * @param Element el An Element to add
973 * @cat DOM/Traversing
976 return this.pushStack( jQuery.merge(
977 this.get(), typeof t == "string" ?
979 t.constructor == Array ? t : [t] ), arguments );
983 * Checks the current selection against an expression and returns true,
984 * if at least one element of the selection fits the given expression.
985 * Does return false, if no element fits or the expression is not valid.
987 * @example $("input[@type='checkbox']").parent().is("form")
988 * @before <form><input type="checkbox" /></form>
990 * @desc Returns true, because the parent of the input is a form element
992 * @example $("input[@type='checkbox']").parent().is("form")
993 * @before <form><p><input type="checkbox" /></p></form>
995 * @desc Returns false, because the parent of the input is a p element
997 * @example $("form").is(null)
998 * @before <form></form>
1000 * @desc An invalid expression always returns false.
1004 * @param String expr The expression with which to filter
1005 * @cat DOM/Traversing
1007 is: function(expr) {
1008 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1015 * @param Boolean table Insert TBODY in TABLEs if one is not found.
1016 * @param Number dir If dir<0, process args in reverse order.
1017 * @param Function fn The function doing the DOM manipulation.
1021 domManip: function(args, table, dir, fn){
1022 var clone = this.length > 1;
1023 var a = jQuery.clean(args);
1027 return this.each(function(){
1030 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" )
1031 obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
1033 for ( var i=0; i < a.length; i++ )
1034 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1049 pushStack: function(a,args) {
1050 var fn = args && args.length > 1 && args[args.length-1];
1051 var fn2 = args && args.length > 2 && args[args.length-2];
1053 if ( fn && fn.constructor != Function ) fn = null;
1054 if ( fn2 && fn2.constructor != Function ) fn2 = null;
1057 if ( !this.stack ) this.stack = [];
1058 this.stack.push( this.get() );
1061 var old = this.get();
1064 if ( fn2 && a.length || !fn2 )
1065 this.each( fn2 || fn ).set( old );
1067 this.set( old ).each( fn );
1075 * Extends the jQuery object itself. Can be used to add functions into
1076 * the jQuery namespace and to add plugin methods (plugins).
1078 * @example jQuery.fn.extend({
1079 * check: function() {
1080 * return this.each(function() { this.checked = true; });
1082 * uncheck: function() {
1083 * return this.each(function() { this.checked = false; });
1086 * $("input[@type=checkbox]").check();
1087 * $("input[@type=radio]").uncheck();
1088 * @desc Adds two plugin methods.
1090 * @example jQuery.extend({
1091 * min: function(a, b) { return a < b ? a : b; },
1092 * max: function(a, b) { return a > b ? a : b; }
1094 * @desc Adds two functions into the jQuery namespace
1097 * @param Object prop The object that will be merged into the jQuery object
1103 * Extend one object with one or more others, returning the original,
1104 * modified, object. This is a great utility for simple inheritance.
1106 * @example var settings = { validate: false, limit: 5, name: "foo" };
1107 * var options = { validate: true, name: "bar" };
1108 * jQuery.extend(settings, options);
1109 * @result settings == { validate: true, limit: 5, name: "bar" }
1110 * @desc Merge settings and options, modifying settings
1112 * @example var defaults = { validate: false, limit: 5, name: "foo" };
1113 * var options = { validate: true, name: "bar" };
1114 * var settings = jQuery.extend({}, defaults, options);
1115 * @result settings == { validate: true, limit: 5, name: "bar" }
1116 * @desc Merge defaults and options, without modifying the defaults
1119 * @param Object target The object to extend
1120 * @param Object prop1 The object that will be merged into the first.
1121 * @param Object propN (optional) More objects to merge into the first
1125 jQuery.extend = jQuery.fn.extend = function() {
1126 // copy reference to target object
1127 var target = arguments[0],
1130 // extend jQuery itself if only one argument is passed
1131 if ( arguments.length == 1 ) {
1136 while (prop = arguments[a++])
1137 // Extend the base object
1138 for ( var i in prop ) target[i] = prop[i];
1140 // Return the modified object
1152 jQuery.initDone = true;
1154 jQuery.each( jQuery.macros.axis, function(i,n){
1155 jQuery.fn[ i ] = function(a) {
1156 var ret = jQuery.map(this,n);
1157 if ( a && typeof a == "string" )
1158 ret = jQuery.filter(a,ret).r;
1159 return this.pushStack( ret, arguments );
1163 jQuery.each( jQuery.macros.to, function(i,n){
1164 jQuery.fn[ i ] = function(){
1166 return this.each(function(){
1167 for ( var j = 0; j < a.length; j++ )
1168 jQuery(a[j])[n]( this );
1173 jQuery.each( jQuery.macros.each, function(i,n){
1174 jQuery.fn[ i ] = function() {
1175 return this.each( n, arguments );
1179 jQuery.each( jQuery.macros.filter, function(i,n){
1180 jQuery.fn[ n ] = function(num,fn) {
1181 return this.filter( ":" + n + "(" + num + ")", fn );
1185 jQuery.each( jQuery.macros.attr, function(i,n){
1187 jQuery.fn[ i ] = function(h) {
1188 return h == undefined ?
1189 this.length ? this[0][n] : null :
1194 jQuery.each( jQuery.macros.css, function(i,n){
1195 jQuery.fn[ n ] = function(h) {
1196 return h == undefined ?
1197 ( this.length ? jQuery.css( this[0], n ) : null ) :
1205 * A generic iterator function, which can be used to seemlessly
1206 * iterate over both objects and arrays. This function is not the same
1207 * as $().each() - which is used to iterate, exclusively, over a jQuery
1208 * object. This function can be used to iterate over anything.
1210 * @example $.each( [0,1,2], function(i){
1211 * alert( "Item #" + i + ": " + this );
1213 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1215 * @example $.each( { name: "John", lang: "JS" }, function(i){
1216 * alert( "Name: " + i + ", Value: " + this );
1218 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1221 * @param Object obj The object, or array, to iterate over.
1222 * @param Function fn The function that will be executed on every object.
1226 // args is for internal usage only
1227 each: function( obj, fn, args ) {
1228 if ( obj.length == undefined )
1229 for ( var i in obj )
1230 fn.apply( obj[i], args || [i, obj[i]] );
1232 for ( var i = 0; i < obj.length; i++ )
1233 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1239 if (jQuery.className.has(o,c)) return;
1240 o.className += ( o.className ? " " : "" ) + c;
1242 remove: function(o,c){
1246 var classes = o.className.split(" ");
1247 for(var i=0; i<classes.length; i++) {
1248 if(classes[i] == c) {
1249 classes.splice(i, 1);
1253 o.className = classes.join(' ');
1256 has: function(e,a) {
1257 if ( e.className != undefined )
1259 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1264 * Swap in/out style options.
1267 swap: function(e,o,f) {
1268 for ( var i in o ) {
1269 e.style["old"+i] = e.style[i];
1274 e.style[i] = e.style["old"+i];
1277 css: function(e,p) {
1278 if ( p == "height" || p == "width" ) {
1279 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1281 for ( var i=0; i<d.length; i++ ) {
1282 old["padding" + d[i]] = 0;
1283 old["border" + d[i] + "Width"] = 0;
1286 jQuery.swap( e, old, function() {
1287 if (jQuery.css(e,"display") != "none") {
1288 oHeight = e.offsetHeight;
1289 oWidth = e.offsetWidth;
1291 e = jQuery(e.cloneNode(true))
1292 .find(":radio").removeAttr("checked").end()
1294 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1295 }).appendTo(e.parentNode)[0];
1297 var parPos = jQuery.css(e.parentNode,"position");
1298 if ( parPos == "" || parPos == "static" )
1299 e.parentNode.style.position = "relative";
1301 oHeight = e.clientHeight;
1302 oWidth = e.clientWidth;
1304 if ( parPos == "" || parPos == "static" )
1305 e.parentNode.style.position = "static";
1307 e.parentNode.removeChild(e);
1311 return p == "height" ? oHeight : oWidth;
1314 return jQuery.curCSS( e, p );
1317 curCSS: function(elem, prop, force) {
1320 if (prop == 'opacity' && jQuery.browser.msie)
1321 return jQuery.attr(elem.style, 'opacity');
1323 if (prop == "float" || prop == "cssFloat")
1324 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1326 if (!force && elem.style[prop]) {
1328 ret = elem.style[prop];
1330 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1332 if (prop == "cssFloat" || prop == "styleFloat")
1335 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1336 var cur = document.defaultView.getComputedStyle(elem, null);
1339 ret = cur.getPropertyValue(prop);
1340 else if ( prop == 'display' )
1343 jQuery.swap(elem, { display: 'block' }, function() {
1344 var c = document.defaultView.getComputedStyle(this, '');
1345 ret = c && c.getPropertyValue(prop) || '';
1348 } else if (elem.currentStyle) {
1350 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1351 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1358 clean: function(a) {
1360 for ( var i = 0; i < a.length; i++ ) {
1362 if ( typeof arg == "string" ) { // Convert html string into DOM nodes
1363 // Trim whitespace, otherwise indexOf won't work as expected
1364 var s = jQuery.trim(arg), s3 = s.substring(0,3), s6 = s.substring(0,6),
1365 div = document.createElement("div"), wrap = [0,"",""];
1367 if ( s.substring(0,4) == "<opt" ) // option or optgroup
1368 wrap = [1, "<select>", "</select>"];
1369 else if ( s6 == "<thead" || s6 == "<tbody" || s6 == "<tfoot" )
1370 wrap = [1, "<table>", "</table>"];
1371 else if ( s3 == "<tr" )
1372 wrap = [2, "<table><tbody>", "</tbody></table>"];
1373 else if ( s3 == "<td" || s3 == "<th" ) // <thead> matched above
1374 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
1376 // Go to html and back, then peel off extra wrappers
1377 div.innerHTML = wrap[1] + s + wrap[2];
1378 while ( wrap[0]-- ) div = div.firstChild;
1380 // Remove IE's autoinserted <tbody> from table fragments
1381 if ( jQuery.browser.msie ) {
1383 // String was a <table>, *may* have spurious <tbody>
1384 if ( s6 == "<table" && s.indexOf("<tbody") < 0 )
1385 tb = div.firstChild && div.firstChild.childNodes;
1386 // String was a bare <thead> or <tfoot>
1387 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 )
1388 tb = div.childNodes;
1390 for ( var n = tb.length-1; n >= 0 ; --n )
1391 if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )
1392 tb[n].parentNode.removeChild(tb[n]);
1396 arg = div.childNodes;
1400 if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
1401 for ( var n = 0; n < arg.length; n++ ) // Handles Array, jQuery, DOM NodeList collections
1404 r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
1410 nth: function(cur,result,dir){
1411 result = result || 1;
1413 for ( ; cur; cur = cur[dir] ) {
1414 if ( cur.nodeType == 1 ) num++;
1415 if ( num == result || result == "even" && num % 2 == 0 && num > 1 ||
1416 result == "odd" && num % 2 == 1 ) return cur;
1421 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1422 "#": "a.getAttribute('id')==m[2]",
1430 last: "i==r.length-1",
1435 "nth-child": "jQuery.nth(a.parentNode.firstChild,m[3],'nextSibling')==a",
1436 "first-child": "jQuery.nth(a.parentNode.firstChild,1,'nextSibling')==a",
1437 "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a",
1438 "only-child": "jQuery.sibling(a.parentNode.firstChild).length==1",
1441 parent: "a.childNodes.length",
1442 empty: "!a.childNodes.length",
1445 contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
1448 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1449 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1452 enabled: "!a.disabled",
1453 disabled: "a.disabled",
1454 checked: "a.checked",
1455 selected: "a.selected || jQuery.attr(a, 'selected')",
1458 text: "a.type=='text'",
1459 radio: "a.type=='radio'",
1460 checkbox: "a.type=='checkbox'",
1461 file: "a.type=='file'",
1462 password: "a.type=='password'",
1463 submit: "a.type=='submit'",
1464 image: "a.type=='image'",
1465 reset: "a.type=='reset'",
1466 button: "a.type=='button'",
1467 input: "/input|select|textarea|button/i.test(a.nodeName)"
1469 ".": "jQuery.className.has(a,m[2])",
1473 "^=": "z && !z.indexOf(m[4])",
1474 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
1475 "*=": "z && z.indexOf(m[4])>=0",
1477 _resort: function(m){
1478 return ["", m[1], m[3], m[2], m[5]];
1480 _prefix: "z=jQuery.attr(a,m[3]);"
1482 "[": "jQuery.find(m[2],a).length"
1486 * All elements on a specified axis.
1491 * @param Element elem The element to find all the siblings of (including itself).
1492 * @cat DOM/Traversing
1494 sibling: function( n, elem ) {
1497 for ( ; n; n = n.nextSibling ) {
1498 if ( n.nodeType == 1 && (!elem || n != elem) )
1506 "\\.\\.|/\\.\\.", "a.parentNode",
1507 ">|/", "jQuery.sibling(a.firstChild)",
1508 "\\+", "jQuery.nth(a,2,'nextSibling')",
1510 var s = jQuery.sibling(a.parentNode.firstChild)
1511 return s.slice(0, jQuery.inArray(a,s));
1517 * @type Array<Element>
1521 find: function( t, context ) {
1522 // Quickly handle non-string expressions
1523 if ( typeof t != "string" )
1526 // Make sure that the context is a DOM Element
1527 if ( context && context.nodeType == undefined )
1530 // Set the correct context (if none is provided)
1531 context = context || document;
1533 // Handle the common XPath // expression
1534 if ( !t.indexOf("//") ) {
1535 context = context.documentElement;
1536 t = t.substr(2,t.length);
1538 // And the / root expression
1539 } else if ( !t.indexOf("/") ) {
1540 context = context.documentElement;
1541 t = t.substr(1,t.length);
1542 if ( t.indexOf("/") >= 1 )
1543 t = t.substr(t.indexOf("/"),t.length);
1546 // Initialize the search
1547 var ret = [context], done = [], last = null;
1549 // Continue while a selector expression exists, and while
1550 // we're no longer looping upon ourselves
1551 while ( t && last != t ) {
1555 t = jQuery.trim(t).replace( /^\/\//i, "" );
1557 var foundToken = false;
1559 // An attempt at speeding up child selectors that
1560 // point to a specific element tag
1561 var re = /^[\/>]\s*([a-z0-9*-]+)/i;
1565 // Perform our own iteration and filter
1566 for ( var i = 0; i < ret.length; i++ )
1567 for ( var c = ret[i].firstChild; c; c = c.nextSibling )
1568 if ( c.nodeType == 1 && ( c.nodeName == m[1].toUpperCase() || m[1] == "*" ) )
1572 t = jQuery.trim( t.replace( re, "" ) );
1575 // Look for pre-defined expression tokens
1576 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1577 // Attempt to match each, individual, token in
1578 // the specified order
1579 var re = new RegExp("^(" + jQuery.token[i] + ")");
1582 // If the token match was found
1584 // Map it against the token's handler
1585 r = ret = jQuery.map( ret, jQuery.token[i+1].constructor == Function ?
1587 function(a){ return eval(jQuery.token[i+1]); });
1589 // And remove the token
1590 t = jQuery.trim( t.replace( re, "" ) );
1597 // See if there's still an expression, and that we haven't already
1599 if ( t && !foundToken ) {
1600 // Handle multiple expressions
1601 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1602 // Clean teh result set
1603 if ( ret[0] == context ) ret.shift();
1605 // Merge the result sets
1606 jQuery.merge( done, ret );
1608 // Reset the context
1609 r = ret = [context];
1611 // Touch up the selector string
1612 t = " " + t.substr(1,t.length);
1615 // Optomize for the case nodeName#idName
1616 var re2 = /^([a-z0-9_-]+)(#)([a-z0-9\\*_-]*)/i;
1617 var m = re2.exec(t);
1619 // Re-organize the results, so that they're consistent
1621 m = [ 0, m[2], m[3], m[1] ];
1624 // Otherwise, do a traditional filter check for
1625 // ID, class, and element selectors
1626 re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1630 // Try to do a global search by ID, where we can
1631 if ( m[1] == "#" && ret[ret.length-1].getElementById ) {
1632 // Optimization for HTML document case
1633 var oid = ret[ret.length-1].getElementById(m[2]);
1635 // Do a quick check for node name (where applicable) so
1636 // that div#foo searches will be really fast
1638 (!m[3] || oid.nodeName == m[3].toUpperCase()) ? [oid] : [];
1640 // Use the DOM 0 shortcut for the body element
1641 } else if ( m[1] == "" && m[2] == "body" ) {
1642 ret = r = [ document.body ];
1645 // Pre-compile a regular expression to handle class searches
1647 var rec = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
1649 // We need to find all descendant elements, it is more
1650 // efficient to use getAll() when we are already further down
1651 // the tree - we try to recognize that here
1652 for ( var i = 0; i < ret.length; i++ )
1654 m[1] != "" && ret.length != 1 ?
1655 jQuery.getAll( ret[i], [], m[1], m[2], rec ) :
1656 ret[i].getElementsByTagName( m[1] != "" || m[0] == "" ? "*" : m[2] )
1659 // It's faster to filter by class and be done with it
1660 if ( m[1] == "." && ret.length == 1 )
1661 r = jQuery.grep( r, function(e) {
1662 return rec.test(e.className);
1665 // Same with ID filtering
1666 if ( m[1] == "#" && ret.length == 1 ) {
1667 // Remember, then wipe out, the result set
1671 // Then try to find the element with the ID
1672 for ( var i = 0; i < tmp.length; i++ )
1673 if ( tmp[i].getAttribute("id") == m[2] ) {
1682 t = t.replace( re2, "" );
1687 // If a selector string still exists
1689 // Attempt to filter it
1690 var val = jQuery.filter(t,r);
1692 t = jQuery.trim(val.t);
1696 // Remove the root context
1697 if ( ret && ret[0] == context ) ret.shift();
1699 // And combine the results
1700 jQuery.merge( done, ret );
1705 getAll: function( o, r, token, name, re ) {
1706 for ( var s = o.firstChild; s; s = s.nextSibling )
1707 if ( s.nodeType == 1 ) {
1711 add = s.className && re.test(s.className);
1712 else if ( token == "#" )
1713 add = s.getAttribute('id') == name;
1718 if ( token == "#" && r.length ) break;
1721 jQuery.getAll( s, r, token, name, re );
1727 attr: function(elem, name, value){
1730 "class": "className",
1731 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1732 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1733 innerHTML: "innerHTML",
1734 className: "className",
1736 disabled: "disabled",
1738 readonly: "readOnly",
1739 selected: "selected"
1742 // IE actually uses filters for opacity ... elem is actually elem.style
1743 if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
1744 // IE has trouble with opacity if it does not have layout
1745 // Force it by setting the zoom level
1748 // Set the alpha filter to set the opacity
1749 return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
1750 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
1752 } else if ( name == "opacity" && jQuery.browser.msie ) {
1753 return elem.filter ?
1754 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
1757 // Mozilla doesn't play well with opacity 1
1758 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
1761 // Certain attributes only work when accessed via the old DOM 0 way
1763 if ( value != undefined ) elem[fix[name]] = value;
1764 return elem[fix[name]];
1766 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1767 return elem.getAttributeNode(name).nodeValue;
1769 // IE elem.getAttribute passes even for style
1770 } else if ( elem.tagName ) {
1771 if ( value != undefined ) elem.setAttribute( name, value );
1772 return elem.getAttribute( name );
1775 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1776 if ( value != undefined ) elem[name] = value;
1781 // The regular expressions that power the parsing engine
1783 // Match: [@value='test'], [@foo]
1784 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
1786 // Match: [div], [div p]
1787 "(\\[)\\s*(.*?)\\s*\\]",
1789 // Match: :contains('foo')
1790 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
1792 // Match: :even, :last-chlid
1796 filter: function(t,r,not) {
1797 // Look for common filter expressions
1798 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1800 var p = jQuery.parse;
1802 for ( var i = 0; i < p.length; i++ ) {
1804 // Look for, and replace, string-like sequences
1805 // and finally build a regexp out of it
1806 var re = new RegExp(
1807 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
1809 var m = re.exec( t );
1812 // Re-organize the first match
1813 if ( jQuery.expr[ m[1] ]._resort )
1814 m = jQuery.expr[ m[1] ]._resort( m );
1816 // Remove what we just matched
1817 t = t.replace( re, "" );
1823 // :not() is a special case that can be optimized by
1824 // keeping it out of the expression list
1825 if ( m[1] == ":" && m[2] == "not" )
1826 r = jQuery.filter(m[3], r, true).r;
1828 // Handle classes as a special case (this will help to
1829 // improve the speed, as the regexp will only be compiled once)
1830 else if ( m[1] == "." ) {
1832 var re = new RegExp("(^|\\s)" + m[2] + "(\\s|$)");
1833 r = jQuery.grep( r, function(e){
1834 return re.test(e.className || '');
1837 // Otherwise, find the expression to execute
1839 var f = jQuery.expr[m[1]];
1840 if ( typeof f != "string" )
1841 f = jQuery.expr[m[1]][m[2]];
1843 // Build a custom macro to enclose it
1844 eval("f = function(a,i){" +
1845 ( jQuery.expr[ m[1] ]._prefix || "" ) +
1846 "return " + f + "}");
1848 // Execute it against the current filter
1849 r = jQuery.grep( r, f, not );
1853 // Return an array of filtered elements (r)
1854 // and the modified expression string (t)
1855 return { r: r, t: t };
1859 * Remove the whitespace from the beginning and end of a string.
1861 * @example $.trim(" hello, how are you? ");
1862 * @result "hello, how are you?"
1866 * @param String str The string to trim.
1870 return t.replace(/^\s+|\s+$/g, "");
1874 * All ancestors of a given element.
1878 * @type Array<Element>
1879 * @param Element elem The element to find the ancestors of.
1880 * @cat DOM/Traversing
1882 parents: function( elem ){
1884 var cur = elem.parentNode;
1885 while ( cur && cur != document ) {
1886 matched.push( cur );
1887 cur = cur.parentNode;
1892 makeArray: function( a ) {
1895 if ( a.constructor != Array ) {
1896 for ( var i = 0; i < a.length; i++ )
1904 inArray: function( b, a ) {
1905 for ( var i = 0; i < a.length; i++ )
1912 * Merge two arrays together, removing all duplicates. The final order
1913 * or the new array is: All the results from the first array, followed
1914 * by the unique results from the second array.
1916 * @example $.merge( [0,1,2], [2,3,4] )
1917 * @result [0,1,2,3,4]
1919 * @example $.merge( [3,2,1], [4,3,2] )
1924 * @param Array first The first array to merge.
1925 * @param Array second The second array to merge.
1928 merge: function(first, second) {
1929 var r = [].slice.call( first, 0 );
1931 // Now check for duplicates between the two arrays
1932 // and only add the unique items
1933 for ( var i = 0; i < second.length; i++ ) {
1934 // Check for duplicates
1935 if ( jQuery.inArray( second[i], r ) == -1 )
1936 // The item is unique, add it
1937 first.push( second[i] );
1944 * Filter items out of an array, by using a filter function.
1945 * The specified function will be passed two arguments: The
1946 * current array item and the index of the item in the array. The
1947 * function should return 'true' if you wish to keep the item in
1948 * the array, false if it should be removed.
1950 * @example $.grep( [0,1,2], function(i){
1957 * @param Array array The Array to find items in.
1958 * @param Function fn The function to process each item against.
1959 * @param Boolean inv Invert the selection - select the opposite of the function.
1962 grep: function(elems, fn, inv) {
1963 // If a string is passed in for the function, make a function
1964 // for it (a handy shortcut)
1965 if ( typeof fn == "string" )
1966 fn = new Function("a","i","return " + fn);
1970 // Go through the array, only saving the items
1971 // that pass the validator function
1972 for ( var i = 0; i < elems.length; i++ )
1973 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
1974 result.push( elems[i] );
1980 * Translate all items in an array to another array of items.
1981 * The translation function that is provided to this method is
1982 * called for each item in the array and is passed one argument:
1983 * The item to be translated. The function can then return:
1984 * The translated value, 'null' (to remove the item), or
1985 * an array of values - which will be flattened into the full array.
1987 * @example $.map( [0,1,2], function(i){
1992 * @example $.map( [0,1,2], function(i){
1993 * return i > 0 ? i + 1 : null;
1997 * @example $.map( [0,1,2], function(i){
1998 * return [ i, i + 1 ];
2000 * @result [0, 1, 1, 2, 2, 3]
2004 * @param Array array The Array to translate.
2005 * @param Function fn The function to process each item against.
2008 map: function(elems, fn) {
2009 // If a string is passed in for the function, make a function
2010 // for it (a handy shortcut)
2011 if ( typeof fn == "string" )
2012 fn = new Function("a","return " + fn);
2014 var result = [], r = [];
2016 // Go through the array, translating each of the items to their
2017 // new value (or values).
2018 for ( var i = 0; i < elems.length; i++ ) {
2019 var val = fn(elems[i],i);
2021 if ( val !== null && val != undefined ) {
2022 if ( val.constructor != Array ) val = [val];
2023 result = result.concat( val );
2027 var r = [ result[0] ];
2029 check: for ( var i = 1; i < result.length; i++ ) {
2030 for ( var j = 0; j < i; j++ )
2031 if ( result[i] == r[j] )
2034 r.push( result[i] );
2041 * A number of helper functions used for managing events.
2042 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2046 // Bind an event to an element
2047 // Original by Dean Edwards
2048 add: function(element, type, handler, data) {
2049 // For whatever reason, IE has trouble passing the window object
2050 // around, causing it to be cloned in the process
2051 if ( jQuery.browser.msie && element.setInterval != undefined )
2054 // if data is passed, bind to handler
2056 handler.data = data;
2058 // Make sure that the function being executed has a unique ID
2059 if ( !handler.guid )
2060 handler.guid = this.guid++;
2062 // Init the element's event structure
2063 if (!element.events)
2064 element.events = {};
2066 // Get the current list of functions bound to this event
2067 var handlers = element.events[type];
2069 // If it hasn't been initialized yet
2071 // Init the event handler queue
2072 handlers = element.events[type] = {};
2074 // Remember an existing handler, if it's already there
2075 if (element["on" + type])
2076 handlers[0] = element["on" + type];
2079 // Add the function to the element's handler list
2080 handlers[handler.guid] = handler;
2082 // And bind the global event handler to the element
2083 element["on" + type] = this.handle;
2085 // Remember the function in a global list (for triggering)
2086 if (!this.global[type])
2087 this.global[type] = [];
2088 this.global[type].push( element );
2094 // Detach an event or set of events from an element
2095 remove: function(element, type, handler) {
2097 if ( type && type.type )
2098 delete element.events[ type.type ][ type.handler.guid ];
2099 else if (type && element.events[type])
2101 delete element.events[type][handler.guid];
2103 for ( var i in element.events[type] )
2104 delete element.events[type][i];
2106 for ( var j in element.events )
2107 this.remove( element, j );
2110 trigger: function(type,data,element) {
2111 // Clone the incoming data, if any
2112 data = jQuery.makeArray(data || []);
2114 // Handle a global trigger
2116 var g = this.global[type];
2118 for ( var i = 0; i < g.length; i++ )
2119 this.trigger( type, data, g[i] );
2121 // Handle triggering a single element
2122 } else if ( element["on" + type] ) {
2123 // Pass along a fake event
2124 data.unshift( this.fix({ type: type, target: element }) );
2126 // Trigger the event
2127 element["on" + type].apply( element, data );
2131 handle: function(event) {
2132 if ( typeof jQuery == "undefined" ) return false;
2134 event = jQuery.event.fix( event || window.event || {} ); // Empty object is for triggered events with no data
2136 var returnValue = true;
2138 var c = this.events[event.type];
2140 var args = [].slice.call( arguments, 1 );
2141 args.unshift( event );
2143 for ( var j in c ) {
2144 // Pass in a reference to the handler function itself
2145 // So that we can later remove it
2146 args[0].handler = c[j];
2147 args[0].data = c[j].data;
2149 if ( c[j].apply( this, args ) === false ) {
2150 event.preventDefault();
2151 event.stopPropagation();
2152 returnValue = false;
2156 // Clean up added properties in IE to prevent memory leak
2157 if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = event.handler = event.data = null;
2162 fix: function(event) {
2163 // Fix target property, if necessary
2164 if ( !event.target && event.srcElement )
2165 event.target = event.srcElement;
2167 // Calculate pageX/Y if missing and clientX/Y available
2168 if ( typeof event.pageX == "undefined" && typeof event.clientX != "undefined" ) {
2169 var e = document.documentElement, b = document.body;
2170 event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft);
2171 event.pageY = event.clientY + (e.scrollTop || b.scrollTop);
2174 // Check safari and if target is a textnode
2175 if ( jQuery.browser.safari && event.target.nodeType == 3 ) {
2176 // target is readonly, clone the event object
2177 event = jQuery.extend({}, event);
2178 // get parentnode from textnode
2179 event.target = event.target.parentNode;
2182 // fix preventDefault and stopPropagation
2183 if (!event.preventDefault) {
2184 event.preventDefault = function() {
2185 this.returnValue = false;
2189 if (!event.stopPropagation) {
2190 event.stopPropagation = function() {
2191 this.cancelBubble = true;
2201 * Contains flags for the useragent, read from navigator.userAgent.
2202 * Available flags are: safari, opera, msie, mozilla
2203 * This property is available before the DOM is ready, therefore you can
2204 * use it to add ready events only for certain browsers.
2206 * There are situations where object detections is not reliable enough, in that
2207 * cases it makes sense to use browser detection. Simply try to avoid both!
2209 * A combination of browser and object detection yields quite reliable results.
2211 * @example $.browser.msie
2212 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
2214 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
2215 * @desc Alerts "this is safari!" only for safari browsers
2224 * Wheather the W3C compliant box model is being used.
2232 var b = navigator.userAgent.toLowerCase();
2234 // Figure out what browser is being used
2236 safari: /webkit/.test(b),
2237 opera: /opera/.test(b),
2238 msie: /msie/.test(b) && !/opera/.test(b),
2239 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2242 // Check to see if the W3C box model is being used
2243 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2249 * Append all of the matched elements to another, specified, set of elements.
2250 * This operation is, essentially, the reverse of doing a regular
2251 * $(A).append(B), in that instead of appending B to A, you're appending
2254 * @example $("p").appendTo("#foo");
2255 * @before <p>I would like to say: </p><div id="foo"></div>
2256 * @result <div id="foo"><p>I would like to say: </p></div>
2260 * @param String expr A jQuery expression of elements to match.
2261 * @cat DOM/Manipulation
2266 * Prepend all of the matched elements to another, specified, set of elements.
2267 * This operation is, essentially, the reverse of doing a regular
2268 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2271 * @example $("p").prependTo("#foo");
2272 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2273 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2277 * @param String expr A jQuery expression of elements to match.
2278 * @cat DOM/Manipulation
2280 prependTo: "prepend",
2283 * Insert all of the matched elements before another, specified, set of elements.
2284 * This operation is, essentially, the reverse of doing a regular
2285 * $(A).before(B), in that instead of inserting B before A, you're inserting
2288 * @example $("p").insertBefore("#foo");
2289 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2290 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2292 * @name insertBefore
2294 * @param String expr A jQuery expression of elements to match.
2295 * @cat DOM/Manipulation
2297 insertBefore: "before",
2300 * Insert all of the matched elements after another, specified, set of elements.
2301 * This operation is, essentially, the reverse of doing a regular
2302 * $(A).after(B), in that instead of inserting B after A, you're inserting
2305 * @example $("p").insertAfter("#foo");
2306 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2307 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2311 * @param String expr A jQuery expression of elements to match.
2312 * @cat DOM/Manipulation
2314 insertAfter: "after"
2318 * Get the current CSS width of the first matched element.
2320 * @example $("p").width();
2321 * @before <p>This is just a test.</p>
2330 * Set the CSS width of every matched element. Be sure to include
2331 * the "px" (or other unit of measurement) after the number that you
2332 * specify, otherwise you might get strange results.
2334 * @example $("p").width("20px");
2335 * @before <p>This is just a test.</p>
2336 * @result <p style="width:20px;">This is just a test.</p>
2340 * @param String val Set the CSS property to the specified value.
2345 * Get the current CSS height of the first matched element.
2347 * @example $("p").height();
2348 * @before <p>This is just a test.</p>
2357 * Set the CSS height of every matched element. Be sure to include
2358 * the "px" (or other unit of measurement) after the number that you
2359 * specify, otherwise you might get strange results.
2361 * @example $("p").height("20px");
2362 * @before <p>This is just a test.</p>
2363 * @result <p style="height:20px;">This is just a test.</p>
2367 * @param String val Set the CSS property to the specified value.
2372 * Get the current CSS top of the first matched element.
2374 * @example $("p").top();
2375 * @before <p>This is just a test.</p>
2384 * Set the CSS top of every matched element. Be sure to include
2385 * the "px" (or other unit of measurement) after the number that you
2386 * specify, otherwise you might get strange results.
2388 * @example $("p").top("20px");
2389 * @before <p>This is just a test.</p>
2390 * @result <p style="top:20px;">This is just a test.</p>
2394 * @param String val Set the CSS property to the specified value.
2399 * Get the current CSS left of the first matched element.
2401 * @example $("p").left();
2402 * @before <p>This is just a test.</p>
2411 * Set the CSS left of every matched element. Be sure to include
2412 * the "px" (or other unit of measurement) after the number that you
2413 * specify, otherwise you might get strange results.
2415 * @example $("p").left("20px");
2416 * @before <p>This is just a test.</p>
2417 * @result <p style="left:20px;">This is just a test.</p>
2421 * @param String val Set the CSS property to the specified value.
2426 * Get the current CSS position of the first matched element.
2428 * @example $("p").position();
2429 * @before <p>This is just a test.</p>
2438 * Set the CSS position of every matched element.
2440 * @example $("p").position("relative");
2441 * @before <p>This is just a test.</p>
2442 * @result <p style="position:relative;">This is just a test.</p>
2446 * @param String val Set the CSS property to the specified value.
2451 * Get the current CSS float of the first matched element.
2453 * @example $("p").float();
2454 * @before <p>This is just a test.</p>
2463 * Set the CSS float of every matched element.
2465 * @example $("p").float("left");
2466 * @before <p>This is just a test.</p>
2467 * @result <p style="float:left;">This is just a test.</p>
2471 * @param String val Set the CSS property to the specified value.
2476 * Get the current CSS overflow of the first matched element.
2478 * @example $("p").overflow();
2479 * @before <p>This is just a test.</p>
2488 * Set the CSS overflow of every matched element.
2490 * @example $("p").overflow("auto");
2491 * @before <p>This is just a test.</p>
2492 * @result <p style="overflow:auto;">This is just a test.</p>
2496 * @param String val Set the CSS property to the specified value.
2501 * Get the current CSS color of the first matched element.
2503 * @example $("p").color();
2504 * @before <p>This is just a test.</p>
2513 * Set the CSS color of every matched element.
2515 * @example $("p").color("blue");
2516 * @before <p>This is just a test.</p>
2517 * @result <p style="color:blue;">This is just a test.</p>
2521 * @param String val Set the CSS property to the specified value.
2526 * Get the current CSS background of the first matched element.
2528 * @example $("p").background();
2529 * @before <p style="background:blue;">This is just a test.</p>
2538 * Set the CSS background of every matched element.
2540 * @example $("p").background("blue");
2541 * @before <p>This is just a test.</p>
2542 * @result <p style="background:blue;">This is just a test.</p>
2546 * @param String val Set the CSS property to the specified value.
2550 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2553 * Reduce the set of matched elements to a single element.
2554 * The position of the element in the set of matched elements
2555 * starts at 0 and goes to length - 1.
2557 * @example $("p").eq(1)
2558 * @before <p>This is just a test.</p><p>So is this</p>
2559 * @result [ <p>So is this</p> ]
2563 * @param Number pos The index of the element that you wish to limit to.
2568 * Reduce the set of matched elements to all elements before a given position.
2569 * The position of the element in the set of matched elements
2570 * starts at 0 and goes to length - 1.
2572 * @example $("p").lt(1)
2573 * @before <p>This is just a test.</p><p>So is this</p>
2574 * @result [ <p>This is just a test.</p> ]
2578 * @param Number pos Reduce the set to all elements below this position.
2583 * Reduce the set of matched elements to all elements after a given position.
2584 * The position of the element in the set of matched elements
2585 * starts at 0 and goes to length - 1.
2587 * @example $("p").gt(0)
2588 * @before <p>This is just a test.</p><p>So is this</p>
2589 * @result [ <p>So is this</p> ]
2593 * @param Number pos Reduce the set to all elements after this position.
2598 * Filter the set of elements to those that contain the specified text.
2600 * @example $("p").contains("test")
2601 * @before <p>This is just a test.</p><p>So is this</p>
2602 * @result [ <p>This is just a test.</p> ]
2606 * @param String str The string that will be contained within the text of an element.
2607 * @cat DOM/Traversing
2610 filter: [ "eq", "lt", "gt", "contains" ],
2614 * Get the current value of the first matched element.
2616 * @example $("input").val();
2617 * @before <input type="text" value="some text"/>
2618 * @result "some text"
2622 * @cat DOM/Attributes
2626 * Set the value of every matched element.
2628 * @example $("input").val("test");
2629 * @before <input type="text" value="some text"/>
2630 * @result <input type="text" value="test"/>
2634 * @param String val Set the property to the specified value.
2635 * @cat DOM/Attributes
2640 * Get the html contents of the first matched element.
2641 * This property is not available on XML documents.
2643 * @example $("div").html();
2644 * @before <div><input/></div>
2649 * @cat DOM/Attributes
2653 * Set the html contents of every matched element.
2654 * This property is not available on XML documents.
2656 * @example $("div").html("<b>new stuff</b>");
2657 * @before <div><input/></div>
2658 * @result <div><b>new stuff</b></div>
2662 * @param String val Set the html contents to the specified value.
2663 * @cat DOM/Attributes
2668 * Get the current id of the first matched element.
2670 * @example $("input").id();
2671 * @before <input type="text" id="test" value="some text"/>
2676 * @cat DOM/Attributes
2680 * Set the id of every matched element.
2682 * @example $("input").id("newid");
2683 * @before <input type="text" id="test" value="some text"/>
2684 * @result <input type="text" id="newid" value="some text"/>
2688 * @param String val Set the property to the specified value.
2689 * @cat DOM/Attributes
2694 * Get the current title of the first matched element.
2696 * @example $("img").title();
2697 * @before <img src="test.jpg" title="my image"/>
2698 * @result "my image"
2702 * @cat DOM/Attributes
2706 * Set the title of every matched element.
2708 * @example $("img").title("new title");
2709 * @before <img src="test.jpg" title="my image"/>
2710 * @result <img src="test.jpg" title="new image"/>
2714 * @param String val Set the property to the specified value.
2715 * @cat DOM/Attributes
2720 * Get the current name of the first matched element.
2722 * @example $("input").name();
2723 * @before <input type="text" name="username"/>
2724 * @result "username"
2728 * @cat DOM/Attributes
2732 * Set the name of every matched element.
2734 * @example $("input").name("user");
2735 * @before <input type="text" name="username"/>
2736 * @result <input type="text" name="user"/>
2740 * @param String val Set the property to the specified value.
2741 * @cat DOM/Attributes
2746 * Get the current href of the first matched element.
2748 * @example $("a").href();
2749 * @before <a href="test.html">my link</a>
2750 * @result "test.html"
2754 * @cat DOM/Attributes
2758 * Set the href of every matched element.
2760 * @example $("a").href("test2.html");
2761 * @before <a href="test.html">my link</a>
2762 * @result <a href="test2.html">my link</a>
2766 * @param String val Set the property to the specified value.
2767 * @cat DOM/Attributes
2772 * Get the current src of the first matched element.
2774 * @example $("img").src();
2775 * @before <img src="test.jpg" title="my image"/>
2776 * @result "test.jpg"
2780 * @cat DOM/Attributes
2784 * Set the src of every matched element.
2786 * @example $("img").src("test2.jpg");
2787 * @before <img src="test.jpg" title="my image"/>
2788 * @result <img src="test2.jpg" title="my image"/>
2792 * @param String val Set the property to the specified value.
2793 * @cat DOM/Attributes
2798 * Get the current rel of the first matched element.
2800 * @example $("a").rel();
2801 * @before <a href="test.html" rel="nofollow">my link</a>
2802 * @result "nofollow"
2806 * @cat DOM/Attributes
2810 * Set the rel of every matched element.
2812 * @example $("a").rel("nofollow");
2813 * @before <a href="test.html">my link</a>
2814 * @result <a href="test.html" rel="nofollow">my link</a>
2818 * @param String val Set the property to the specified value.
2819 * @cat DOM/Attributes
2826 * Get a set of elements containing the unique parents of the matched
2829 * @example $("p").parent()
2830 * @before <div><p>Hello</p><p>Hello</p></div>
2831 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2835 * @cat DOM/Traversing
2839 * Get a set of elements containing the unique parents of the matched
2840 * set of elements, and filtered by an expression.
2842 * @example $("p").parent(".selected")
2843 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2844 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2848 * @param String expr An expression to filter the parents with
2849 * @cat DOM/Traversing
2851 parent: "a.parentNode",
2854 * Get a set of elements containing the unique ancestors of the matched
2855 * set of elements (except for the root element).
2857 * @example $("span").parents()
2858 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2859 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2863 * @cat DOM/Traversing
2867 * Get a set of elements containing the unique ancestors of the matched
2868 * set of elements, and filtered by an expression.
2870 * @example $("span").parents("p")
2871 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2872 * @result [ <p><span>Hello</span></p> ]
2876 * @param String expr An expression to filter the ancestors with
2877 * @cat DOM/Traversing
2879 parents: jQuery.parents,
2882 * Get a set of elements containing the unique next siblings of each of the
2883 * matched set of elements.
2885 * It only returns the very next sibling, not all next siblings.
2887 * @example $("p").next()
2888 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2889 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2893 * @cat DOM/Traversing
2897 * Get a set of elements containing the unique next siblings of each of the
2898 * matched set of elements, and filtered by an expression.
2900 * It only returns the very next sibling, not all next siblings.
2902 * @example $("p").next(".selected")
2903 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2904 * @result [ <p class="selected">Hello Again</p> ]
2908 * @param String expr An expression to filter the next Elements with
2909 * @cat DOM/Traversing
2911 next: "jQuery.nth(a,1,'nextSibling')",
2914 * Get a set of elements containing the unique previous siblings of each of the
2915 * matched set of elements.
2917 * It only returns the immediately previous sibling, not all previous siblings.
2919 * @example $("p").prev()
2920 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2921 * @result [ <div><span>Hello Again</span></div> ]
2925 * @cat DOM/Traversing
2929 * Get a set of elements containing the unique previous siblings of each of the
2930 * matched set of elements, and filtered by an expression.
2932 * It only returns the immediately previous sibling, not all previous siblings.
2934 * @example $("p").prev(".selected")
2935 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2936 * @result [ <div><span>Hello</span></div> ]
2940 * @param String expr An expression to filter the previous Elements with
2941 * @cat DOM/Traversing
2943 prev: "jQuery.nth(a,1,'previousSibling')",
2946 * Get a set of elements containing all of the unique siblings of each of the
2947 * matched set of elements.
2949 * @example $("div").siblings()
2950 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2951 * @result [ <p>Hello</p>, <p>And Again</p> ]
2955 * @cat DOM/Traversing
2959 * Get a set of elements containing all of the unique siblings of each of the
2960 * matched set of elements, and filtered by an expression.
2962 * @example $("div").siblings(".selected")
2963 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2964 * @result [ <p class="selected">Hello Again</p> ]
2968 * @param String expr An expression to filter the sibling Elements with
2969 * @cat DOM/Traversing
2971 siblings: "jQuery.sibling(a.parentNode.firstChild,a)",
2974 * Get a set of elements containing all of the unique children of each of the
2975 * matched set of elements.
2977 * @example $("div").children()
2978 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2979 * @result [ <span>Hello Again</span> ]
2983 * @cat DOM/Traversing
2987 * Get a set of elements containing all of the unique children of each of the
2988 * matched set of elements, and filtered by an expression.
2990 * @example $("div").children(".selected")
2991 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2992 * @result [ <p class="selected">Hello Again</p> ]
2996 * @param String expr An expression to filter the child Elements with
2997 * @cat DOM/Traversing
2999 children: "jQuery.sibling(a.firstChild)"
3005 * Remove an attribute from each of the matched elements.
3007 * @example $("input").removeAttr("disabled")
3008 * @before <input disabled="disabled"/>
3013 * @param String name The name of the attribute to remove.
3016 removeAttr: function( key ) {
3017 jQuery.attr( this, key, "" );
3018 this.removeAttribute( key );
3022 * Displays each of the set of matched elements if they are hidden.
3024 * @example $("p").show()
3025 * @before <p style="display: none">Hello</p>
3026 * @result [ <p style="display: block">Hello</p> ]
3033 this.style.display = this.oldblock ? this.oldblock : "";
3034 if ( jQuery.css(this,"display") == "none" )
3035 this.style.display = "block";
3039 * Hides each of the set of matched elements if they are shown.
3041 * @example $("p").hide()
3042 * @before <p>Hello</p>
3043 * @result [ <p style="display: none">Hello</p> ]
3045 * var pass = true, div = $("div");
3046 * div.hide().each(function(){
3047 * if ( this.style.display != "none" ) pass = false;
3049 * ok( pass, "Hide" );
3056 this.oldblock = this.oldblock || jQuery.css(this,"display");
3057 if ( this.oldblock == "none" )
3058 this.oldblock = "block";
3059 this.style.display = "none";
3063 * Toggles each of the set of matched elements. If they are shown,
3064 * toggle makes them hidden. If they are hidden, toggle
3067 * @example $("p").toggle()
3068 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3069 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3076 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3080 * Adds the specified class to each of the set of matched elements.
3082 * @example $("p").addClass("selected")
3083 * @before <p>Hello</p>
3084 * @result [ <p class="selected">Hello</p> ]
3088 * @param String class A CSS class to add to the elements
3091 addClass: function(c){
3092 jQuery.className.add(this,c);
3096 * Removes the specified class from the set of matched elements.
3098 * @example $("p").removeClass("selected")
3099 * @before <p class="selected">Hello</p>
3100 * @result [ <p>Hello</p> ]
3104 * @param String class A CSS class to remove from the elements
3107 removeClass: function(c){
3108 jQuery.className.remove(this,c);
3112 * Adds the specified class if it is not present, removes it if it is
3115 * @example $("p").toggleClass("selected")
3116 * @before <p>Hello</p><p class="selected">Hello Again</p>
3117 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3121 * @param String class A CSS class with which to toggle the elements
3124 toggleClass: function( c ){
3125 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
3129 * Removes all matched elements from the DOM. This does NOT remove them from the
3130 * jQuery object, allowing you to use the matched elements further.
3132 * @example $("p").remove();
3133 * @before <p>Hello</p> how are <p>you?</p>
3138 * @cat DOM/Manipulation
3142 * Removes only elements (out of the list of matched elements) that match
3143 * the specified jQuery expression. This does NOT remove them from the
3144 * jQuery object, allowing you to use the matched elements further.
3146 * @example $("p").remove(".hello");
3147 * @before <p class="hello">Hello</p> how are <p>you?</p>
3148 * @result how are <p>you?</p>
3152 * @param String expr A jQuery expression to filter elements by.
3153 * @cat DOM/Manipulation
3155 remove: function(a){
3156 if ( !a || jQuery.filter( a, [this] ).r )
3157 this.parentNode.removeChild( this );
3161 * Removes all child nodes from the set of matched elements.
3163 * @example $("p").empty()
3164 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3165 * @result [ <p></p> ]
3169 * @cat DOM/Manipulation
3172 while ( this.firstChild )
3173 this.removeChild( this.firstChild );
3177 * Binds a handler to a particular event (like click) for each matched element.
3178 * The event handler is passed an event object that you can use to prevent
3179 * default behaviour. To stop both default action and event bubbling, your handler
3180 * has to return false.
3182 * In most cases, you can define your event handlers as anonymous functions
3183 * (see first example). In cases where that is not possible, you can pass additional
3184 * data as the second paramter (and the handler function as the third), see
3187 * @example $("p").bind( "click", function() {
3188 * alert( $(this).text() );
3190 * @before <p>Hello</p>
3191 * @result alert("Hello")
3193 * @example var handler = function(event) {
3194 * alert(event.data.foo);
3196 * $("p").bind( "click", {foo: "bar"}, handler)
3197 * @result alert("bar")
3198 * @desc Pass some additional data to the event handler.
3200 * @example $("form").bind( "submit", function() { return false; } )
3201 * @desc Cancel a default action and prevent it from bubbling by returning false
3202 * from your function.
3204 * @example $("form").bind( "submit", function(event) {
3205 * event.preventDefault();
3207 * @desc Cancel only the default action by using the preventDefault method.
3210 * @example $("form").bind( "submit", function(event) {
3211 * event.stopPropagation();
3213 * @desc Stop only an event from bubbling by using the stopPropagation method.
3217 * @param String type An event type
3218 * @param Object data (optional) Additional data passed to the event handler as event.data
3219 * @param Function fn A function to bind to the event on each of the set of matched elements
3222 bind: function( type, data, fn ) {
3223 jQuery.event.add( this, type, fn || data, data );
3227 * The opposite of bind, removes a bound event from each of the matched
3228 * elements. You must pass the identical function that was used in the original
3231 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3232 * @before <p onclick="alert('Hello');">Hello</p>
3233 * @result [ <p>Hello</p> ]
3237 * @param String type An event type
3238 * @param Function fn A function to unbind from the event on each of the set of matched elements
3243 * Removes all bound events of a particular type from each of the matched
3246 * @example $("p").unbind( "click" )
3247 * @before <p onclick="alert('Hello');">Hello</p>
3248 * @result [ <p>Hello</p> ]
3252 * @param String type An event type
3257 * Removes all bound events from each of the matched elements.
3259 * @example $("p").unbind()
3260 * @before <p onclick="alert('Hello');">Hello</p>
3261 * @result [ <p>Hello</p> ]
3267 unbind: function( type, fn ) {
3268 jQuery.event.remove( this, type, fn );
3272 * Trigger a type of event on every matched element.
3274 * @example $("p").trigger("click")
3275 * @before <p click="alert('hello')">Hello</p>
3276 * @result alert('hello')
3280 * @param String type An event type to trigger.
3283 trigger: function( type, data ) {
3284 jQuery.event.trigger( type, data, this );