2 * jQuery @VERSION - New Wave Javascript
\r
4 * Copyright (c) 2006 John Resig (jquery.com)
\r
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
\r
6 * and GPL (GPL-LICENSE.txt) licenses.
\r
12 // Global undefined variable
\r
13 window.undefined = window.undefined;
\r
16 * Create a new jQuery Object
\r
23 var jQuery = function(a,c) {
\r
25 // Shortcut for document ready (because $(document).each() is silly)
\r
26 if ( a && typeof a == "function" && jQuery.fn.ready && !a.nodeType && a[0] == undefined ) // Safari reports typeof on DOM NodeLists as a function
\r
27 return jQuery(document).ready(a);
\r
29 // Make sure that a selection was provided
\r
32 // Watch for when a jQuery object is passed as the selector
\r
34 return jQuery( jQuery.merge( a, [] ) );
\r
36 // Watch for when a jQuery object is passed at the context
\r
37 if ( c && c.jquery )
\r
38 return jQuery( c ).find(a);
\r
40 // If the context is global, return a new object
\r
41 if ( window == this )
\r
42 return new jQuery(a,c);
\r
44 // Handle HTML strings
\r
45 if ( typeof a == "string" ) {
\r
46 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
\r
47 if ( m ) a = jQuery.clean( [ m[1] ] );
\r
50 // Watch for when an array is passed in
\r
51 this.set( a.constructor == Array || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType ?
\r
52 // Assume that it is an array of DOM Elements
\r
53 jQuery.merge( a, [] ) :
\r
55 // Find the matching elements and save them for later
\r
56 jQuery.find( a, c ) );
\r
61 // Map over the $ in case of overwrite
\r
62 if ( typeof $ != "undefined" )
\r
65 // Map the jQuery namespace to the '$' one
\r
69 * This function accepts a string containing a CSS or
\r
70 * basic XPath selector which is then used to match a set of elements.
\r
72 * The core functionality of jQuery centers around this function.
\r
73 * Everything in jQuery is based upon this, or uses this in some way.
\r
74 * The most basic use of this function is to pass in an expression
\r
75 * (usually consisting of CSS or XPath), which then finds all matching
\r
78 * By default, $() looks for DOM elements within the context of the
\r
79 * current HTML document.
\r
81 * @example $("div > p")
\r
82 * @desc This finds all p elements that are children of a div element.
\r
83 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
\r
84 * @result [ <p>two</p> ]
\r
86 * @example $("input:radio", document.forms[0])
\r
87 * @desc Searches for all inputs of type radio within the first form in the document
\r
89 * @example $("div", xml.responseXML)
\r
90 * @desc This finds all div elements within the specified XML document.
\r
93 * @param String expr An expression to search with
\r
94 * @param Element context (optional) A DOM Element, or Document, representing the base context.
\r
98 * @see $(Element<Array>)
\r
102 * This function accepts a string of raw HTML.
\r
104 * The HTML string is different from the traditional selectors in that
\r
105 * it creates the DOM elements representing that HTML string, on the fly,
\r
106 * to be (assumedly) inserted into the document later.
\r
108 * @example $("<div><p>Hello</p></div>").appendTo("#body")
\r
109 * @desc Creates a div element (and all of its contents) dynamically,
\r
110 * and appends it to the element with the ID of body. Internally, an
\r
111 * element is created and it's innerHTML property set to the given markup.
\r
112 * It is therefore both quite flexible and limited.
\r
115 * @param String html A string of HTML to create on the fly.
\r
121 * Wrap jQuery functionality around a specific DOM Element.
\r
122 * This function also accepts XML Documents and Window objects
\r
123 * as valid arguments (even though they are not DOM Elements).
\r
125 * @example $(document).find("div > p")
\r
126 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
\r
127 * @result [ <p>two</p> ]
\r
129 * @example $(document.body).background( "black" );
\r
130 * @desc Sets the background color of the page to black.
\r
133 * @param Element elem A DOM element to be encapsulated by a jQuery object.
\r
139 * Wrap jQuery functionality around a set of DOM Elements.
\r
141 * @example $( myForm.elements ).hide()
\r
142 * @desc Hides all the input elements within a form
\r
145 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
\r
151 * A shorthand for $(document).ready(), allowing you to bind a function
\r
152 * to be executed when the DOM document has finished loading. This function
\r
153 * behaves just like $(document).ready(), in that it should be used to wrap
\r
154 * all of the other $() operations on your page. While this function is,
\r
155 * technically, chainable - there really isn't much use for chaining against it.
\r
156 * You can have as many $(document).ready events on your page as you like.
\r
158 * @example $(function(){
\r
159 * // Document is ready
\r
161 * @desc Executes the function when the DOM is ready to be used.
\r
164 * @param Function fn The function to execute when the DOM is ready.
\r
170 * A means of creating a cloned copy of a jQuery object. This function
\r
171 * copies the set of matched elements from one jQuery object and creates
\r
172 * another, new, jQuery object containing the same elements.
\r
174 * @example var div = $("div");
\r
175 * $( div ).find("p");
\r
176 * @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).
\r
179 * @param jQuery obj The jQuery object to be cloned.
\r
184 jQuery.fn = jQuery.prototype = {
\r
186 * The current version of jQuery.
\r
194 jquery: "@VERSION",
\r
197 * The number of elements currently matched.
\r
199 * @example $("img").length;
\r
200 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
210 * The number of elements currently matched.
\r
212 * @example $("img").size();
\r
213 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
221 return this.length;
\r
225 * Access all matched elements. This serves as a backwards-compatible
\r
226 * way of accessing all matched elements (other than the jQuery object
\r
227 * itself, which is, in fact, an array of elements).
\r
229 * @example $("img").get();
\r
230 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
231 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
\r
234 * @type Array<Element>
\r
239 * Access a single matched element. num is used to access the
\r
240 * Nth element matched.
\r
242 * @example $("img").get(1);
\r
243 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
244 * @result [ <img src="test1.jpg"/> ]
\r
248 * @param Number num Access the element in the Nth position.
\r
251 get: function( num ) {
\r
252 return num == undefined ?
\r
254 // Return a 'clean' array
\r
255 jQuery.merge( this, [] ) :
\r
257 // Return just the object
\r
262 * Set the jQuery object to an array of elements.
\r
264 * @example $("img").set([ document.body ]);
\r
265 * @result $("img").set() == [ document.body ]
\r
270 * @param Elements elems An array of elements
\r
273 set: function( array ) {
\r
274 // Use a tricky hack to make the jQuery object
\r
275 // look and feel like an array
\r
277 [].push.apply( this, array );
\r
282 * Execute a function within the context of every matched element.
\r
283 * This means that every time the passed-in function is executed
\r
284 * (which is once for every element matched) the 'this' keyword
\r
285 * points to the specific element.
\r
287 * Additionally, the function, when executed, is passed a single
\r
288 * argument representing the position of the element in the matched
\r
291 * @example $("img").each(function(i){
\r
292 * this.src = "test" + i + ".jpg";
\r
294 * @before <img/> <img/>
\r
295 * @result <img src="test0.jpg"/> <img src="test1.jpg"/>
\r
296 * @desc Iterates over two images and sets their src property
\r
300 * @param Function fn A function to execute
\r
303 each: function( fn, args ) {
\r
304 return jQuery.each( this, fn, args );
\r
308 * Searches every matched element for the object and returns
\r
309 * the index of the element, if found, starting with zero.
\r
310 * Returns -1 if the object wasn't found.
\r
312 * @example $("*").index(document.getElementById('foobar'))
\r
313 * @before <div id="foobar"></div><b></b><span id="foo"></span>
\r
316 * @example $("*").index(document.getElementById('foo'))
\r
317 * @before <div id="foobar"></div><b></b><span id="foo"></span>
\r
320 * @example $("*").index(document.getElementById('bar'))
\r
321 * @before <div id="foobar"></div><b></b><span id="foo"></span>
\r
326 * @param Object obj Object to search for
\r
329 index: function( obj ) {
\r
331 this.each(function(i){
\r
332 if ( this == obj ) pos = i;
\r
338 * Access a property on the first matched element.
\r
339 * This method makes it easy to retrieve a property value
\r
340 * from the first matched element.
\r
342 * @example $("img").attr("src");
\r
343 * @before <img src="test.jpg"/>
\r
348 * @param String name The name of the property to access.
\r
353 * Set a hash of key/value object properties to all matched elements.
\r
354 * This serves as the best way to set a large number of properties
\r
355 * on all matched elements.
\r
357 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
\r
359 * @result <img src="test.jpg" alt="Test Image"/>
\r
363 * @param Hash prop A set of key/value pairs to set as object properties.
\r
368 * Set a single property to a value, on all matched elements.
\r
370 * @example $("img").attr("src","test.jpg");
\r
372 * @result <img src="test.jpg"/>
\r
376 * @param String key The name of the property to set.
\r
377 * @param Object value The value to set the property to.
\r
380 attr: function( key, value, type ) {
\r
381 // Check to see if we're setting style values
\r
382 return key.constructor != String || value != undefined ?
\r
383 this.each(function(){
\r
384 // See if we're setting a hash of styles
\r
385 if ( value == undefined )
\r
386 // Set all the styles
\r
387 for ( var prop in key )
\r
389 type ? this.style : this,
\r
393 // See if we're setting a single key/value style
\r
396 type ? this.style : this,
\r
401 // Look for the case where we're accessing a style value
\r
402 jQuery[ type || "attr" ]( this[0], key );
\r
406 * Access a style property on the first matched element.
\r
407 * This method makes it easy to retrieve a style property value
\r
408 * from the first matched element.
\r
410 * @example $("p").css("color");
\r
411 * @before <p style="color:red;">Test Paragraph.</p>
\r
413 * @desc Retrieves the color style of the first paragraph
\r
415 * @example $("p").css("fontWeight");
\r
416 * @before <p style="font-weight: bold;">Test Paragraph.</p>
\r
418 * @desc Retrieves the font-weight style of the first paragraph.
\r
419 * Note that for all style properties with a dash (like 'font-weight'), you have to
\r
420 * write it in camelCase. In other words: Every time you have a '-' in a
\r
421 * property, remove it and replace the next character with an uppercase
\r
422 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
\r
423 * borderStyle, borderBottomWidth etc.
\r
427 * @param String name The name of the property to access.
\r
432 * Set a hash of key/value style properties to all matched elements.
\r
433 * This serves as the best way to set a large number of style properties
\r
434 * on all matched elements.
\r
436 * @example $("p").css({ color: "red", background: "blue" });
\r
437 * @before <p>Test Paragraph.</p>
\r
438 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
\r
442 * @param Hash prop A set of key/value pairs to set as style properties.
\r
447 * Set a single style property to a value, on all matched elements.
\r
449 * @example $("p").css("color","red");
\r
450 * @before <p>Test Paragraph.</p>
\r
451 * @result <p style="color:red;">Test Paragraph.</p>
\r
452 * @desc Changes the color of all paragraphs to red
\r
456 * @param String key The name of the property to set.
\r
457 * @param Object value The value to set the property to.
\r
460 css: function( key, value ) {
\r
461 return this.attr( key, value, "curCSS" );
\r
465 * Retrieve the text contents of all matched elements. The result is
\r
466 * a string that contains the combined text contents of all matched
\r
467 * elements. This method works on both HTML and XML documents.
\r
469 * @example $("p").text();
\r
470 * @before <p>Test Paragraph.</p>
\r
471 * @result Test Paragraph.
\r
477 text: function(e) {
\r
480 for ( var j = 0; j < e.length; j++ ) {
\r
481 var r = e[j].childNodes;
\r
482 for ( var i = 0; i < r.length; i++ )
\r
483 if ( r[i].nodeType != 8 )
\r
484 t += r[i].nodeType != 1 ?
\r
485 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
\r
491 * Wrap all matched elements with a structure of other elements.
\r
492 * This wrapping process is most useful for injecting additional
\r
493 * stucture into a document, without ruining the original semantic
\r
494 * qualities of a document.
\r
496 * This works by going through the first element
\r
497 * provided (which is generated, on the fly, from the provided HTML)
\r
498 * and finds the deepest ancestor element within its
\r
499 * structure - it is that element that will en-wrap everything else.
\r
501 * This does not work with elements that contain text. Any necessary text
\r
502 * must be added after the wrapping is done.
\r
504 * @example $("p").wrap("<div class='wrap'></div>");
\r
505 * @before <p>Test Paragraph.</p>
\r
506 * @result <div class='wrap'><p>Test Paragraph.</p></div>
\r
510 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
\r
511 * @cat DOM/Manipulation
\r
515 * Wrap all matched elements with a structure of other elements.
\r
516 * This wrapping process is most useful for injecting additional
\r
517 * stucture into a document, without ruining the original semantic
\r
518 * qualities of a document.
\r
520 * This works by going through the first element
\r
521 * provided and finding the deepest ancestor element within its
\r
522 * structure - it is that element that will en-wrap everything else.
\r
524 * This does not work with elements that contain text. Any necessary text
\r
525 * must be added after the wrapping is done.
\r
527 * @example $("p").wrap( document.getElementById('content') );
\r
528 * @before <p>Test Paragraph.</p><div id="content"></div>
\r
529 * @result <div id="content"><p>Test Paragraph.</p></div>
\r
533 * @param Element elem A DOM element that will be wrapped.
\r
534 * @cat DOM/Manipulation
\r
537 // The elements to wrap the target around
\r
538 var a = jQuery.clean(arguments);
\r
540 // Wrap each of the matched elements individually
\r
541 return this.each(function(){
\r
542 // Clone the structure that we're using to wrap
\r
543 var b = a[0].cloneNode(true);
\r
545 // Insert it before the element to be wrapped
\r
546 this.parentNode.insertBefore( b, this );
\r
548 // Find the deepest point in the wrap structure
\r
549 while ( b.firstChild )
\r
552 // Move the matched element to within the wrap structure
\r
553 b.appendChild( this );
\r
558 * Append any number of elements to the inside of every matched elements,
\r
559 * generated from the provided HTML.
\r
560 * This operation is similar to doing an appendChild to all the
\r
561 * specified elements, adding them into the document.
\r
563 * @example $("p").append("<b>Hello</b>");
\r
564 * @before <p>I would like to say: </p>
\r
565 * @result <p>I would like to say: <b>Hello</b></p>
\r
569 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
570 * @cat DOM/Manipulation
\r
574 * Append an element to the inside of all matched elements.
\r
575 * This operation is similar to doing an appendChild to all the
\r
576 * specified elements, adding them into the document.
\r
578 * @example $("p").append( $("#foo")[0] );
\r
579 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
580 * @result <p>I would like to say: <b id="foo">Hello</b></p>
\r
584 * @param Element elem A DOM element that will be appended.
\r
585 * @cat DOM/Manipulation
\r
589 * Append any number of elements to the inside of all matched elements.
\r
590 * This operation is similar to doing an appendChild to all the
\r
591 * specified elements, adding them into the document.
\r
593 * @example $("p").append( $("b") );
\r
594 * @before <p>I would like to say: </p><b>Hello</b>
\r
595 * @result <p>I would like to say: <b>Hello</b></p>
\r
599 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
600 * @cat DOM/Manipulation
\r
602 append: function() {
\r
603 return this.domManip(arguments, true, 1, function(a){
\r
604 this.appendChild( a );
\r
609 * Prepend any number of elements to the inside of every matched elements,
\r
610 * generated from the provided HTML.
\r
611 * This operation is the best way to insert dynamically created elements
\r
612 * inside, at the beginning, of all the matched element.
\r
614 * @example $("p").prepend("<b>Hello</b>");
\r
615 * @before <p>I would like to say: </p>
\r
616 * @result <p><b>Hello</b>I would like to say: </p>
\r
620 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
621 * @cat DOM/Manipulation
\r
625 * Prepend an element to the inside of all matched elements.
\r
626 * This operation is the best way to insert an element inside, at the
\r
627 * beginning, of all the matched element.
\r
629 * @example $("p").prepend( $("#foo")[0] );
\r
630 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
631 * @result <p><b id="foo">Hello</b>I would like to say: </p>
\r
635 * @param Element elem A DOM element that will be appended.
\r
636 * @cat DOM/Manipulation
\r
640 * Prepend any number of elements to the inside of all matched elements.
\r
641 * This operation is the best way to insert a set of elements inside, at the
\r
642 * beginning, of all the matched element.
\r
644 * @example $("p").prepend( $("b") );
\r
645 * @before <p>I would like to say: </p><b>Hello</b>
\r
646 * @result <p><b>Hello</b>I would like to say: </p>
\r
650 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
651 * @cat DOM/Manipulation
\r
653 prepend: function() {
\r
654 return this.domManip(arguments, true, -1, function(a){
\r
655 this.insertBefore( a, this.firstChild );
\r
660 * Insert any number of dynamically generated elements before each of the
\r
661 * matched elements.
\r
663 * @example $("p").before("<b>Hello</b>");
\r
664 * @before <p>I would like to say: </p>
\r
665 * @result <b>Hello</b><p>I would like to say: </p>
\r
669 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
670 * @cat DOM/Manipulation
\r
674 * Insert an element before each of the matched elements.
\r
676 * @example $("p").before( $("#foo")[0] );
\r
677 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
678 * @result <b id="foo">Hello</b><p>I would like to say: </p>
\r
682 * @param Element elem A DOM element that will be appended.
\r
683 * @cat DOM/Manipulation
\r
687 * Insert any number of elements before each of the matched elements.
\r
689 * @example $("p").before( $("b") );
\r
690 * @before <p>I would like to say: </p><b>Hello</b>
\r
691 * @result <b>Hello</b><p>I would like to say: </p>
\r
695 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
696 * @cat DOM/Manipulation
\r
698 before: function() {
\r
699 return this.domManip(arguments, false, 1, function(a){
\r
700 this.parentNode.insertBefore( a, this );
\r
705 * Insert any number of dynamically generated elements after each of the
\r
706 * matched elements.
\r
708 * @example $("p").after("<b>Hello</b>");
\r
709 * @before <p>I would like to say: </p>
\r
710 * @result <p>I would like to say: </p><b>Hello</b>
\r
714 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
715 * @cat DOM/Manipulation
\r
719 * Insert an element after each of the matched elements.
\r
721 * @example $("p").after( $("#foo")[0] );
\r
722 * @before <b id="foo">Hello</b><p>I would like to say: </p>
\r
723 * @result <p>I would like to say: </p><b id="foo">Hello</b>
\r
727 * @param Element elem A DOM element that will be appended.
\r
728 * @cat DOM/Manipulation
\r
732 * Insert any number of elements after each of the matched elements.
\r
734 * @example $("p").after( $("b") );
\r
735 * @before <b>Hello</b><p>I would like to say: </p>
\r
736 * @result <p>I would like to say: </p><b>Hello</b>
\r
740 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
741 * @cat DOM/Manipulation
\r
743 after: function() {
\r
744 return this.domManip(arguments, false, -1, function(a){
\r
745 this.parentNode.insertBefore( a, this.nextSibling );
\r
750 * End the most recent 'destructive' operation, reverting the list of matched elements
\r
751 * back to its previous state. After an end operation, the list of matched elements will
\r
752 * revert to the last state of matched elements.
\r
754 * @example $("p").find("span").end();
\r
755 * @before <p><span>Hello</span>, how are you?</p>
\r
756 * @result $("p").find("span").end() == [ <p>...</p> ]
\r
760 * @cat DOM/Traversing
\r
763 if( !(this.stack && this.stack.length) )
\r
765 return this.set( this.stack.pop() );
\r
769 * Searches for all elements that match the specified expression.
\r
770 * This method is the optimal way of finding additional descendant
\r
771 * elements with which to process.
\r
773 * All searching is done using a jQuery expression. The expression can be
\r
774 * written using CSS 1-3 Selector syntax, or basic XPath.
\r
776 * @example $("p").find("span");
\r
777 * @before <p><span>Hello</span>, how are you?</p>
\r
778 * @result $("p").find("span") == [ <span>Hello</span> ]
\r
782 * @param String expr An expression to search with.
\r
783 * @cat DOM/Traversing
\r
785 find: function(t) {
\r
786 return this.pushStack( jQuery.map( this, function(a){
\r
787 return jQuery.find(t,a);
\r
792 * Create cloned copies of all matched DOM Elements. This does
\r
793 * not create a cloned copy of this particular jQuery object,
\r
794 * instead it creates duplicate copies of all DOM Elements.
\r
795 * This is useful for moving copies of the elements to another
\r
796 * location in the DOM.
\r
798 * @example $("b").clone().prependTo("p");
\r
799 * @before <b>Hello</b><p>, how are you?</p>
\r
800 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
\r
804 * @cat DOM/Manipulation
\r
806 clone: function(deep) {
\r
807 return this.pushStack( jQuery.map( this, function(a){
\r
808 return a.cloneNode( deep != undefined ? deep : true );
\r
813 * Removes all elements from the set of matched elements that do not
\r
814 * match the specified expression. This method is used to narrow down
\r
815 * the results of a search.
\r
817 * All searching is done using a jQuery expression. The expression
\r
818 * can be written using CSS 1-3 Selector syntax, or basic XPath.
\r
820 * @example $("p").filter(".selected")
\r
821 * @before <p class="selected">Hello</p><p>How are you?</p>
\r
822 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
\r
826 * @param String expr An expression to search with.
\r
827 * @cat DOM/Traversing
\r
831 * Removes all elements from the set of matched elements that do not
\r
832 * match at least one of the expressions passed to the function. This
\r
833 * method is used when you want to filter the set of matched elements
\r
834 * through more than one expression.
\r
836 * Elements will be retained in the jQuery object if they match at
\r
837 * least one of the expressions passed.
\r
839 * @example $("p").filter([".selected", ":first"])
\r
840 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
\r
841 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
\r
845 * @param Array<String> exprs A set of expressions to evaluate against
\r
846 * @cat DOM/Traversing
\r
848 filter: function(t) {
\r
849 return this.pushStack(
\r
850 t.constructor == Array &&
\r
851 jQuery.map(this,function(a){
\r
852 for ( var i = 0; i < t.length; i++ )
\r
853 if ( jQuery.filter(t[i],[a]).r.length )
\r
858 t.constructor == Boolean &&
\r
859 ( t ? this.get() : [] ) ||
\r
861 typeof t == "function" &&
\r
862 jQuery.grep( this, t ) ||
\r
864 jQuery.filter(t,this).r );
\r
868 * Removes the specified Element from the set of matched elements. This
\r
869 * method is used to remove a single Element from a jQuery object.
\r
871 * @example $("p").not( document.getElementById("selected") )
\r
872 * @before <p>Hello</p><p id="selected">Hello Again</p>
\r
873 * @result [ <p>Hello</p> ]
\r
877 * @param Element el An element to remove from the set
\r
878 * @cat DOM/Traversing
\r
882 * Removes elements matching the specified expression from the set
\r
883 * of matched elements. This method is used to remove one or more
\r
884 * elements from a jQuery object.
\r
886 * @example $("p").not("#selected")
\r
887 * @before <p>Hello</p><p id="selected">Hello Again</p>
\r
888 * @result [ <p>Hello</p> ]
\r
892 * @param String expr An expression with which to remove matching elements
\r
893 * @cat DOM/Traversing
\r
896 return this.pushStack( typeof t == "string" ?
\r
897 jQuery.filter(t,this,false).r :
\r
898 jQuery.grep(this,function(a){ return a != t; }) );
\r
902 * Adds the elements matched by the expression to the jQuery object. This
\r
903 * can be used to concatenate the result sets of two expressions.
\r
905 * @example $("p").add("span")
\r
906 * @before <p>Hello</p><p><span>Hello Again</span></p>
\r
907 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
\r
911 * @param String expr An expression whose matched elements are added
\r
912 * @cat DOM/Traversing
\r
916 * Adds each of the Elements in the array to the set of matched elements.
\r
917 * This is used to add a set of Elements to a jQuery object.
\r
919 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
\r
920 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
\r
921 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
\r
925 * @param Array<Element> els An array of Elements to add
\r
926 * @cat DOM/Traversing
\r
930 * Adds a single Element to the set of matched elements. This is used to
\r
931 * add a single Element to a jQuery object.
\r
933 * @example $("p").add( document.getElementById("a") )
\r
934 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
\r
935 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
\r
939 * @param Element el An Element to add
\r
940 * @cat DOM/Traversing
\r
943 return this.pushStack( jQuery.merge( this, typeof t == "string" ?
\r
944 jQuery.find(t) : t.constructor == Array ? t : [t] ) );
\r
948 * Checks the current selection against an expression and returns true,
\r
949 * if at least one element of the selection fits the given expression.
\r
950 * Does return false, if no element fits or the expression is not valid.
\r
952 * @example $("input[@type='checkbox']").parent().is("form")
\r
953 * @before <form><input type="checkbox" /></form>
\r
955 * @desc Returns true, because the parent of the input is a form element
\r
957 * @example $("input[@type='checkbox']").parent().is("form")
\r
958 * @before <form><p><input type="checkbox" /></p></form>
\r
960 * @desc Returns false, because the parent of the input is a p element
\r
962 * @example $("form").is(null)
\r
963 * @before <form></form>
\r
965 * @desc An invalid expression always returns false.
\r
969 * @param String expr The expression with which to filter
\r
970 * @cat DOM/Traversing
\r
972 is: function(expr) {
\r
973 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
\r
979 * @param Array args
\r
980 * @param Boolean table
\r
981 * @param Number dir
\r
982 * @param Function fn The function doing the DOM manipulation.
\r
986 domManip: function(args, table, dir, fn){
\r
987 var clone = this.size() > 1;
\r
988 var a = jQuery.clean(args);
\r
990 return this.each(function(){
\r
993 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
\r
994 var tbody = this.getElementsByTagName("tbody");
\r
996 if ( !tbody.length ) {
\r
997 obj = document.createElement("tbody");
\r
998 this.appendChild( obj );
\r
1003 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
\r
1004 i != ( dir < 0 ? dir : a.length ); i += dir ) {
\r
1005 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
\r
1016 * @param Array args
\r
1020 pushStack: function(a) {
\r
1021 if ( !this.stack )
\r
1023 this.stack.push( this.get() );
\r
1024 return this.set( a );
\r
1029 * Extends the jQuery object itself. Can be used to add functions into
\r
1030 * the jQuery namespace and to add plugin methods (plugins).
\r
1032 * @example jQuery.fn.extend({
\r
1033 * check: function() {
\r
1034 * return this.each(function() { this.checked = true; });
\r
1036 * uncheck: function() {
\r
1037 * return this.each(function() { this.checked = false; });
\r
1040 * $("input[@type=checkbox]").check();
\r
1041 * $("input[@type=radio]").uncheck();
\r
1042 * @desc Adds two plugin methods.
\r
1044 * @example jQuery.extend({
\r
1045 * min: function(a, b) { return a < b ? a : b; },
\r
1046 * max: function(a, b) { return a > b ? a : b; }
\r
1048 * @desc Adds two functions into the jQuery namespace
\r
1051 * @param Object prop The object that will be merged into the jQuery object
\r
1057 * Extend one object with one or more others, returning the original,
\r
1058 * modified, object. This is a great utility for simple inheritance.
\r
1060 * @example var settings = { validate: false, limit: 5, name: "foo" };
\r
1061 * var options = { validate: true, name: "bar" };
\r
1062 * jQuery.extend(settings, options);
\r
1063 * @result settings == { validate: true, limit: 5, name: "bar" }
\r
1064 * @desc Merge settings and options, modifying settings
\r
1066 * @example var defaults = { validate: false, limit: 5, name: "foo" };
\r
1067 * var options = { validate: true, name: "bar" };
\r
1068 * var settings = jQuery.extend({}, defaults, options);
\r
1069 * @result settings == { validate: true, limit: 5, name: "bar" }
\r
1070 * @desc Merge defaults and options, without modifying the defaults
\r
1073 * @param Object target The object to extend
\r
1074 * @param Object prop1 The object that will be merged into the first.
\r
1075 * @param Object propN (optional) More objects to merge into the first
\r
1079 jQuery.extend = jQuery.fn.extend = function() {
\r
1080 // copy reference to target object
\r
1081 var target = arguments[0],
\r
1084 // extend jQuery itself if only one argument is passed
\r
1085 if ( arguments.length == 1 ) {
\r
1090 while (prop = arguments[a++])
\r
1091 // Extend the base object
\r
1092 for ( var i in prop ) target[i] = prop[i];
\r
1094 // Return the modified object
\r
1106 jQuery.initDone = true;
\r
1108 jQuery.each( jQuery.macros.axis, function(i,n){
\r
1109 jQuery.fn[ i ] = function(a) {
\r
1110 var ret = jQuery.map(this,n);
\r
1111 if ( a && typeof a == "string" )
\r
1112 ret = jQuery.filter(a,ret).r;
\r
1113 return this.pushStack( ret, arguments );
\r
1117 jQuery.each( jQuery.macros.to, function(i,n){
\r
1118 jQuery.fn[ i ] = function(){
\r
1119 var a = arguments;
\r
1120 return this.each(function(){
\r
1121 for ( var j = 0; j < a.length; j++ )
\r
1122 jQuery(a[j])[n]( this );
\r
1127 jQuery.each( jQuery.macros.each, function(i,n){
\r
1128 jQuery.fn[ i ] = function() {
\r
1129 return this.each( n, arguments );
\r
1133 jQuery.each( jQuery.macros.filter, function(i,n){
\r
1134 jQuery.fn[ n ] = function(num,fn) {
\r
1135 return this.filter( ":" + n + "(" + num + ")", fn );
\r
1139 jQuery.each( jQuery.macros.attr, function(i,n){
\r
1141 jQuery.fn[ i ] = function(h) {
\r
1142 return h == undefined ?
\r
1143 this.length ? this[0][n] : null :
\r
1144 this.attr( n, h );
\r
1148 jQuery.each( jQuery.macros.css, function(i,n){
\r
1149 jQuery.fn[ n ] = function(h) {
\r
1150 return h == undefined ?
\r
1151 ( this.length ? jQuery.css( this[0], n ) : null ) :
\r
1159 * A generic iterator function, which can be used to seemlessly
\r
1160 * iterate over both objects and arrays. This function is not the same
\r
1161 * as $().each() - which is used to iterate, exclusively, over a jQuery
\r
1162 * object. This function can be used to iterate over anything.
\r
1164 * @example $.each( [0,1,2], function(i){
\r
1165 * alert( "Item #" + i + ": " + this );
\r
1167 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
\r
1169 * @example $.each( { name: "John", lang: "JS" }, function(i){
\r
1170 * alert( "Name: " + i + ", Value: " + this );
\r
1172 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
\r
1175 * @param Object obj The object, or array, to iterate over.
\r
1176 * @param Function fn The function that will be executed on every object.
\r
1180 // args is for internal usage only
\r
1181 each: function( obj, fn, args ) {
\r
1182 if ( obj.length == undefined )
\r
1183 for ( var i in obj )
\r
1184 fn.apply( obj[i], args || [i, obj[i]] );
\r
1186 for ( var i = 0; i < obj.length; i++ )
\r
1187 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
\r
1192 add: function(o,c){
\r
1193 if (jQuery.className.has(o,c)) return;
\r
1194 o.className += ( o.className ? " " : "" ) + c;
\r
1196 remove: function(o,c){
\r
1200 var classes = o.className.split(" ");
\r
1201 for(var i=0; i<classes.length; i++) {
\r
1202 if(classes[i] == c) {
\r
1203 classes.splice(i, 1);
\r
1207 o.className = classes.join(' ');
\r
1210 has: function(e,a) {
\r
1211 if ( e.className != undefined )
\r
1213 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
\r
1218 * Swap in/out style options.
\r
1221 swap: function(e,o,f) {
\r
1222 for ( var i in o ) {
\r
1223 e.style["old"+i] = e.style[i];
\r
1224 e.style[i] = o[i];
\r
1227 for ( var i in o )
\r
1228 e.style[i] = e.style["old"+i];
\r
1231 css: function(e,p) {
\r
1232 if ( p == "height" || p == "width" ) {
\r
1233 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
\r
1235 for ( var i=0; i<d.length; i++ ) {
\r
1236 old["padding" + d[i]] = 0;
\r
1237 old["border" + d[i] + "Width"] = 0;
\r
1240 jQuery.swap( e, old, function() {
\r
1241 if (jQuery.css(e,"display") != "none") {
\r
1242 oHeight = e.offsetHeight;
\r
1243 oWidth = e.offsetWidth;
\r
1245 e = jQuery(e.cloneNode(true))
\r
1246 .find(":radio").removeAttr("checked").end()
\r
1248 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
\r
1249 }).appendTo(e.parentNode)[0];
\r
1251 var parPos = jQuery.css(e.parentNode,"position");
\r
1252 if ( parPos == "" || parPos == "static" )
\r
1253 e.parentNode.style.position = "relative";
\r
1255 oHeight = e.clientHeight;
\r
1256 oWidth = e.clientWidth;
\r
1258 if ( parPos == "" || parPos == "static" )
\r
1259 e.parentNode.style.position = "static";
\r
1261 e.parentNode.removeChild(e);
\r
1265 return p == "height" ? oHeight : oWidth;
\r
1268 return jQuery.curCSS( e, p );
\r
1271 curCSS: function(elem, prop, force) {
\r
1274 if (prop == 'opacity' && jQuery.browser.msie)
\r
1275 return jQuery.attr(elem.style, 'opacity');
\r
1277 if (prop == "float" || prop == "cssFloat")
\r
1278 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
\r
1280 if (!force && elem.style[prop]) {
\r
1282 ret = elem.style[prop];
\r
1284 } else if (elem.currentStyle) {
\r
1286 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
\r
1287 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
\r
1289 } else if (document.defaultView && document.defaultView.getComputedStyle) {
\r
1291 if (prop == "cssFloat" || prop == "styleFloat")
\r
1294 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
\r
1295 var cur = document.defaultView.getComputedStyle(elem, null);
\r
1298 ret = cur.getPropertyValue(prop);
\r
1299 else if ( prop == 'display' )
\r
1302 jQuery.swap(elem, { display: 'block' }, function() {
\r
1303 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
\r
1311 clean: function(a) {
\r
1313 for ( var i = 0; i < a.length; i++ ) {
\r
1315 if ( typeof arg == "string" ) { // Convert html string into DOM nodes
\r
1316 // Trim whitespace, otherwise indexOf won't work as expected
\r
1317 var s = jQuery.trim(arg), div = document.createElement("div"), wrap = [0,"",""];
\r
1319 if ( !s.indexOf("<opt") ) // option or optgroup
\r
1320 wrap = [1, "<select>", "</select>"];
\r
1321 else if ( !s.indexOf("<thead") || !s.indexOf("<tbody") )
\r
1322 wrap = [1, "<table>", "</table>"];
\r
1323 else if ( !s.indexOf("<tr") )
\r
1324 wrap = [2, "<table>", "</table>"]; // tbody auto-inserted
\r
1325 else if ( !s.indexOf("<td") || !s.indexOf("<th") )
\r
1326 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
\r
1328 // Go to html and back, then peel off extra wrappers
\r
1329 div.innerHTML = wrap[1] + s + wrap[2];
\r
1330 while ( wrap[0]-- ) div = div.firstChild;
\r
1331 arg = div.childNodes;
\r
1335 if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
\r
1336 for ( var n = 0; n < arg.length; n++ ) // Handles Array, jQuery, DOM NodeList collections
\r
1339 r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
\r
1346 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
\r
1347 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
\r
1349 // Position Checks
\r
1355 last: "i==r.length-1",
\r
1360 "nth-child": "jQuery.sibling(a,m[3]).cur",
\r
1361 "first-child": "jQuery.sibling(a,0).cur",
\r
1362 "last-child": "jQuery.sibling(a,0).last",
\r
1363 "only-child": "jQuery.sibling(a).length==1",
\r
1366 parent: "a.childNodes.length",
\r
1367 empty: "!a.childNodes.length",
\r
1370 contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
\r
1373 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
\r
1374 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
\r
1376 // Form attributes
\r
1377 enabled: "!a.disabled",
\r
1378 disabled: "a.disabled",
\r
1379 checked: "a.checked",
\r
1380 selected: "a.selected || jQuery.attr(a, 'selected')",
\r
1383 text: "a.type=='text'",
\r
1384 radio: "a.type=='radio'",
\r
1385 checkbox: "a.type=='checkbox'",
\r
1386 file: "a.type=='file'",
\r
1387 password: "a.type=='password'",
\r
1388 submit: "a.type=='submit'",
\r
1389 image: "a.type=='image'",
\r
1390 reset: "a.type=='reset'",
\r
1391 button: "a.type=='button'",
\r
1392 input: "/input|select|textarea|button/i.test(a.nodeName)"
\r
1394 ".": "jQuery.className.has(a,m[2])",
\r
1398 "^=": "z && !z.indexOf(m[4])",
\r
1399 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
\r
1400 "*=": "z && z.indexOf(m[4])>=0",
\r
1403 "[": "jQuery.find(m[2],a).length"
\r
1407 "\\.\\.|/\\.\\.", "a.parentNode",
\r
1408 ">|/", "jQuery.sibling(a.firstChild)",
\r
1409 "\\+", "jQuery.sibling(a).next",
\r
1411 var s = jQuery.sibling(a);
\r
1412 return s.n >= 0 ? s.slice(s.n+1) : [];
\r
1418 * @type Array<Element>
\r
1422 find: function( t, context ) {
\r
1423 // Make sure that the context is a DOM Element
\r
1424 if ( context && context.nodeType == undefined )
\r
1427 // Set the correct context (if none is provided)
\r
1428 context = context || document;
\r
1430 if ( t.constructor != String ) return [t];
\r
1432 if ( !t.indexOf("//") ) {
\r
1433 context = context.documentElement;
\r
1434 t = t.substr(2,t.length);
\r
1435 } else if ( !t.indexOf("/") ) {
\r
1436 context = context.documentElement;
\r
1437 t = t.substr(1,t.length);
\r
1438 // FIX Assume the root element is right :(
\r
1439 if ( t.indexOf("/") >= 1 )
\r
1440 t = t.substr(t.indexOf("/"),t.length);
\r
1443 var ret = [context];
\r
1447 while ( t.length > 0 && last != t ) {
\r
1451 t = jQuery.trim(t).replace( /^\/\//i, "" );
\r
1453 var foundToken = false;
\r
1455 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
\r
1456 if ( foundToken ) continue;
\r
1458 var re = new RegExp("^(" + jQuery.token[i] + ")");
\r
1459 var m = re.exec(t);
\r
1462 r = ret = jQuery.map( ret, jQuery.token[i+1] );
\r
1463 t = jQuery.trim( t.replace( re, "" ) );
\r
1464 foundToken = true;
\r
1468 if ( !foundToken ) {
\r
1469 if ( !t.indexOf(",") || !t.indexOf("|") ) {
\r
1470 if ( ret[0] == context ) ret.shift();
\r
1471 done = jQuery.merge( done, ret );
\r
1472 r = ret = [context];
\r
1473 t = " " + t.substr(1,t.length);
\r
1475 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
\r
1476 var m = re2.exec(t);
\r
1478 if ( m[1] == "#" ) {
\r
1479 // Ummm, should make this work in all XML docs
\r
1480 var oid = document.getElementById(m[2]);
\r
1481 r = ret = oid ? [oid] : [];
\r
1482 t = t.replace( re2, "" );
\r
1484 if ( !m[2] || m[1] == "." ) m[2] = "*";
\r
1486 for ( var i = 0; i < ret.length; i++ )
\r
1487 r = jQuery.merge( r,
\r
1489 jQuery.getAll(ret[i]) :
\r
1490 ret[i].getElementsByTagName(m[2])
\r
1498 var val = jQuery.filter(t,r);
\r
1500 t = jQuery.trim(val.t);
\r
1504 if ( ret && ret[0] == context ) ret.shift();
\r
1505 done = jQuery.merge( done, ret );
\r
1510 getAll: function(o,r) {
\r
1512 var s = o.childNodes;
\r
1513 for ( var i = 0; i < s.length; i++ )
\r
1514 if ( s[i].nodeType == 1 ) {
\r
1516 jQuery.getAll( s[i], r );
\r
1521 attr: function(elem, name, value){
\r
1524 "class": "className",
\r
1525 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
\r
1526 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
\r
1527 innerHTML: "innerHTML",
\r
1528 className: "className",
\r
1530 disabled: "disabled",
\r
1531 checked: "checked",
\r
1532 readonly: "readOnly"
\r
1535 // IE actually uses filters for opacity ... elem is actually elem.style
\r
1536 if (name == "opacity" && jQuery.browser.msie && value != undefined) {
\r
1537 // IE has trouble with opacity if it does not have layout
\r
1538 // Would prefer to check element.hasLayout first but don't have access to the element here
\r
1539 elem['zoom'] = 1;
\r
1540 if (value == 1) // Remove filter to avoid more IE weirdness
\r
1541 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"");
\r
1543 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"") + "alpha(opacity=" + value * 100 + ")";
\r
1544 } else if (name == "opacity" && jQuery.browser.msie) {
\r
1545 return elem["filter"] ? parseFloat( elem["filter"].match(/alpha\(opacity=(.*)\)/)[1] )/100 : 1;
\r
1548 // Mozilla doesn't play well with opacity 1
\r
1549 if (name == "opacity" && jQuery.browser.mozilla && value == 1) value = 0.9999;
\r
1551 if ( fix[name] ) {
\r
1552 if ( value != undefined ) elem[fix[name]] = value;
\r
1553 return elem[fix[name]];
\r
1554 } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
\r
1555 return elem.getAttributeNode(name).nodeValue;
\r
1556 } else if ( elem.tagName ) { // IE elem.getAttribute passes even for style
\r
1557 if ( value != undefined ) elem.setAttribute( name, value );
\r
1558 return elem.getAttribute( name );
\r
1560 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
\r
1561 if ( value != undefined ) elem[name] = value;
\r
1562 return elem[name];
\r
1566 // The regular expressions that power the parsing engine
\r
1568 // Match: [@value='test'], [@foo]
\r
1569 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
\r
1571 // Match: [div], [div p]
\r
1572 "(\\[)\s*(.*?)\s*\\]",
\r
1574 // Match: :contains('foo')
\r
1575 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
\r
1577 // Match: :even, :last-chlid
\r
1581 filter: function(t,r,not) {
\r
1582 // Figure out if we're doing regular, or inverse, filtering
\r
1583 var g = not !== false ? jQuery.grep :
\r
1584 function(a,f) {return jQuery.grep(a,f,true);};
\r
1586 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
\r
1588 var p = jQuery.parse;
\r
1590 for ( var i = 0; i < p.length; i++ ) {
\r
1592 // Look for, and replace, string-like sequences
\r
1593 // and finally build a regexp out of it
\r
1594 var re = new RegExp(
\r
1595 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
\r
1597 var m = re.exec( t );
\r
1600 // Re-organize the first match
\r
1602 m = ["",m[1], m[3], m[2], m[5]];
\r
1604 // Remove what we just matched
\r
1605 t = t.replace( re, "" );
\r
1611 // :not() is a special case that can be optimized by
\r
1612 // keeping it out of the expression list
\r
1613 if ( m[1] == ":" && m[2] == "not" )
\r
1614 r = jQuery.filter(m[3],r,false).r;
\r
1616 // Otherwise, find the expression to execute
\r
1618 var f = jQuery.expr[m[1]];
\r
1619 if ( f.constructor != String )
\r
1620 f = jQuery.expr[m[1]][m[2]];
\r
1622 // Build a custom macro to enclose it
\r
1623 eval("f = function(a,i){" +
\r
1624 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
\r
1625 "return " + f + "}");
\r
1627 // Execute it against the current filter
\r
1632 // Return an array of filtered elements (r)
\r
1633 // and the modified expression string (t)
\r
1634 return { r: r, t: t };
\r
1638 * Remove the whitespace from the beginning and end of a string.
\r
1640 * @example $.trim(" hello, how are you? ");
\r
1641 * @result "hello, how are you?"
\r
1645 * @param String str The string to trim.
\r
1648 trim: function(t){
\r
1649 return t.replace(/^\s+|\s+$/g, "");
\r
1653 * All ancestors of a given element.
\r
1657 * @type Array<Element>
\r
1658 * @param Element elem The element to find the ancestors of.
\r
1659 * @cat DOM/Traversing
\r
1661 parents: function( elem ){
\r
1663 var cur = elem.parentNode;
\r
1664 while ( cur && cur != document ) {
\r
1665 matched.push( cur );
\r
1666 cur = cur.parentNode;
\r
1672 * All elements on a specified axis.
\r
1677 * @param Element elem The element to find all the siblings of (including itself).
\r
1678 * @cat DOM/Traversing
\r
1680 sibling: function(elem, pos, not) {
\r
1684 var siblings = elem.parentNode.childNodes;
\r
1685 for ( var i = 0; i < siblings.length; i++ ) {
\r
1686 if ( not === true && siblings[i] == elem ) continue;
\r
1688 if ( siblings[i].nodeType == 1 )
\r
1689 elems.push( siblings[i] );
\r
1690 if ( siblings[i] == elem )
\r
1691 elems.n = elems.length - 1;
\r
1695 return jQuery.extend( elems, {
\r
1696 last: elems.n == elems.length - 1,
\r
1697 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
\r
1698 prev: elems[elems.n - 1],
\r
1699 next: elems[elems.n + 1]
\r
1704 * Merge two arrays together, removing all duplicates. The final order
\r
1705 * or the new array is: All the results from the first array, followed
\r
1706 * by the unique results from the second array.
\r
1708 * @example $.merge( [0,1,2], [2,3,4] )
\r
1709 * @result [0,1,2,3,4]
\r
1711 * @example $.merge( [3,2,1], [4,3,2] )
\r
1712 * @result [3,2,1,4]
\r
1716 * @param Array first The first array to merge.
\r
1717 * @param Array second The second array to merge.
\r
1720 merge: function(first, second) {
\r
1723 // Move b over to the new array (this helps to avoid
\r
1724 // StaticNodeList instances)
\r
1725 for ( var k = 0; k < first.length; k++ )
\r
1726 result[k] = first[k];
\r
1728 // Now check for duplicates between a and b and only
\r
1729 // add the unique items
\r
1730 for ( var i = 0; i < second.length; i++ ) {
\r
1731 var noCollision = true;
\r
1733 // The collision-checking process
\r
1734 for ( var j = 0; j < first.length; j++ )
\r
1735 if ( second[i] == first[j] )
\r
1736 noCollision = false;
\r
1738 // If the item is unique, add it
\r
1739 if ( noCollision )
\r
1740 result.push( second[i] );
\r
1747 * Filter items out of an array, by using a filter function.
\r
1748 * The specified function will be passed two arguments: The
\r
1749 * current array item and the index of the item in the array. The
\r
1750 * function should return 'true' if you wish to keep the item in
\r
1751 * the array, false if it should be removed.
\r
1753 * @example $.grep( [0,1,2], function(i){
\r
1760 * @param Array array The Array to find items in.
\r
1761 * @param Function fn The function to process each item against.
\r
1762 * @param Boolean inv Invert the selection - select the opposite of the function.
\r
1765 grep: function(elems, fn, inv) {
\r
1766 // If a string is passed in for the function, make a function
\r
1767 // for it (a handy shortcut)
\r
1768 if ( typeof fn == "string" )
\r
1769 fn = new Function("a","i","return " + fn);
\r
1773 // Go through the array, only saving the items
\r
1774 // that pass the validator function
\r
1775 for ( var i = 0; i < elems.length; i++ )
\r
1776 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
\r
1777 result.push( elems[i] );
\r
1783 * Translate all items in an array to another array of items.
\r
1784 * The translation function that is provided to this method is
\r
1785 * called for each item in the array and is passed one argument:
\r
1786 * The item to be translated. The function can then return:
\r
1787 * The translated value, 'null' (to remove the item), or
\r
1788 * an array of values - which will be flattened into the full array.
\r
1790 * @example $.map( [0,1,2], function(i){
\r
1793 * @result [4, 5, 6]
\r
1795 * @example $.map( [0,1,2], function(i){
\r
1796 * return i > 0 ? i + 1 : null;
\r
1800 * @example $.map( [0,1,2], function(i){
\r
1801 * return [ i, i + 1 ];
\r
1803 * @result [0, 1, 1, 2, 2, 3]
\r
1807 * @param Array array The Array to translate.
\r
1808 * @param Function fn The function to process each item against.
\r
1811 map: function(elems, fn) {
\r
1812 // If a string is passed in for the function, make a function
\r
1813 // for it (a handy shortcut)
\r
1814 if ( typeof fn == "string" )
\r
1815 fn = new Function("a","return " + fn);
\r
1819 // Go through the array, translating each of the items to their
\r
1820 // new value (or values).
\r
1821 for ( var i = 0; i < elems.length; i++ ) {
\r
1822 var val = fn(elems[i],i);
\r
1824 if ( val !== null && val != undefined ) {
\r
1825 if ( val.constructor != Array ) val = [val];
\r
1826 result = jQuery.merge( result, val );
\r
1834 * A number of helper functions used for managing events.
\r
1835 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
\r
1839 // Bind an event to an element
\r
1840 // Original by Dean Edwards
\r
1841 add: function(element, type, handler) {
\r
1842 // For whatever reason, IE has trouble passing the window object
\r
1843 // around, causing it to be cloned in the process
\r
1844 if ( jQuery.browser.msie && element.setInterval != undefined )
\r
1847 // Make sure that the function being executed has a unique ID
\r
1848 if ( !handler.guid )
\r
1849 handler.guid = this.guid++;
\r
1851 // Init the element's event structure
\r
1852 if (!element.events)
\r
1853 element.events = {};
\r
1855 // Get the current list of functions bound to this event
\r
1856 var handlers = element.events[type];
\r
1858 // If it hasn't been initialized yet
\r
1860 // Init the event handler queue
\r
1861 handlers = element.events[type] = {};
\r
1863 // Remember an existing handler, if it's already there
\r
1864 if (element["on" + type])
\r
1865 handlers[0] = element["on" + type];
\r
1868 // Add the function to the element's handler list
\r
1869 handlers[handler.guid] = handler;
\r
1871 // And bind the global event handler to the element
\r
1872 element["on" + type] = this.handle;
\r
1874 // Remember the function in a global list (for triggering)
\r
1875 if (!this.global[type])
\r
1876 this.global[type] = [];
\r
1877 this.global[type].push( element );
\r
1883 // Detach an event or set of events from an element
\r
1884 remove: function(element, type, handler) {
\r
1885 if (element.events)
\r
1886 if (type && element.events[type])
\r
1888 delete element.events[type][handler.guid];
\r
1890 for ( var i in element.events[type] )
\r
1891 delete element.events[type][i];
\r
1893 for ( var j in element.events )
\r
1894 this.remove( element, j );
\r
1897 trigger: function(type,data,element) {
\r
1898 // Clone the incoming data, if any
\r
1899 data = $.merge([], data || []);
\r
1901 // Handle a global trigger
\r
1903 var g = this.global[type];
\r
1905 for ( var i = 0; i < g.length; i++ )
\r
1906 this.trigger( type, data, g[i] );
\r
1908 // Handle triggering a single element
\r
1909 } else if ( element["on" + type] ) {
\r
1910 // Pass along a fake event
\r
1911 data.unshift( this.fix({ type: type, target: element }) );
\r
1913 // Trigger the event
\r
1914 element["on" + type].apply( element, data );
\r
1918 handle: function(event) {
\r
1919 if ( typeof jQuery == "undefined" ) return false;
\r
1921 event = jQuery.event.fix( event || window.event || {} ); // Empty object is for triggered events with no data
\r
1923 // If no correct event was found, fail
\r
1924 if ( !event ) return false;
\r
1926 var returnValue = true;
\r
1928 var c = this.events[event.type];
\r
1930 var args = [].slice.call( arguments, 1 );
\r
1931 args.unshift( event );
\r
1933 for ( var j in c ) {
\r
1934 if ( c[j].apply( this, args ) === false ) {
\r
1935 event.preventDefault();
\r
1936 event.stopPropagation();
\r
1937 returnValue = false;
\r
1941 // Clean up added properties in IE to prevent memory leak
\r
1942 if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = null;
\r
1944 return returnValue;
\r
1947 fix: function(event) {
\r
1949 if(jQuery.browser.msie) {
\r
1950 // fix target property, if available
\r
1951 // check prevents overwriting of fake target coming from trigger
\r
1952 if(event.srcElement)
\r
1953 event.target = event.srcElement;
\r
1955 // calculate pageX/Y
\r
1956 var e = document.documentElement, b = document.body;
\r
1957 event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft);
\r
1958 event.pageY = event.clientY + (e.scrollTop || b.scrollTop);
\r
1960 // check safari and if target is a textnode
\r
1961 } else if(jQuery.browser.safari && event.target.nodeType == 3) {
\r
1962 // target is readonly, clone the event object
\r
1963 event = jQuery.extend({}, event);
\r
1964 // get parentnode from textnode
\r
1965 event.target = event.target.parentNode;
\r
1968 // fix preventDefault and stopPropagation
\r
1969 if (!event.preventDefault)
\r
1970 event.preventDefault = function() {
\r
1971 this.returnValue = false;
\r
1974 if (!event.stopPropagation)
\r
1975 event.stopPropagation = function() {
\r
1976 this.cancelBubble = true;
\r
1985 * Contains flags for the useragent, read from navigator.userAgent.
\r
1986 * Available flags are: safari, opera, msie, mozilla
\r
1987 * This property is available before the DOM is ready, therefore you can
\r
1988 * use it to add ready events only for certain browsers.
\r
1990 * @example $.browser.msie
\r
1991 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
\r
1993 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
\r
1994 * @desc Alerts "this is safari!" only for safari browsers
\r
2003 * Wheather the W3C compliant box model is being used.
\r
2006 * @name $.boxModel
\r
2011 var b = navigator.userAgent.toLowerCase();
\r
2013 // Figure out what browser is being used
\r
2014 jQuery.browser = {
\r
2015 safari: /webkit/.test(b),
\r
2016 opera: /opera/.test(b),
\r
2017 msie: /msie/.test(b) && !/opera/.test(b),
\r
2018 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
\r
2021 // Check to see if the W3C box model is being used
\r
2022 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
\r
2028 * Append all of the matched elements to another, specified, set of elements.
\r
2029 * This operation is, essentially, the reverse of doing a regular
\r
2030 * $(A).append(B), in that instead of appending B to A, you're appending
\r
2033 * @example $("p").appendTo("#foo");
\r
2034 * @before <p>I would like to say: </p><div id="foo"></div>
\r
2035 * @result <div id="foo"><p>I would like to say: </p></div>
\r
2039 * @param String expr A jQuery expression of elements to match.
\r
2040 * @cat DOM/Manipulation
\r
2042 appendTo: "append",
\r
2045 * Prepend all of the matched elements to another, specified, set of elements.
\r
2046 * This operation is, essentially, the reverse of doing a regular
\r
2047 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
\r
2050 * @example $("p").prependTo("#foo");
\r
2051 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
\r
2052 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
\r
2056 * @param String expr A jQuery expression of elements to match.
\r
2057 * @cat DOM/Manipulation
\r
2059 prependTo: "prepend",
\r
2062 * Insert all of the matched elements before another, specified, set of elements.
\r
2063 * This operation is, essentially, the reverse of doing a regular
\r
2064 * $(A).before(B), in that instead of inserting B before A, you're inserting
\r
2067 * @example $("p").insertBefore("#foo");
\r
2068 * @before <div id="foo">Hello</div><p>I would like to say: </p>
\r
2069 * @result <p>I would like to say: </p><div id="foo">Hello</div>
\r
2071 * @name insertBefore
\r
2073 * @param String expr A jQuery expression of elements to match.
\r
2074 * @cat DOM/Manipulation
\r
2076 insertBefore: "before",
\r
2079 * Insert all of the matched elements after another, specified, set of elements.
\r
2080 * This operation is, essentially, the reverse of doing a regular
\r
2081 * $(A).after(B), in that instead of inserting B after A, you're inserting
\r
2084 * @example $("p").insertAfter("#foo");
\r
2085 * @before <p>I would like to say: </p><div id="foo">Hello</div>
\r
2086 * @result <div id="foo">Hello</div><p>I would like to say: </p>
\r
2088 * @name insertAfter
\r
2090 * @param String expr A jQuery expression of elements to match.
\r
2091 * @cat DOM/Manipulation
\r
2093 insertAfter: "after"
\r
2097 * Get the current CSS width of the first matched element.
\r
2099 * @example $("p").width();
\r
2100 * @before <p>This is just a test.</p>
\r
2109 * Set the CSS width of every matched element. Be sure to include
\r
2110 * the "px" (or other unit of measurement) after the number that you
\r
2111 * specify, otherwise you might get strange results.
\r
2113 * @example $("p").width("20px");
\r
2114 * @before <p>This is just a test.</p>
\r
2115 * @result <p style="width:20px;">This is just a test.</p>
\r
2119 * @param String val Set the CSS property to the specified value.
\r
2124 * Get the current CSS height of the first matched element.
\r
2126 * @example $("p").height();
\r
2127 * @before <p>This is just a test.</p>
\r
2136 * Set the CSS height of every matched element. Be sure to include
\r
2137 * the "px" (or other unit of measurement) after the number that you
\r
2138 * specify, otherwise you might get strange results.
\r
2140 * @example $("p").height("20px");
\r
2141 * @before <p>This is just a test.</p>
\r
2142 * @result <p style="height:20px;">This is just a test.</p>
\r
2146 * @param String val Set the CSS property to the specified value.
\r
2151 * Get the current CSS top of the first matched element.
\r
2153 * @example $("p").top();
\r
2154 * @before <p>This is just a test.</p>
\r
2163 * Set the CSS top of every matched element. Be sure to include
\r
2164 * the "px" (or other unit of measurement) after the number that you
\r
2165 * specify, otherwise you might get strange results.
\r
2167 * @example $("p").top("20px");
\r
2168 * @before <p>This is just a test.</p>
\r
2169 * @result <p style="top:20px;">This is just a test.</p>
\r
2173 * @param String val Set the CSS property to the specified value.
\r
2178 * Get the current CSS left of the first matched element.
\r
2180 * @example $("p").left();
\r
2181 * @before <p>This is just a test.</p>
\r
2190 * Set the CSS left of every matched element. Be sure to include
\r
2191 * the "px" (or other unit of measurement) after the number that you
\r
2192 * specify, otherwise you might get strange results.
\r
2194 * @example $("p").left("20px");
\r
2195 * @before <p>This is just a test.</p>
\r
2196 * @result <p style="left:20px;">This is just a test.</p>
\r
2200 * @param String val Set the CSS property to the specified value.
\r
2205 * Get the current CSS position of the first matched element.
\r
2207 * @example $("p").position();
\r
2208 * @before <p>This is just a test.</p>
\r
2209 * @result "static"
\r
2217 * Set the CSS position of every matched element.
\r
2219 * @example $("p").position("relative");
\r
2220 * @before <p>This is just a test.</p>
\r
2221 * @result <p style="position:relative;">This is just a test.</p>
\r
2225 * @param String val Set the CSS property to the specified value.
\r
2230 * Get the current CSS float of the first matched element.
\r
2232 * @example $("p").float();
\r
2233 * @before <p>This is just a test.</p>
\r
2242 * Set the CSS float of every matched element.
\r
2244 * @example $("p").float("left");
\r
2245 * @before <p>This is just a test.</p>
\r
2246 * @result <p style="float:left;">This is just a test.</p>
\r
2250 * @param String val Set the CSS property to the specified value.
\r
2255 * Get the current CSS overflow of the first matched element.
\r
2257 * @example $("p").overflow();
\r
2258 * @before <p>This is just a test.</p>
\r
2267 * Set the CSS overflow of every matched element.
\r
2269 * @example $("p").overflow("auto");
\r
2270 * @before <p>This is just a test.</p>
\r
2271 * @result <p style="overflow:auto;">This is just a test.</p>
\r
2275 * @param String val Set the CSS property to the specified value.
\r
2280 * Get the current CSS color of the first matched element.
\r
2282 * @example $("p").color();
\r
2283 * @before <p>This is just a test.</p>
\r
2292 * Set the CSS color of every matched element.
\r
2294 * @example $("p").color("blue");
\r
2295 * @before <p>This is just a test.</p>
\r
2296 * @result <p style="color:blue;">This is just a test.</p>
\r
2300 * @param String val Set the CSS property to the specified value.
\r
2305 * Get the current CSS background of the first matched element.
\r
2307 * @example $("p").background();
\r
2308 * @before <p style="background:blue;">This is just a test.</p>
\r
2311 * @name background
\r
2317 * Set the CSS background of every matched element.
\r
2319 * @example $("p").background("blue");
\r
2320 * @before <p>This is just a test.</p>
\r
2321 * @result <p style="background:blue;">This is just a test.</p>
\r
2323 * @name background
\r
2325 * @param String val Set the CSS property to the specified value.
\r
2329 css: "width,height,top,left,position,float,overflow,color,background".split(","),
\r
2332 * Reduce the set of matched elements to a single element.
\r
2333 * The position of the element in the set of matched elements
\r
2334 * starts at 0 and goes to length - 1.
\r
2336 * @example $("p").eq(1)
\r
2337 * @before <p>This is just a test.</p><p>So is this</p>
\r
2338 * @result [ <p>So is this</p> ]
\r
2342 * @param Number pos The index of the element that you wish to limit to.
\r
2347 * Reduce the set of matched elements to all elements before a given position.
\r
2348 * The position of the element in the set of matched elements
\r
2349 * starts at 0 and goes to length - 1.
\r
2351 * @example $("p").lt(1)
\r
2352 * @before <p>This is just a test.</p><p>So is this</p>
\r
2353 * @result [ <p>This is just a test.</p> ]
\r
2357 * @param Number pos Reduce the set to all elements below this position.
\r
2362 * Reduce the set of matched elements to all elements after a given position.
\r
2363 * The position of the element in the set of matched elements
\r
2364 * starts at 0 and goes to length - 1.
\r
2366 * @example $("p").gt(0)
\r
2367 * @before <p>This is just a test.</p><p>So is this</p>
\r
2368 * @result [ <p>So is this</p> ]
\r
2372 * @param Number pos Reduce the set to all elements after this position.
\r
2377 * Filter the set of elements to those that contain the specified text.
\r
2379 * @example $("p").contains("test")
\r
2380 * @before <p>This is just a test.</p><p>So is this</p>
\r
2381 * @result [ <p>This is just a test.</p> ]
\r
2385 * @param String str The string that will be contained within the text of an element.
\r
2386 * @cat DOM/Traversing
\r
2389 filter: [ "eq", "lt", "gt", "contains" ],
\r
2393 * Get the current value of the first matched element.
\r
2395 * @example $("input").val();
\r
2396 * @before <input type="text" value="some text"/>
\r
2397 * @result "some text"
\r
2401 * @cat DOM/Attributes
\r
2405 * Set the value of every matched element.
\r
2407 * @example $("input").val("test");
\r
2408 * @before <input type="text" value="some text"/>
\r
2409 * @result <input type="text" value="test"/>
\r
2413 * @param String val Set the property to the specified value.
\r
2414 * @cat DOM/Attributes
\r
2419 * Get the html contents of the first matched element.
\r
2421 * @example $("div").html();
\r
2422 * @before <div><input/></div>
\r
2423 * @result <input/>
\r
2427 * @cat DOM/Attributes
\r
2431 * Set the html contents of every matched element.
\r
2433 * @example $("div").html("<b>new stuff</b>");
\r
2434 * @before <div><input/></div>
\r
2435 * @result <div><b>new stuff</b></div>
\r
2439 * @param String val Set the html contents to the specified value.
\r
2440 * @cat DOM/Attributes
\r
2442 html: "innerHTML",
\r
2445 * Get the current id of the first matched element.
\r
2447 * @example $("input").id();
\r
2448 * @before <input type="text" id="test" value="some text"/>
\r
2453 * @cat DOM/Attributes
\r
2457 * Set the id of every matched element.
\r
2459 * @example $("input").id("newid");
\r
2460 * @before <input type="text" id="test" value="some text"/>
\r
2461 * @result <input type="text" id="newid" value="some text"/>
\r
2465 * @param String val Set the property to the specified value.
\r
2466 * @cat DOM/Attributes
\r
2471 * Get the current title of the first matched element.
\r
2473 * @example $("img").title();
\r
2474 * @before <img src="test.jpg" title="my image"/>
\r
2475 * @result "my image"
\r
2479 * @cat DOM/Attributes
\r
2483 * Set the title of every matched element.
\r
2485 * @example $("img").title("new title");
\r
2486 * @before <img src="test.jpg" title="my image"/>
\r
2487 * @result <img src="test.jpg" title="new image"/>
\r
2491 * @param String val Set the property to the specified value.
\r
2492 * @cat DOM/Attributes
\r
2497 * Get the current name of the first matched element.
\r
2499 * @example $("input").name();
\r
2500 * @before <input type="text" name="username"/>
\r
2501 * @result "username"
\r
2505 * @cat DOM/Attributes
\r
2509 * Set the name of every matched element.
\r
2511 * @example $("input").name("user");
\r
2512 * @before <input type="text" name="username"/>
\r
2513 * @result <input type="text" name="user"/>
\r
2517 * @param String val Set the property to the specified value.
\r
2518 * @cat DOM/Attributes
\r
2523 * Get the current href of the first matched element.
\r
2525 * @example $("a").href();
\r
2526 * @before <a href="test.html">my link</a>
\r
2527 * @result "test.html"
\r
2531 * @cat DOM/Attributes
\r
2535 * Set the href of every matched element.
\r
2537 * @example $("a").href("test2.html");
\r
2538 * @before <a href="test.html">my link</a>
\r
2539 * @result <a href="test2.html">my link</a>
\r
2543 * @param String val Set the property to the specified value.
\r
2544 * @cat DOM/Attributes
\r
2549 * Get the current src of the first matched element.
\r
2551 * @example $("img").src();
\r
2552 * @before <img src="test.jpg" title="my image"/>
\r
2553 * @result "test.jpg"
\r
2557 * @cat DOM/Attributes
\r
2561 * Set the src of every matched element.
\r
2563 * @example $("img").src("test2.jpg");
\r
2564 * @before <img src="test.jpg" title="my image"/>
\r
2565 * @result <img src="test2.jpg" title="my image"/>
\r
2569 * @param String val Set the property to the specified value.
\r
2570 * @cat DOM/Attributes
\r
2575 * Get the current rel of the first matched element.
\r
2577 * @example $("a").rel();
\r
2578 * @before <a href="test.html" rel="nofollow">my link</a>
\r
2579 * @result "nofollow"
\r
2583 * @cat DOM/Attributes
\r
2587 * Set the rel of every matched element.
\r
2589 * @example $("a").rel("nofollow");
\r
2590 * @before <a href="test.html">my link</a>
\r
2591 * @result <a href="test.html" rel="nofollow">my link</a>
\r
2595 * @param String val Set the property to the specified value.
\r
2596 * @cat DOM/Attributes
\r
2603 * Get a set of elements containing the unique parents of the matched
\r
2604 * set of elements.
\r
2606 * @example $("p").parent()
\r
2607 * @before <div><p>Hello</p><p>Hello</p></div>
\r
2608 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
\r
2612 * @cat DOM/Traversing
\r
2616 * Get a set of elements containing the unique parents of the matched
\r
2617 * set of elements, and filtered by an expression.
\r
2619 * @example $("p").parent(".selected")
\r
2620 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
\r
2621 * @result [ <div class="selected"><p>Hello Again</p></div> ]
\r
2625 * @param String expr An expression to filter the parents with
\r
2626 * @cat DOM/Traversing
\r
2628 parent: "a.parentNode",
\r
2631 * Get a set of elements containing the unique ancestors of the matched
\r
2632 * set of elements (except for the root element).
\r
2634 * @example $("span").ancestors()
\r
2635 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2636 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
\r
2640 * @cat DOM/Traversing
\r
2644 * Get a set of elements containing the unique ancestors of the matched
\r
2645 * set of elements, and filtered by an expression.
\r
2647 * @example $("span").ancestors("p")
\r
2648 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2649 * @result [ <p><span>Hello</span></p> ]
\r
2653 * @param String expr An expression to filter the ancestors with
\r
2654 * @cat DOM/Traversing
\r
2656 ancestors: jQuery.parents,
\r
2659 * Get a set of elements containing the unique ancestors of the matched
\r
2660 * set of elements (except for the root element).
\r
2662 * @example $("span").ancestors()
\r
2663 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2664 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
\r
2668 * @cat DOM/Traversing
\r
2672 * Get a set of elements containing the unique ancestors of the matched
\r
2673 * set of elements, and filtered by an expression.
\r
2675 * @example $("span").ancestors("p")
\r
2676 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2677 * @result [ <p><span>Hello</span></p> ]
\r
2681 * @param String expr An expression to filter the ancestors with
\r
2682 * @cat DOM/Traversing
\r
2684 parents: jQuery.parents,
\r
2687 * Get a set of elements containing the unique next siblings of each of the
\r
2688 * matched set of elements.
\r
2690 * It only returns the very next sibling, not all next siblings.
\r
2692 * @example $("p").next()
\r
2693 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
\r
2694 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
\r
2698 * @cat DOM/Traversing
\r
2702 * Get a set of elements containing the unique next siblings of each of the
\r
2703 * matched set of elements, and filtered by an expression.
\r
2705 * It only returns the very next sibling, not all next siblings.
\r
2707 * @example $("p").next(".selected")
\r
2708 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
\r
2709 * @result [ <p class="selected">Hello Again</p> ]
\r
2713 * @param String expr An expression to filter the next Elements with
\r
2714 * @cat DOM/Traversing
\r
2716 next: "jQuery.sibling(a).next",
\r
2719 * Get a set of elements containing the unique previous siblings of each of the
\r
2720 * matched set of elements.
\r
2722 * It only returns the immediately previous sibling, not all previous siblings.
\r
2724 * @example $("p").prev()
\r
2725 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
2726 * @result [ <div><span>Hello Again</span></div> ]
\r
2730 * @cat DOM/Traversing
\r
2734 * Get a set of elements containing the unique previous siblings of each of the
\r
2735 * matched set of elements, and filtered by an expression.
\r
2737 * It only returns the immediately previous sibling, not all previous siblings.
\r
2739 * @example $("p").prev(".selected")
\r
2740 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
\r
2741 * @result [ <div><span>Hello</span></div> ]
\r
2745 * @param String expr An expression to filter the previous Elements with
\r
2746 * @cat DOM/Traversing
\r
2748 prev: "jQuery.sibling(a).prev",
\r
2751 * Get a set of elements containing all of the unique siblings of each of the
\r
2752 * matched set of elements.
\r
2754 * @example $("div").siblings()
\r
2755 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
2756 * @result [ <p>Hello</p>, <p>And Again</p> ]
\r
2760 * @cat DOM/Traversing
\r
2764 * Get a set of elements containing all of the unique siblings of each of the
\r
2765 * matched set of elements, and filtered by an expression.
\r
2767 * @example $("div").siblings(".selected")
\r
2768 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
\r
2769 * @result [ <p class="selected">Hello Again</p> ]
\r
2773 * @param String expr An expression to filter the sibling Elements with
\r
2774 * @cat DOM/Traversing
\r
2776 siblings: "jQuery.sibling(a, null, true)",
\r
2780 * Get a set of elements containing all of the unique children of each of the
\r
2781 * matched set of elements.
\r
2783 * @example $("div").children()
\r
2784 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
2785 * @result [ <span>Hello Again</span> ]
\r
2789 * @cat DOM/Traversing
\r
2793 * Get a set of elements containing all of the unique children of each of the
\r
2794 * matched set of elements, and filtered by an expression.
\r
2796 * @example $("div").children(".selected")
\r
2797 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
\r
2798 * @result [ <p class="selected">Hello Again</p> ]
\r
2802 * @param String expr An expression to filter the child Elements with
\r
2803 * @cat DOM/Traversing
\r
2805 children: "jQuery.sibling(a.firstChild)"
\r
2811 * Remove an attribute from each of the matched elements.
\r
2813 * @example $("input").removeAttr("disabled")
\r
2814 * @before <input disabled="disabled"/>
\r
2815 * @result <input/>
\r
2817 * @name removeAttr
\r
2819 * @param String name The name of the attribute to remove.
\r
2822 removeAttr: function( key ) {
\r
2823 jQuery.attr( this, key, "" );
\r
2824 this.removeAttribute( key );
\r
2828 * Displays each of the set of matched elements if they are hidden.
\r
2830 * @example $("p").show()
\r
2831 * @before <p style="display: none">Hello</p>
\r
2832 * @result [ <p style="display: block">Hello</p> ]
\r
2839 this.style.display = this.oldblock ? this.oldblock : "";
\r
2840 if ( jQuery.css(this,"display") == "none" )
\r
2841 this.style.display = "block";
\r
2845 * Hides each of the set of matched elements if they are shown.
\r
2847 * @example $("p").hide()
\r
2848 * @before <p>Hello</p>
\r
2849 * @result [ <p style="display: none">Hello</p> ]
\r
2851 * var pass = true, div = $("div");
\r
2852 * div.hide().each(function(){
\r
2853 * if ( this.style.display != "none" ) pass = false;
\r
2855 * ok( pass, "Hide" );
\r
2862 this.oldblock = this.oldblock || jQuery.css(this,"display");
\r
2863 if ( this.oldblock == "none" )
\r
2864 this.oldblock = "block";
\r
2865 this.style.display = "none";
\r
2869 * Toggles each of the set of matched elements. If they are shown,
\r
2870 * toggle makes them hidden. If they are hidden, toggle
\r
2871 * makes them shown.
\r
2873 * @example $("p").toggle()
\r
2874 * @before <p>Hello</p><p style="display: none">Hello Again</p>
\r
2875 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
\r
2881 toggle: function(){
\r
2882 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
\r
2886 * Adds the specified class to each of the set of matched elements.
\r
2888 * @example $("p").addClass("selected")
\r
2889 * @before <p>Hello</p>
\r
2890 * @result [ <p class="selected">Hello</p> ]
\r
2894 * @param String class A CSS class to add to the elements
\r
2897 addClass: function(c){
\r
2898 jQuery.className.add(this,c);
\r
2902 * Removes the specified class from the set of matched elements.
\r
2904 * @example $("p").removeClass("selected")
\r
2905 * @before <p class="selected">Hello</p>
\r
2906 * @result [ <p>Hello</p> ]
\r
2908 * @name removeClass
\r
2910 * @param String class A CSS class to remove from the elements
\r
2913 removeClass: function(c){
\r
2914 jQuery.className.remove(this,c);
\r
2918 * Adds the specified class if it is not present, removes it if it is
\r
2921 * @example $("p").toggleClass("selected")
\r
2922 * @before <p>Hello</p><p class="selected">Hello Again</p>
\r
2923 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
\r
2925 * @name toggleClass
\r
2927 * @param String class A CSS class with which to toggle the elements
\r
2930 toggleClass: function( c ){
\r
2931 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
\r
2935 * Removes all matched elements from the DOM. This does NOT remove them from the
\r
2936 * jQuery object, allowing you to use the matched elements further.
\r
2938 * @example $("p").remove();
\r
2939 * @before <p>Hello</p> how are <p>you?</p>
\r
2944 * @cat DOM/Manipulation
\r
2948 * Removes only elements (out of the list of matched elements) that match
\r
2949 * the specified jQuery expression. This does NOT remove them from the
\r
2950 * jQuery object, allowing you to use the matched elements further.
\r
2952 * @example $("p").remove(".hello");
\r
2953 * @before <p class="hello">Hello</p> how are <p>you?</p>
\r
2954 * @result how are <p>you?</p>
\r
2958 * @param String expr A jQuery expression to filter elements by.
\r
2959 * @cat DOM/Manipulation
\r
2961 remove: function(a){
\r
2962 if ( !a || jQuery.filter( a, [this] ).r )
\r
2963 this.parentNode.removeChild( this );
\r
2967 * Removes all child nodes from the set of matched elements.
\r
2969 * @example $("p").empty()
\r
2970 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
\r
2971 * @result [ <p></p> ]
\r
2975 * @cat DOM/Manipulation
\r
2977 empty: function(){
\r
2978 while ( this.firstChild )
\r
2979 this.removeChild( this.firstChild );
\r
2983 * Binds a handler to a particular event (like click) for each matched element.
\r
2984 * The event handler is passed an event object that you can use to prevent
\r
2985 * default behaviour. To stop both default action and event bubbling, your handler
\r
2986 * has to return false.
\r
2988 * @example $("p").bind( "click", function() {
\r
2989 * alert( $(this).text() );
\r
2991 * @before <p>Hello</p>
\r
2992 * @result alert("Hello")
\r
2994 * @example $("form").bind( "submit", function() { return false; } )
\r
2995 * @desc Cancel a default action and prevent it from bubbling by returning false
\r
2996 * from your function.
\r
2998 * @example $("form").bind( "submit", function(event) {
\r
2999 * event.preventDefault();
\r
3001 * @desc Cancel only the default action by using the preventDefault method.
\r
3004 * @example $("form").bind( "submit", function(event) {
\r
3005 * event.stopPropagation();
\r
3007 * @desc Stop only an event from bubbling by using the stopPropagation method.
\r
3011 * @param String type An event type
\r
3012 * @param Function fn A function to bind to the event on each of the set of matched elements
\r
3015 bind: function( type, fn ) {
\r
3016 jQuery.event.add( this, type, fn );
\r
3020 * The opposite of bind, removes a bound event from each of the matched
\r
3021 * elements. You must pass the identical function that was used in the original
\r
3024 * @example $("p").unbind( "click", function() { alert("Hello"); } )
\r
3025 * @before <p onclick="alert('Hello');">Hello</p>
\r
3026 * @result [ <p>Hello</p> ]
\r
3030 * @param String type An event type
\r
3031 * @param Function fn A function to unbind from the event on each of the set of matched elements
\r
3036 * Removes all bound events of a particular type from each of the matched
\r
3039 * @example $("p").unbind( "click" )
\r
3040 * @before <p onclick="alert('Hello');">Hello</p>
\r
3041 * @result [ <p>Hello</p> ]
\r
3045 * @param String type An event type
\r
3050 * Removes all bound events from each of the matched elements.
\r
3052 * @example $("p").unbind()
\r
3053 * @before <p onclick="alert('Hello');">Hello</p>
\r
3054 * @result [ <p>Hello</p> ]
\r
3060 unbind: function( type, fn ) {
\r
3061 jQuery.event.remove( this, type, fn );
\r
3065 * Trigger a type of event on every matched element.
\r
3067 * @example $("p").trigger("click")
\r
3068 * @before <p click="alert('hello')">Hello</p>
\r
3069 * @result alert('hello')
\r
3073 * @param String type An event type to trigger.
\r
3076 trigger: function( type, data ) {
\r
3077 jQuery.event.trigger( type, data, this );
\r