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 * Note that you can't set the name property of input elements in IE.
\r
371 * Use $(html) or $().append(html) or $().html(html) to create elements
\r
372 * on the fly including the name property.
\r
374 * @example $("img").attr("src","test.jpg");
\r
376 * @result <img src="test.jpg"/>
\r
380 * @param String key The name of the property to set.
\r
381 * @param Object value The value to set the property to.
\r
384 attr: function( key, value, type ) {
\r
385 // Check to see if we're setting style values
\r
386 return key.constructor != String || value != undefined ?
\r
387 this.each(function(){
\r
388 // See if we're setting a hash of styles
\r
389 if ( value == undefined )
\r
390 // Set all the styles
\r
391 for ( var prop in key )
\r
393 type ? this.style : this,
\r
397 // See if we're setting a single key/value style
\r
400 type ? this.style : this,
\r
405 // Look for the case where we're accessing a style value
\r
406 jQuery[ type || "attr" ]( this[0], key );
\r
410 * Access a style property on the first matched element.
\r
411 * This method makes it easy to retrieve a style property value
\r
412 * from the first matched element.
\r
414 * @example $("p").css("color");
\r
415 * @before <p style="color:red;">Test Paragraph.</p>
\r
417 * @desc Retrieves the color style of the first paragraph
\r
419 * @example $("p").css("fontWeight");
\r
420 * @before <p style="font-weight: bold;">Test Paragraph.</p>
\r
422 * @desc Retrieves the font-weight style of the first paragraph.
\r
423 * Note that for all style properties with a dash (like 'font-weight'), you have to
\r
424 * write it in camelCase. In other words: Every time you have a '-' in a
\r
425 * property, remove it and replace the next character with an uppercase
\r
426 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
\r
427 * borderStyle, borderBottomWidth etc.
\r
431 * @param String name The name of the property to access.
\r
436 * Set a hash of key/value style properties to all matched elements.
\r
437 * This serves as the best way to set a large number of style properties
\r
438 * on all matched elements.
\r
440 * @example $("p").css({ color: "red", background: "blue" });
\r
441 * @before <p>Test Paragraph.</p>
\r
442 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
\r
446 * @param Hash prop A set of key/value pairs to set as style properties.
\r
451 * Set a single style property to a value, on all matched elements.
\r
453 * @example $("p").css("color","red");
\r
454 * @before <p>Test Paragraph.</p>
\r
455 * @result <p style="color:red;">Test Paragraph.</p>
\r
456 * @desc Changes the color of all paragraphs to red
\r
460 * @param String key The name of the property to set.
\r
461 * @param Object value The value to set the property to.
\r
464 css: function( key, value ) {
\r
465 return this.attr( key, value, "curCSS" );
\r
469 * Retrieve the text contents of all matched elements. The result is
\r
470 * a string that contains the combined text contents of all matched
\r
471 * elements. This method works on both HTML and XML documents.
\r
473 * @example $("p").text();
\r
474 * @before <p>Test Paragraph.</p>
\r
475 * @result Test Paragraph.
\r
481 text: function(e) {
\r
484 for ( var j = 0; j < e.length; j++ ) {
\r
485 var r = e[j].childNodes;
\r
486 for ( var i = 0; i < r.length; i++ )
\r
487 if ( r[i].nodeType != 8 )
\r
488 t += r[i].nodeType != 1 ?
\r
489 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
\r
495 * Wrap all matched elements with a structure of other elements.
\r
496 * This wrapping process is most useful for injecting additional
\r
497 * stucture into a document, without ruining the original semantic
\r
498 * qualities of a document.
\r
500 * This works by going through the first element
\r
501 * provided (which is generated, on the fly, from the provided HTML)
\r
502 * and finds the deepest ancestor element within its
\r
503 * structure - it is that element that will en-wrap everything else.
\r
505 * This does not work with elements that contain text. Any necessary text
\r
506 * must be added after the wrapping is done.
\r
508 * @example $("p").wrap("<div class='wrap'></div>");
\r
509 * @before <p>Test Paragraph.</p>
\r
510 * @result <div class='wrap'><p>Test Paragraph.</p></div>
\r
514 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
\r
515 * @cat DOM/Manipulation
\r
519 * Wrap all matched elements with a structure of other elements.
\r
520 * This wrapping process is most useful for injecting additional
\r
521 * stucture into a document, without ruining the original semantic
\r
522 * qualities of a document.
\r
524 * This works by going through the first element
\r
525 * provided and finding the deepest ancestor element within its
\r
526 * structure - it is that element that will en-wrap everything else.
\r
528 * This does not work with elements that contain text. Any necessary text
\r
529 * must be added after the wrapping is done.
\r
531 * @example $("p").wrap( document.getElementById('content') );
\r
532 * @before <p>Test Paragraph.</p><div id="content"></div>
\r
533 * @result <div id="content"><p>Test Paragraph.</p></div>
\r
537 * @param Element elem A DOM element that will be wrapped.
\r
538 * @cat DOM/Manipulation
\r
541 // The elements to wrap the target around
\r
542 var a = jQuery.clean(arguments);
\r
544 // Wrap each of the matched elements individually
\r
545 return this.each(function(){
\r
546 // Clone the structure that we're using to wrap
\r
547 var b = a[0].cloneNode(true);
\r
549 // Insert it before the element to be wrapped
\r
550 this.parentNode.insertBefore( b, this );
\r
552 // Find the deepest point in the wrap structure
\r
553 while ( b.firstChild )
\r
556 // Move the matched element to within the wrap structure
\r
557 b.appendChild( this );
\r
562 * Append any number of elements to the inside of every matched elements,
\r
563 * generated from the provided HTML.
\r
564 * This operation is similar to doing an appendChild to all the
\r
565 * specified elements, adding them into the document.
\r
567 * @example $("p").append("<b>Hello</b>");
\r
568 * @before <p>I would like to say: </p>
\r
569 * @result <p>I would like to say: <b>Hello</b></p>
\r
573 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
574 * @cat DOM/Manipulation
\r
578 * Append an element to the inside of all matched elements.
\r
579 * This operation is similar to doing an appendChild to all the
\r
580 * specified elements, adding them into the document.
\r
582 * @example $("p").append( $("#foo")[0] );
\r
583 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
584 * @result <p>I would like to say: <b id="foo">Hello</b></p>
\r
588 * @param Element elem A DOM element that will be appended.
\r
589 * @cat DOM/Manipulation
\r
593 * Append any number of elements to the inside of all matched elements.
\r
594 * This operation is similar to doing an appendChild to all the
\r
595 * specified elements, adding them into the document.
\r
597 * @example $("p").append( $("b") );
\r
598 * @before <p>I would like to say: </p><b>Hello</b>
\r
599 * @result <p>I would like to say: <b>Hello</b></p>
\r
603 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
604 * @cat DOM/Manipulation
\r
606 append: function() {
\r
607 return this.domManip(arguments, true, 1, function(a){
\r
608 this.appendChild( a );
\r
613 * Prepend any number of elements to the inside of every matched elements,
\r
614 * generated from the provided HTML.
\r
615 * This operation is the best way to insert dynamically created elements
\r
616 * inside, at the beginning, of all the matched element.
\r
618 * @example $("p").prepend("<b>Hello</b>");
\r
619 * @before <p>I would like to say: </p>
\r
620 * @result <p><b>Hello</b>I would like to say: </p>
\r
624 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
625 * @cat DOM/Manipulation
\r
629 * Prepend an element to the inside of all matched elements.
\r
630 * This operation is the best way to insert an element inside, at the
\r
631 * beginning, of all the matched element.
\r
633 * @example $("p").prepend( $("#foo")[0] );
\r
634 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
635 * @result <p><b id="foo">Hello</b>I would like to say: </p>
\r
639 * @param Element elem A DOM element that will be appended.
\r
640 * @cat DOM/Manipulation
\r
644 * Prepend any number of elements to the inside of all matched elements.
\r
645 * This operation is the best way to insert a set of elements inside, at the
\r
646 * beginning, of all the matched element.
\r
648 * @example $("p").prepend( $("b") );
\r
649 * @before <p>I would like to say: </p><b>Hello</b>
\r
650 * @result <p><b>Hello</b>I would like to say: </p>
\r
654 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
655 * @cat DOM/Manipulation
\r
657 prepend: function() {
\r
658 return this.domManip(arguments, true, -1, function(a){
\r
659 this.insertBefore( a, this.firstChild );
\r
664 * Insert any number of dynamically generated elements before each of the
\r
665 * matched elements.
\r
667 * @example $("p").before("<b>Hello</b>");
\r
668 * @before <p>I would like to say: </p>
\r
669 * @result <b>Hello</b><p>I would like to say: </p>
\r
673 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
674 * @cat DOM/Manipulation
\r
678 * Insert an element before each of the matched elements.
\r
680 * @example $("p").before( $("#foo")[0] );
\r
681 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
682 * @result <b id="foo">Hello</b><p>I would like to say: </p>
\r
686 * @param Element elem A DOM element that will be appended.
\r
687 * @cat DOM/Manipulation
\r
691 * Insert any number of elements before each of the matched elements.
\r
693 * @example $("p").before( $("b") );
\r
694 * @before <p>I would like to say: </p><b>Hello</b>
\r
695 * @result <b>Hello</b><p>I would like to say: </p>
\r
699 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
700 * @cat DOM/Manipulation
\r
702 before: function() {
\r
703 return this.domManip(arguments, false, 1, function(a){
\r
704 this.parentNode.insertBefore( a, this );
\r
709 * Insert any number of dynamically generated elements after each of the
\r
710 * matched elements.
\r
712 * @example $("p").after("<b>Hello</b>");
\r
713 * @before <p>I would like to say: </p>
\r
714 * @result <p>I would like to say: </p><b>Hello</b>
\r
718 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
719 * @cat DOM/Manipulation
\r
723 * Insert an element after each of the matched elements.
\r
725 * @example $("p").after( $("#foo")[0] );
\r
726 * @before <b id="foo">Hello</b><p>I would like to say: </p>
\r
727 * @result <p>I would like to say: </p><b id="foo">Hello</b>
\r
731 * @param Element elem A DOM element that will be appended.
\r
732 * @cat DOM/Manipulation
\r
736 * Insert any number of elements after each of the matched elements.
\r
738 * @example $("p").after( $("b") );
\r
739 * @before <b>Hello</b><p>I would like to say: </p>
\r
740 * @result <p>I would like to say: </p><b>Hello</b>
\r
744 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
745 * @cat DOM/Manipulation
\r
747 after: function() {
\r
748 return this.domManip(arguments, false, -1, function(a){
\r
749 this.parentNode.insertBefore( a, this.nextSibling );
\r
754 * End the most recent 'destructive' operation, reverting the list of matched elements
\r
755 * back to its previous state. After an end operation, the list of matched elements will
\r
756 * revert to the last state of matched elements.
\r
758 * @example $("p").find("span").end();
\r
759 * @before <p><span>Hello</span>, how are you?</p>
\r
760 * @result $("p").find("span").end() == [ <p>...</p> ]
\r
764 * @cat DOM/Traversing
\r
767 if( !(this.stack && this.stack.length) )
\r
769 return this.set( this.stack.pop() );
\r
773 * Searches for all elements that match the specified expression.
\r
774 * This method is the optimal way of finding additional descendant
\r
775 * elements with which to process.
\r
777 * All searching is done using a jQuery expression. The expression can be
\r
778 * written using CSS 1-3 Selector syntax, or basic XPath.
\r
780 * @example $("p").find("span");
\r
781 * @before <p><span>Hello</span>, how are you?</p>
\r
782 * @result $("p").find("span") == [ <span>Hello</span> ]
\r
786 * @param String expr An expression to search with.
\r
787 * @cat DOM/Traversing
\r
789 find: function(t) {
\r
790 return this.pushStack( jQuery.map( this, function(a){
\r
791 return jQuery.find(t,a);
\r
796 * Create cloned copies of all matched DOM Elements. This does
\r
797 * not create a cloned copy of this particular jQuery object,
\r
798 * instead it creates duplicate copies of all DOM Elements.
\r
799 * This is useful for moving copies of the elements to another
\r
800 * location in the DOM.
\r
802 * @example $("b").clone().prependTo("p");
\r
803 * @before <b>Hello</b><p>, how are you?</p>
\r
804 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
\r
808 * @cat DOM/Manipulation
\r
810 clone: function(deep) {
\r
811 return this.pushStack( jQuery.map( this, function(a){
\r
812 return a.cloneNode( deep != undefined ? deep : true );
\r
817 * Removes all elements from the set of matched elements that do not
\r
818 * match the specified expression. This method is used to narrow down
\r
819 * the results of a search.
\r
821 * All searching is done using a jQuery expression. The expression
\r
822 * can be written using CSS 1-3 Selector syntax, or basic XPath.
\r
824 * @example $("p").filter(".selected")
\r
825 * @before <p class="selected">Hello</p><p>How are you?</p>
\r
826 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
\r
830 * @param String expr An expression to search with.
\r
831 * @cat DOM/Traversing
\r
835 * Removes all elements from the set of matched elements that do not
\r
836 * match at least one of the expressions passed to the function. This
\r
837 * method is used when you want to filter the set of matched elements
\r
838 * through more than one expression.
\r
840 * Elements will be retained in the jQuery object if they match at
\r
841 * least one of the expressions passed.
\r
843 * @example $("p").filter([".selected", ":first"])
\r
844 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
\r
845 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
\r
849 * @param Array<String> exprs A set of expressions to evaluate against
\r
850 * @cat DOM/Traversing
\r
852 filter: function(t) {
\r
853 return this.pushStack(
\r
854 t.constructor == Array &&
\r
855 jQuery.map(this,function(a){
\r
856 for ( var i = 0; i < t.length; i++ )
\r
857 if ( jQuery.filter(t[i],[a]).r.length )
\r
862 t.constructor == Boolean &&
\r
863 ( t ? this.get() : [] ) ||
\r
865 typeof t == "function" &&
\r
866 jQuery.grep( this, t ) ||
\r
868 jQuery.filter(t,this).r );
\r
872 * Removes the specified Element from the set of matched elements. This
\r
873 * method is used to remove a single Element from a jQuery object.
\r
875 * @example $("p").not( document.getElementById("selected") )
\r
876 * @before <p>Hello</p><p id="selected">Hello Again</p>
\r
877 * @result [ <p>Hello</p> ]
\r
881 * @param Element el An element to remove from the set
\r
882 * @cat DOM/Traversing
\r
886 * Removes elements matching the specified expression from the set
\r
887 * of matched elements. This method is used to remove one or more
\r
888 * elements from a jQuery object.
\r
890 * @example $("p").not("#selected")
\r
891 * @before <p>Hello</p><p id="selected">Hello Again</p>
\r
892 * @result [ <p>Hello</p> ]
\r
896 * @param String expr An expression with which to remove matching elements
\r
897 * @cat DOM/Traversing
\r
900 return this.pushStack( typeof t == "string" ?
\r
901 jQuery.filter(t,this,false).r :
\r
902 jQuery.grep(this,function(a){ return a != t; }) );
\r
906 * Adds the elements matched by the expression to the jQuery object. This
\r
907 * can be used to concatenate the result sets of two expressions.
\r
909 * @example $("p").add("span")
\r
910 * @before <p>Hello</p><p><span>Hello Again</span></p>
\r
911 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
\r
915 * @param String expr An expression whose matched elements are added
\r
916 * @cat DOM/Traversing
\r
920 * Adds each of the Elements in the array to the set of matched elements.
\r
921 * This is used to add a set of Elements to a jQuery object.
\r
923 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
\r
924 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
\r
925 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
\r
929 * @param Array<Element> els An array of Elements to add
\r
930 * @cat DOM/Traversing
\r
934 * Adds a single Element to the set of matched elements. This is used to
\r
935 * add a single Element to a jQuery object.
\r
937 * @example $("p").add( document.getElementById("a") )
\r
938 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
\r
939 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
\r
943 * @param Element el An Element to add
\r
944 * @cat DOM/Traversing
\r
947 return this.pushStack( jQuery.merge( this, typeof t == "string" ?
\r
948 jQuery.find(t) : t.constructor == Array ? t : [t] ) );
\r
952 * Checks the current selection against an expression and returns true,
\r
953 * if at least one element of the selection fits the given expression.
\r
954 * Does return false, if no element fits or the expression is not valid.
\r
956 * @example $("input[@type='checkbox']").parent().is("form")
\r
957 * @before <form><input type="checkbox" /></form>
\r
959 * @desc Returns true, because the parent of the input is a form element
\r
961 * @example $("input[@type='checkbox']").parent().is("form")
\r
962 * @before <form><p><input type="checkbox" /></p></form>
\r
964 * @desc Returns false, because the parent of the input is a p element
\r
966 * @example $("form").is(null)
\r
967 * @before <form></form>
\r
969 * @desc An invalid expression always returns false.
\r
973 * @param String expr The expression with which to filter
\r
974 * @cat DOM/Traversing
\r
976 is: function(expr) {
\r
977 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
\r
983 * @param Array args
\r
984 * @param Boolean table
\r
985 * @param Number dir
\r
986 * @param Function fn The function doing the DOM manipulation.
\r
990 domManip: function(args, table, dir, fn){
\r
991 var clone = this.size() > 1;
\r
992 var a = jQuery.clean(args);
\r
994 return this.each(function(){
\r
997 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
\r
998 var tbody = this.getElementsByTagName("tbody");
\r
1000 if ( !tbody.length ) {
\r
1001 obj = document.createElement("tbody");
\r
1002 this.appendChild( obj );
\r
1007 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
\r
1008 i != ( dir < 0 ? dir : a.length ); i += dir ) {
\r
1009 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
\r
1020 * @param Array args
\r
1024 pushStack: function(a) {
\r
1025 if ( !this.stack )
\r
1027 this.stack.push( this.get() );
\r
1028 return this.set( a );
\r
1033 * Extends the jQuery object itself. Can be used to add functions into
\r
1034 * the jQuery namespace and to add plugin methods (plugins).
\r
1036 * @example jQuery.fn.extend({
\r
1037 * check: function() {
\r
1038 * return this.each(function() { this.checked = true; });
\r
1040 * uncheck: function() {
\r
1041 * return this.each(function() { this.checked = false; });
\r
1044 * $("input[@type=checkbox]").check();
\r
1045 * $("input[@type=radio]").uncheck();
\r
1046 * @desc Adds two plugin methods.
\r
1048 * @example jQuery.extend({
\r
1049 * min: function(a, b) { return a < b ? a : b; },
\r
1050 * max: function(a, b) { return a > b ? a : b; }
\r
1052 * @desc Adds two functions into the jQuery namespace
\r
1055 * @param Object prop The object that will be merged into the jQuery object
\r
1061 * Extend one object with one or more others, returning the original,
\r
1062 * modified, object. This is a great utility for simple inheritance.
\r
1064 * @example var settings = { validate: false, limit: 5, name: "foo" };
\r
1065 * var options = { validate: true, name: "bar" };
\r
1066 * jQuery.extend(settings, options);
\r
1067 * @result settings == { validate: true, limit: 5, name: "bar" }
\r
1068 * @desc Merge settings and options, modifying settings
\r
1070 * @example var defaults = { validate: false, limit: 5, name: "foo" };
\r
1071 * var options = { validate: true, name: "bar" };
\r
1072 * var settings = jQuery.extend({}, defaults, options);
\r
1073 * @result settings == { validate: true, limit: 5, name: "bar" }
\r
1074 * @desc Merge defaults and options, without modifying the defaults
\r
1077 * @param Object target The object to extend
\r
1078 * @param Object prop1 The object that will be merged into the first.
\r
1079 * @param Object propN (optional) More objects to merge into the first
\r
1083 jQuery.extend = jQuery.fn.extend = function() {
\r
1084 // copy reference to target object
\r
1085 var target = arguments[0],
\r
1088 // extend jQuery itself if only one argument is passed
\r
1089 if ( arguments.length == 1 ) {
\r
1094 while (prop = arguments[a++])
\r
1095 // Extend the base object
\r
1096 for ( var i in prop ) target[i] = prop[i];
\r
1098 // Return the modified object
\r
1110 jQuery.initDone = true;
\r
1112 jQuery.each( jQuery.macros.axis, function(i,n){
\r
1113 jQuery.fn[ i ] = function(a) {
\r
1114 var ret = jQuery.map(this,n);
\r
1115 if ( a && typeof a == "string" )
\r
1116 ret = jQuery.filter(a,ret).r;
\r
1117 return this.pushStack( ret, arguments );
\r
1121 jQuery.each( jQuery.macros.to, function(i,n){
\r
1122 jQuery.fn[ i ] = function(){
\r
1123 var a = arguments;
\r
1124 return this.each(function(){
\r
1125 for ( var j = 0; j < a.length; j++ )
\r
1126 jQuery(a[j])[n]( this );
\r
1131 jQuery.each( jQuery.macros.each, function(i,n){
\r
1132 jQuery.fn[ i ] = function() {
\r
1133 return this.each( n, arguments );
\r
1137 jQuery.each( jQuery.macros.filter, function(i,n){
\r
1138 jQuery.fn[ n ] = function(num,fn) {
\r
1139 return this.filter( ":" + n + "(" + num + ")", fn );
\r
1143 jQuery.each( jQuery.macros.attr, function(i,n){
\r
1145 jQuery.fn[ i ] = function(h) {
\r
1146 return h == undefined ?
\r
1147 this.length ? this[0][n] : null :
\r
1148 this.attr( n, h );
\r
1152 jQuery.each( jQuery.macros.css, function(i,n){
\r
1153 jQuery.fn[ n ] = function(h) {
\r
1154 return h == undefined ?
\r
1155 ( this.length ? jQuery.css( this[0], n ) : null ) :
\r
1163 * A generic iterator function, which can be used to seemlessly
\r
1164 * iterate over both objects and arrays. This function is not the same
\r
1165 * as $().each() - which is used to iterate, exclusively, over a jQuery
\r
1166 * object. This function can be used to iterate over anything.
\r
1168 * @example $.each( [0,1,2], function(i){
\r
1169 * alert( "Item #" + i + ": " + this );
\r
1171 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
\r
1173 * @example $.each( { name: "John", lang: "JS" }, function(i){
\r
1174 * alert( "Name: " + i + ", Value: " + this );
\r
1176 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
\r
1179 * @param Object obj The object, or array, to iterate over.
\r
1180 * @param Function fn The function that will be executed on every object.
\r
1184 // args is for internal usage only
\r
1185 each: function( obj, fn, args ) {
\r
1186 if ( obj.length == undefined )
\r
1187 for ( var i in obj )
\r
1188 fn.apply( obj[i], args || [i, obj[i]] );
\r
1190 for ( var i = 0; i < obj.length; i++ )
\r
1191 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
\r
1196 add: function(o,c){
\r
1197 if (jQuery.className.has(o,c)) return;
\r
1198 o.className += ( o.className ? " " : "" ) + c;
\r
1200 remove: function(o,c){
\r
1204 var classes = o.className.split(" ");
\r
1205 for(var i=0; i<classes.length; i++) {
\r
1206 if(classes[i] == c) {
\r
1207 classes.splice(i, 1);
\r
1211 o.className = classes.join(' ');
\r
1214 has: function(e,a) {
\r
1215 if ( e.className != undefined )
\r
1217 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
\r
1222 * Swap in/out style options.
\r
1225 swap: function(e,o,f) {
\r
1226 for ( var i in o ) {
\r
1227 e.style["old"+i] = e.style[i];
\r
1228 e.style[i] = o[i];
\r
1231 for ( var i in o )
\r
1232 e.style[i] = e.style["old"+i];
\r
1235 css: function(e,p) {
\r
1236 if ( p == "height" || p == "width" ) {
\r
1237 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
\r
1239 for ( var i=0; i<d.length; i++ ) {
\r
1240 old["padding" + d[i]] = 0;
\r
1241 old["border" + d[i] + "Width"] = 0;
\r
1244 jQuery.swap( e, old, function() {
\r
1245 if (jQuery.css(e,"display") != "none") {
\r
1246 oHeight = e.offsetHeight;
\r
1247 oWidth = e.offsetWidth;
\r
1249 e = jQuery(e.cloneNode(true))
\r
1250 .find(":radio").removeAttr("checked").end()
\r
1252 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
\r
1253 }).appendTo(e.parentNode)[0];
\r
1255 var parPos = jQuery.css(e.parentNode,"position");
\r
1256 if ( parPos == "" || parPos == "static" )
\r
1257 e.parentNode.style.position = "relative";
\r
1259 oHeight = e.clientHeight;
\r
1260 oWidth = e.clientWidth;
\r
1262 if ( parPos == "" || parPos == "static" )
\r
1263 e.parentNode.style.position = "static";
\r
1265 e.parentNode.removeChild(e);
\r
1269 return p == "height" ? oHeight : oWidth;
\r
1272 return jQuery.curCSS( e, p );
\r
1275 curCSS: function(elem, prop, force) {
\r
1278 if (prop == 'opacity' && jQuery.browser.msie)
\r
1279 return jQuery.attr(elem.style, 'opacity');
\r
1281 if (prop == "float" || prop == "cssFloat")
\r
1282 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
\r
1284 if (!force && elem.style[prop]) {
\r
1286 ret = elem.style[prop];
\r
1288 } else if (elem.currentStyle) {
\r
1290 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
\r
1291 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
\r
1293 } else if (document.defaultView && document.defaultView.getComputedStyle) {
\r
1295 if (prop == "cssFloat" || prop == "styleFloat")
\r
1298 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
\r
1299 var cur = document.defaultView.getComputedStyle(elem, null);
\r
1302 ret = cur.getPropertyValue(prop);
\r
1303 else if ( prop == 'display' )
\r
1306 jQuery.swap(elem, { display: 'block' }, function() {
\r
1307 var c = document.defaultView.getComputedStyle(this, '');
\r
1308 ret = c && c.getPropertyValue(prop) || '';
\r
1316 clean: function(a) {
\r
1318 for ( var i = 0; i < a.length; i++ ) {
\r
1320 if ( typeof arg == "string" ) { // Convert html string into DOM nodes
\r
1321 // Trim whitespace, otherwise indexOf won't work as expected
\r
1322 var s = jQuery.trim(arg), div = document.createElement("div"), wrap = [0,"",""];
\r
1324 if ( !s.indexOf("<opt") ) // option or optgroup
\r
1325 wrap = [1, "<select>", "</select>"];
\r
1326 else if ( !s.indexOf("<thead") || !s.indexOf("<tbody") )
\r
1327 wrap = [1, "<table>", "</table>"];
\r
1328 else if ( !s.indexOf("<tr") )
\r
1329 wrap = [2, "<table>", "</table>"]; // tbody auto-inserted
\r
1330 else if ( !s.indexOf("<td") || !s.indexOf("<th") )
\r
1331 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
\r
1333 // Go to html and back, then peel off extra wrappers
\r
1334 div.innerHTML = wrap[1] + s + wrap[2];
\r
1335 while ( wrap[0]-- ) div = div.firstChild;
\r
1336 arg = div.childNodes;
\r
1340 if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
\r
1341 for ( var n = 0; n < arg.length; n++ ) // Handles Array, jQuery, DOM NodeList collections
\r
1344 r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
\r
1351 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
\r
1352 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
\r
1354 // Position Checks
\r
1360 last: "i==r.length-1",
\r
1365 "nth-child": "jQuery.sibling(a,m[3]).cur",
\r
1366 "first-child": "jQuery.sibling(a,0).cur",
\r
1367 "last-child": "jQuery.sibling(a,0).last",
\r
1368 "only-child": "jQuery.sibling(a).length==1",
\r
1371 parent: "a.childNodes.length",
\r
1372 empty: "!a.childNodes.length",
\r
1375 contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
\r
1378 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
\r
1379 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
\r
1381 // Form attributes
\r
1382 enabled: "!a.disabled",
\r
1383 disabled: "a.disabled",
\r
1384 checked: "a.checked",
\r
1385 selected: "a.selected || jQuery.attr(a, 'selected')",
\r
1388 text: "a.type=='text'",
\r
1389 radio: "a.type=='radio'",
\r
1390 checkbox: "a.type=='checkbox'",
\r
1391 file: "a.type=='file'",
\r
1392 password: "a.type=='password'",
\r
1393 submit: "a.type=='submit'",
\r
1394 image: "a.type=='image'",
\r
1395 reset: "a.type=='reset'",
\r
1396 button: "a.type=='button'",
\r
1397 input: "/input|select|textarea|button/i.test(a.nodeName)"
\r
1399 ".": "jQuery.className.has(a,m[2])",
\r
1403 "^=": "z && !z.indexOf(m[4])",
\r
1404 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
\r
1405 "*=": "z && z.indexOf(m[4])>=0",
\r
1408 "[": "jQuery.find(m[2],a).length"
\r
1412 "\\.\\.|/\\.\\.", "a.parentNode",
\r
1413 ">|/", "jQuery.sibling(a.firstChild)",
\r
1414 "\\+", "jQuery.sibling(a).next",
\r
1416 var s = jQuery.sibling(a);
\r
1417 return s.n >= 0 ? s.slice(s.n+1) : [];
\r
1423 * @type Array<Element>
\r
1427 find: function( t, context ) {
\r
1428 // Make sure that the context is a DOM Element
\r
1429 if ( context && context.nodeType == undefined )
\r
1432 // Set the correct context (if none is provided)
\r
1433 context = context || document;
\r
1435 if ( t.constructor != String ) return [t];
\r
1437 if ( !t.indexOf("//") ) {
\r
1438 context = context.documentElement;
\r
1439 t = t.substr(2,t.length);
\r
1440 } else if ( !t.indexOf("/") ) {
\r
1441 context = context.documentElement;
\r
1442 t = t.substr(1,t.length);
\r
1443 // FIX Assume the root element is right :(
\r
1444 if ( t.indexOf("/") >= 1 )
\r
1445 t = t.substr(t.indexOf("/"),t.length);
\r
1448 var ret = [context];
\r
1452 while ( t.length > 0 && last != t ) {
\r
1456 t = jQuery.trim(t).replace( /^\/\//i, "" );
\r
1458 var foundToken = false;
\r
1460 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
\r
1461 if ( foundToken ) continue;
\r
1463 var re = new RegExp("^(" + jQuery.token[i] + ")");
\r
1464 var m = re.exec(t);
\r
1467 r = ret = jQuery.map( ret, jQuery.token[i+1] );
\r
1468 t = jQuery.trim( t.replace( re, "" ) );
\r
1469 foundToken = true;
\r
1473 if ( !foundToken ) {
\r
1474 if ( !t.indexOf(",") || !t.indexOf("|") ) {
\r
1475 if ( ret[0] == context ) ret.shift();
\r
1476 done = jQuery.merge( done, ret );
\r
1477 r = ret = [context];
\r
1478 t = " " + t.substr(1,t.length);
\r
1480 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
\r
1481 var m = re2.exec(t);
\r
1483 if ( m[1] == "#" ) {
\r
1484 // Ummm, should make this work in all XML docs
\r
1485 var oid = document.getElementById(m[2]);
\r
1486 r = ret = oid ? [oid] : [];
\r
1487 t = t.replace( re2, "" );
\r
1489 if ( !m[2] || m[1] == "." ) m[2] = "*";
\r
1491 for ( var i = 0; i < ret.length; i++ )
\r
1492 r = jQuery.merge( r,
\r
1494 jQuery.getAll(ret[i]) :
\r
1495 ret[i].getElementsByTagName(m[2])
\r
1503 var val = jQuery.filter(t,r);
\r
1505 t = jQuery.trim(val.t);
\r
1509 if ( ret && ret[0] == context ) ret.shift();
\r
1510 done = jQuery.merge( done, ret );
\r
1515 getAll: function(o,r) {
\r
1517 var s = o.childNodes;
\r
1518 for ( var i = 0; i < s.length; i++ )
\r
1519 if ( s[i].nodeType == 1 ) {
\r
1521 jQuery.getAll( s[i], r );
\r
1526 attr: function(elem, name, value){
\r
1529 "class": "className",
\r
1530 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
\r
1531 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
\r
1532 innerHTML: "innerHTML",
\r
1533 className: "className",
\r
1535 disabled: "disabled",
\r
1536 checked: "checked",
\r
1537 readonly: "readOnly"
\r
1540 // IE actually uses filters for opacity ... elem is actually elem.style
\r
1541 if (name == "opacity" && jQuery.browser.msie && value != undefined) {
\r
1542 // IE has trouble with opacity if it does not have layout
\r
1543 // Would prefer to check element.hasLayout first but don't have access to the element here
\r
1544 elem['zoom'] = 1;
\r
1545 if (value == 1) // Remove filter to avoid more IE weirdness
\r
1546 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"");
\r
1548 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"") + "alpha(opacity=" + value * 100 + ")";
\r
1549 } else if (name == "opacity" && jQuery.browser.msie) {
\r
1550 return elem["filter"] ? parseFloat( elem["filter"].match(/alpha\(opacity=(.*)\)/)[1] )/100 : 1;
\r
1553 // Mozilla doesn't play well with opacity 1
\r
1554 if (name == "opacity" && jQuery.browser.mozilla && value == 1) value = 0.9999;
\r
1556 if ( fix[name] ) {
\r
1557 if ( value != undefined ) elem[fix[name]] = value;
\r
1558 return elem[fix[name]];
\r
1559 } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
\r
1560 return elem.getAttributeNode(name).nodeValue;
\r
1561 } else if ( elem.tagName ) { // IE elem.getAttribute passes even for style
\r
1562 if ( value != undefined ) elem.setAttribute( name, value );
\r
1563 return elem.getAttribute( name );
\r
1565 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
\r
1566 if ( value != undefined ) elem[name] = value;
\r
1567 return elem[name];
\r
1571 // The regular expressions that power the parsing engine
\r
1573 // Match: [@value='test'], [@foo]
\r
1574 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
\r
1576 // Match: [div], [div p]
\r
1577 "(\\[)\s*(.*?)\s*\\]",
\r
1579 // Match: :contains('foo')
\r
1580 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
\r
1582 // Match: :even, :last-chlid
\r
1586 filter: function(t,r,not) {
\r
1587 // Figure out if we're doing regular, or inverse, filtering
\r
1588 var g = not !== false ? jQuery.grep :
\r
1589 function(a,f) {return jQuery.grep(a,f,true);};
\r
1591 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
\r
1593 var p = jQuery.parse;
\r
1595 for ( var i = 0; i < p.length; i++ ) {
\r
1597 // Look for, and replace, string-like sequences
\r
1598 // and finally build a regexp out of it
\r
1599 var re = new RegExp(
\r
1600 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
\r
1602 var m = re.exec( t );
\r
1605 // Re-organize the first match
\r
1607 m = ["",m[1], m[3], m[2], m[5]];
\r
1609 // Remove what we just matched
\r
1610 t = t.replace( re, "" );
\r
1616 // :not() is a special case that can be optimized by
\r
1617 // keeping it out of the expression list
\r
1618 if ( m[1] == ":" && m[2] == "not" )
\r
1619 r = jQuery.filter(m[3],r,false).r;
\r
1621 // Otherwise, find the expression to execute
\r
1623 var f = jQuery.expr[m[1]];
\r
1624 if ( f.constructor != String )
\r
1625 f = jQuery.expr[m[1]][m[2]];
\r
1627 // Build a custom macro to enclose it
\r
1628 eval("f = function(a,i){" +
\r
1629 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
\r
1630 "return " + f + "}");
\r
1632 // Execute it against the current filter
\r
1637 // Return an array of filtered elements (r)
\r
1638 // and the modified expression string (t)
\r
1639 return { r: r, t: t };
\r
1643 * Remove the whitespace from the beginning and end of a string.
\r
1645 * @example $.trim(" hello, how are you? ");
\r
1646 * @result "hello, how are you?"
\r
1650 * @param String str The string to trim.
\r
1653 trim: function(t){
\r
1654 return t.replace(/^\s+|\s+$/g, "");
\r
1658 * All ancestors of a given element.
\r
1662 * @type Array<Element>
\r
1663 * @param Element elem The element to find the ancestors of.
\r
1664 * @cat DOM/Traversing
\r
1666 parents: function( elem ){
\r
1668 var cur = elem.parentNode;
\r
1669 while ( cur && cur != document ) {
\r
1670 matched.push( cur );
\r
1671 cur = cur.parentNode;
\r
1677 * All elements on a specified axis.
\r
1682 * @param Element elem The element to find all the siblings of (including itself).
\r
1683 * @cat DOM/Traversing
\r
1685 sibling: function(elem, pos, not) {
\r
1689 var siblings = elem.parentNode.childNodes;
\r
1690 for ( var i = 0; i < siblings.length; i++ ) {
\r
1691 if ( not === true && siblings[i] == elem ) continue;
\r
1693 if ( siblings[i].nodeType == 1 )
\r
1694 elems.push( siblings[i] );
\r
1695 if ( siblings[i] == elem )
\r
1696 elems.n = elems.length - 1;
\r
1700 return jQuery.extend( elems, {
\r
1701 last: elems.n == elems.length - 1,
\r
1702 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
\r
1703 prev: elems[elems.n - 1],
\r
1704 next: elems[elems.n + 1]
\r
1709 * Merge two arrays together, removing all duplicates. The final order
\r
1710 * or the new array is: All the results from the first array, followed
\r
1711 * by the unique results from the second array.
\r
1713 * @example $.merge( [0,1,2], [2,3,4] )
\r
1714 * @result [0,1,2,3,4]
\r
1716 * @example $.merge( [3,2,1], [4,3,2] )
\r
1717 * @result [3,2,1,4]
\r
1721 * @param Array first The first array to merge.
\r
1722 * @param Array second The second array to merge.
\r
1725 merge: function(first, second) {
\r
1728 // Move b over to the new array (this helps to avoid
\r
1729 // StaticNodeList instances)
\r
1730 for ( var k = 0; k < first.length; k++ )
\r
1731 result[k] = first[k];
\r
1733 // Now check for duplicates between a and b and only
\r
1734 // add the unique items
\r
1735 for ( var i = 0; i < second.length; i++ ) {
\r
1736 var noCollision = true;
\r
1738 // The collision-checking process
\r
1739 for ( var j = 0; j < first.length; j++ )
\r
1740 if ( second[i] == first[j] )
\r
1741 noCollision = false;
\r
1743 // If the item is unique, add it
\r
1744 if ( noCollision )
\r
1745 result.push( second[i] );
\r
1752 * Filter items out of an array, by using a filter function.
\r
1753 * The specified function will be passed two arguments: The
\r
1754 * current array item and the index of the item in the array. The
\r
1755 * function should return 'true' if you wish to keep the item in
\r
1756 * the array, false if it should be removed.
\r
1758 * @example $.grep( [0,1,2], function(i){
\r
1765 * @param Array array The Array to find items in.
\r
1766 * @param Function fn The function to process each item against.
\r
1767 * @param Boolean inv Invert the selection - select the opposite of the function.
\r
1770 grep: function(elems, fn, inv) {
\r
1771 // If a string is passed in for the function, make a function
\r
1772 // for it (a handy shortcut)
\r
1773 if ( typeof fn == "string" )
\r
1774 fn = new Function("a","i","return " + fn);
\r
1778 // Go through the array, only saving the items
\r
1779 // that pass the validator function
\r
1780 for ( var i = 0; i < elems.length; i++ )
\r
1781 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
\r
1782 result.push( elems[i] );
\r
1788 * Translate all items in an array to another array of items.
\r
1789 * The translation function that is provided to this method is
\r
1790 * called for each item in the array and is passed one argument:
\r
1791 * The item to be translated. The function can then return:
\r
1792 * The translated value, 'null' (to remove the item), or
\r
1793 * an array of values - which will be flattened into the full array.
\r
1795 * @example $.map( [0,1,2], function(i){
\r
1798 * @result [4, 5, 6]
\r
1800 * @example $.map( [0,1,2], function(i){
\r
1801 * return i > 0 ? i + 1 : null;
\r
1805 * @example $.map( [0,1,2], function(i){
\r
1806 * return [ i, i + 1 ];
\r
1808 * @result [0, 1, 1, 2, 2, 3]
\r
1812 * @param Array array The Array to translate.
\r
1813 * @param Function fn The function to process each item against.
\r
1816 map: function(elems, fn) {
\r
1817 // If a string is passed in for the function, make a function
\r
1818 // for it (a handy shortcut)
\r
1819 if ( typeof fn == "string" )
\r
1820 fn = new Function("a","return " + fn);
\r
1824 // Go through the array, translating each of the items to their
\r
1825 // new value (or values).
\r
1826 for ( var i = 0; i < elems.length; i++ ) {
\r
1827 var val = fn(elems[i],i);
\r
1829 if ( val !== null && val != undefined ) {
\r
1830 if ( val.constructor != Array ) val = [val];
\r
1831 result = jQuery.merge( result, val );
\r
1839 * A number of helper functions used for managing events.
\r
1840 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
\r
1844 // Bind an event to an element
\r
1845 // Original by Dean Edwards
\r
1846 add: function(element, type, handler) {
\r
1847 // For whatever reason, IE has trouble passing the window object
\r
1848 // around, causing it to be cloned in the process
\r
1849 if ( jQuery.browser.msie && element.setInterval != undefined )
\r
1852 // Make sure that the function being executed has a unique ID
\r
1853 if ( !handler.guid )
\r
1854 handler.guid = this.guid++;
\r
1856 // Init the element's event structure
\r
1857 if (!element.events)
\r
1858 element.events = {};
\r
1860 // Get the current list of functions bound to this event
\r
1861 var handlers = element.events[type];
\r
1863 // If it hasn't been initialized yet
\r
1865 // Init the event handler queue
\r
1866 handlers = element.events[type] = {};
\r
1868 // Remember an existing handler, if it's already there
\r
1869 if (element["on" + type])
\r
1870 handlers[0] = element["on" + type];
\r
1873 // Add the function to the element's handler list
\r
1874 handlers[handler.guid] = handler;
\r
1876 // And bind the global event handler to the element
\r
1877 element["on" + type] = this.handle;
\r
1879 // Remember the function in a global list (for triggering)
\r
1880 if (!this.global[type])
\r
1881 this.global[type] = [];
\r
1882 this.global[type].push( element );
\r
1888 // Detach an event or set of events from an element
\r
1889 remove: function(element, type, handler) {
\r
1890 if (element.events)
\r
1891 if (type && element.events[type])
\r
1893 delete element.events[type][handler.guid];
\r
1895 for ( var i in element.events[type] )
\r
1896 delete element.events[type][i];
\r
1898 for ( var j in element.events )
\r
1899 this.remove( element, j );
\r
1902 trigger: function(type,data,element) {
\r
1903 // Clone the incoming data, if any
\r
1904 data = $.merge([], data || []);
\r
1906 // Handle a global trigger
\r
1908 var g = this.global[type];
\r
1910 for ( var i = 0; i < g.length; i++ )
\r
1911 this.trigger( type, data, g[i] );
\r
1913 // Handle triggering a single element
\r
1914 } else if ( element["on" + type] ) {
\r
1915 // Pass along a fake event
\r
1916 data.unshift( this.fix({ type: type, target: element }) );
\r
1918 // Trigger the event
\r
1919 element["on" + type].apply( element, data );
\r
1923 handle: function(event) {
\r
1924 if ( typeof jQuery == "undefined" ) return false;
\r
1926 event = jQuery.event.fix( event || window.event || {} ); // Empty object is for triggered events with no data
\r
1928 // If no correct event was found, fail
\r
1929 if ( !event ) return false;
\r
1931 var returnValue = true;
\r
1933 var c = this.events[event.type];
\r
1935 var args = [].slice.call( arguments, 1 );
\r
1936 args.unshift( event );
\r
1938 for ( var j in c ) {
\r
1939 if ( c[j].apply( this, args ) === false ) {
\r
1940 event.preventDefault();
\r
1941 event.stopPropagation();
\r
1942 returnValue = false;
\r
1946 // Clean up added properties in IE to prevent memory leak
\r
1947 if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = null;
\r
1949 return returnValue;
\r
1952 fix: function(event) {
\r
1954 if(jQuery.browser.msie) {
\r
1955 // fix target property, if available
\r
1956 // check prevents overwriting of fake target coming from trigger
\r
1957 if(event.srcElement)
\r
1958 event.target = event.srcElement;
\r
1960 // calculate pageX/Y
\r
1961 var e = document.documentElement, b = document.body;
\r
1962 event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft);
\r
1963 event.pageY = event.clientY + (e.scrollTop || b.scrollTop);
\r
1965 // check safari and if target is a textnode
\r
1966 } else if(jQuery.browser.safari && event.target.nodeType == 3) {
\r
1967 // target is readonly, clone the event object
\r
1968 event = jQuery.extend({}, event);
\r
1969 // get parentnode from textnode
\r
1970 event.target = event.target.parentNode;
\r
1973 // fix preventDefault and stopPropagation
\r
1974 if (!event.preventDefault)
\r
1975 event.preventDefault = function() {
\r
1976 this.returnValue = false;
\r
1979 if (!event.stopPropagation)
\r
1980 event.stopPropagation = function() {
\r
1981 this.cancelBubble = true;
\r
1990 * Contains flags for the useragent, read from navigator.userAgent.
\r
1991 * Available flags are: safari, opera, msie, mozilla
\r
1992 * This property is available before the DOM is ready, therefore you can
\r
1993 * use it to add ready events only for certain browsers.
\r
1995 * @example $.browser.msie
\r
1996 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
\r
1998 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
\r
1999 * @desc Alerts "this is safari!" only for safari browsers
\r
2008 * Wheather the W3C compliant box model is being used.
\r
2011 * @name $.boxModel
\r
2016 var b = navigator.userAgent.toLowerCase();
\r
2018 // Figure out what browser is being used
\r
2019 jQuery.browser = {
\r
2020 safari: /webkit/.test(b),
\r
2021 opera: /opera/.test(b),
\r
2022 msie: /msie/.test(b) && !/opera/.test(b),
\r
2023 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
\r
2026 // Check to see if the W3C box model is being used
\r
2027 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
\r
2033 * Append all of the matched elements to another, specified, set of elements.
\r
2034 * This operation is, essentially, the reverse of doing a regular
\r
2035 * $(A).append(B), in that instead of appending B to A, you're appending
\r
2038 * @example $("p").appendTo("#foo");
\r
2039 * @before <p>I would like to say: </p><div id="foo"></div>
\r
2040 * @result <div id="foo"><p>I would like to say: </p></div>
\r
2044 * @param String expr A jQuery expression of elements to match.
\r
2045 * @cat DOM/Manipulation
\r
2047 appendTo: "append",
\r
2050 * Prepend all of the matched elements to another, specified, set of elements.
\r
2051 * This operation is, essentially, the reverse of doing a regular
\r
2052 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
\r
2055 * @example $("p").prependTo("#foo");
\r
2056 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
\r
2057 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
\r
2061 * @param String expr A jQuery expression of elements to match.
\r
2062 * @cat DOM/Manipulation
\r
2064 prependTo: "prepend",
\r
2067 * Insert all of the matched elements before another, specified, set of elements.
\r
2068 * This operation is, essentially, the reverse of doing a regular
\r
2069 * $(A).before(B), in that instead of inserting B before A, you're inserting
\r
2072 * @example $("p").insertBefore("#foo");
\r
2073 * @before <div id="foo">Hello</div><p>I would like to say: </p>
\r
2074 * @result <p>I would like to say: </p><div id="foo">Hello</div>
\r
2076 * @name insertBefore
\r
2078 * @param String expr A jQuery expression of elements to match.
\r
2079 * @cat DOM/Manipulation
\r
2081 insertBefore: "before",
\r
2084 * Insert all of the matched elements after another, specified, set of elements.
\r
2085 * This operation is, essentially, the reverse of doing a regular
\r
2086 * $(A).after(B), in that instead of inserting B after A, you're inserting
\r
2089 * @example $("p").insertAfter("#foo");
\r
2090 * @before <p>I would like to say: </p><div id="foo">Hello</div>
\r
2091 * @result <div id="foo">Hello</div><p>I would like to say: </p>
\r
2093 * @name insertAfter
\r
2095 * @param String expr A jQuery expression of elements to match.
\r
2096 * @cat DOM/Manipulation
\r
2098 insertAfter: "after"
\r
2102 * Get the current CSS width of the first matched element.
\r
2104 * @example $("p").width();
\r
2105 * @before <p>This is just a test.</p>
\r
2114 * Set the CSS width of every matched element. Be sure to include
\r
2115 * the "px" (or other unit of measurement) after the number that you
\r
2116 * specify, otherwise you might get strange results.
\r
2118 * @example $("p").width("20px");
\r
2119 * @before <p>This is just a test.</p>
\r
2120 * @result <p style="width:20px;">This is just a test.</p>
\r
2124 * @param String val Set the CSS property to the specified value.
\r
2129 * Get the current CSS height of the first matched element.
\r
2131 * @example $("p").height();
\r
2132 * @before <p>This is just a test.</p>
\r
2141 * Set the CSS height of every matched element. Be sure to include
\r
2142 * the "px" (or other unit of measurement) after the number that you
\r
2143 * specify, otherwise you might get strange results.
\r
2145 * @example $("p").height("20px");
\r
2146 * @before <p>This is just a test.</p>
\r
2147 * @result <p style="height:20px;">This is just a test.</p>
\r
2151 * @param String val Set the CSS property to the specified value.
\r
2156 * Get the current CSS top of the first matched element.
\r
2158 * @example $("p").top();
\r
2159 * @before <p>This is just a test.</p>
\r
2168 * Set the CSS top of every matched element. Be sure to include
\r
2169 * the "px" (or other unit of measurement) after the number that you
\r
2170 * specify, otherwise you might get strange results.
\r
2172 * @example $("p").top("20px");
\r
2173 * @before <p>This is just a test.</p>
\r
2174 * @result <p style="top:20px;">This is just a test.</p>
\r
2178 * @param String val Set the CSS property to the specified value.
\r
2183 * Get the current CSS left of the first matched element.
\r
2185 * @example $("p").left();
\r
2186 * @before <p>This is just a test.</p>
\r
2195 * Set the CSS left of every matched element. Be sure to include
\r
2196 * the "px" (or other unit of measurement) after the number that you
\r
2197 * specify, otherwise you might get strange results.
\r
2199 * @example $("p").left("20px");
\r
2200 * @before <p>This is just a test.</p>
\r
2201 * @result <p style="left:20px;">This is just a test.</p>
\r
2205 * @param String val Set the CSS property to the specified value.
\r
2210 * Get the current CSS position of the first matched element.
\r
2212 * @example $("p").position();
\r
2213 * @before <p>This is just a test.</p>
\r
2214 * @result "static"
\r
2222 * Set the CSS position of every matched element.
\r
2224 * @example $("p").position("relative");
\r
2225 * @before <p>This is just a test.</p>
\r
2226 * @result <p style="position:relative;">This is just a test.</p>
\r
2230 * @param String val Set the CSS property to the specified value.
\r
2235 * Get the current CSS float of the first matched element.
\r
2237 * @example $("p").float();
\r
2238 * @before <p>This is just a test.</p>
\r
2247 * Set the CSS float of every matched element.
\r
2249 * @example $("p").float("left");
\r
2250 * @before <p>This is just a test.</p>
\r
2251 * @result <p style="float:left;">This is just a test.</p>
\r
2255 * @param String val Set the CSS property to the specified value.
\r
2260 * Get the current CSS overflow of the first matched element.
\r
2262 * @example $("p").overflow();
\r
2263 * @before <p>This is just a test.</p>
\r
2272 * Set the CSS overflow of every matched element.
\r
2274 * @example $("p").overflow("auto");
\r
2275 * @before <p>This is just a test.</p>
\r
2276 * @result <p style="overflow:auto;">This is just a test.</p>
\r
2280 * @param String val Set the CSS property to the specified value.
\r
2285 * Get the current CSS color of the first matched element.
\r
2287 * @example $("p").color();
\r
2288 * @before <p>This is just a test.</p>
\r
2297 * Set the CSS color of every matched element.
\r
2299 * @example $("p").color("blue");
\r
2300 * @before <p>This is just a test.</p>
\r
2301 * @result <p style="color:blue;">This is just a test.</p>
\r
2305 * @param String val Set the CSS property to the specified value.
\r
2310 * Get the current CSS background of the first matched element.
\r
2312 * @example $("p").background();
\r
2313 * @before <p style="background:blue;">This is just a test.</p>
\r
2316 * @name background
\r
2322 * Set the CSS background of every matched element.
\r
2324 * @example $("p").background("blue");
\r
2325 * @before <p>This is just a test.</p>
\r
2326 * @result <p style="background:blue;">This is just a test.</p>
\r
2328 * @name background
\r
2330 * @param String val Set the CSS property to the specified value.
\r
2334 css: "width,height,top,left,position,float,overflow,color,background".split(","),
\r
2337 * Reduce the set of matched elements to a single element.
\r
2338 * The position of the element in the set of matched elements
\r
2339 * starts at 0 and goes to length - 1.
\r
2341 * @example $("p").eq(1)
\r
2342 * @before <p>This is just a test.</p><p>So is this</p>
\r
2343 * @result [ <p>So is this</p> ]
\r
2347 * @param Number pos The index of the element that you wish to limit to.
\r
2352 * Reduce the set of matched elements to all elements before a given position.
\r
2353 * The position of the element in the set of matched elements
\r
2354 * starts at 0 and goes to length - 1.
\r
2356 * @example $("p").lt(1)
\r
2357 * @before <p>This is just a test.</p><p>So is this</p>
\r
2358 * @result [ <p>This is just a test.</p> ]
\r
2362 * @param Number pos Reduce the set to all elements below this position.
\r
2367 * Reduce the set of matched elements to all elements after a given position.
\r
2368 * The position of the element in the set of matched elements
\r
2369 * starts at 0 and goes to length - 1.
\r
2371 * @example $("p").gt(0)
\r
2372 * @before <p>This is just a test.</p><p>So is this</p>
\r
2373 * @result [ <p>So is this</p> ]
\r
2377 * @param Number pos Reduce the set to all elements after this position.
\r
2382 * Filter the set of elements to those that contain the specified text.
\r
2384 * @example $("p").contains("test")
\r
2385 * @before <p>This is just a test.</p><p>So is this</p>
\r
2386 * @result [ <p>This is just a test.</p> ]
\r
2390 * @param String str The string that will be contained within the text of an element.
\r
2391 * @cat DOM/Traversing
\r
2394 filter: [ "eq", "lt", "gt", "contains" ],
\r
2398 * Get the current value of the first matched element.
\r
2400 * @example $("input").val();
\r
2401 * @before <input type="text" value="some text"/>
\r
2402 * @result "some text"
\r
2406 * @cat DOM/Attributes
\r
2410 * Set the value of every matched element.
\r
2412 * @example $("input").val("test");
\r
2413 * @before <input type="text" value="some text"/>
\r
2414 * @result <input type="text" value="test"/>
\r
2418 * @param String val Set the property to the specified value.
\r
2419 * @cat DOM/Attributes
\r
2424 * Get the html contents of the first matched element.
\r
2426 * @example $("div").html();
\r
2427 * @before <div><input/></div>
\r
2428 * @result <input/>
\r
2432 * @cat DOM/Attributes
\r
2436 * Set the html contents of every matched element.
\r
2438 * @example $("div").html("<b>new stuff</b>");
\r
2439 * @before <div><input/></div>
\r
2440 * @result <div><b>new stuff</b></div>
\r
2444 * @param String val Set the html contents to the specified value.
\r
2445 * @cat DOM/Attributes
\r
2447 html: "innerHTML",
\r
2450 * Get the current id of the first matched element.
\r
2452 * @example $("input").id();
\r
2453 * @before <input type="text" id="test" value="some text"/>
\r
2458 * @cat DOM/Attributes
\r
2462 * Set the id of every matched element.
\r
2464 * @example $("input").id("newid");
\r
2465 * @before <input type="text" id="test" value="some text"/>
\r
2466 * @result <input type="text" id="newid" value="some text"/>
\r
2470 * @param String val Set the property to the specified value.
\r
2471 * @cat DOM/Attributes
\r
2476 * Get the current title of the first matched element.
\r
2478 * @example $("img").title();
\r
2479 * @before <img src="test.jpg" title="my image"/>
\r
2480 * @result "my image"
\r
2484 * @cat DOM/Attributes
\r
2488 * Set the title of every matched element.
\r
2490 * @example $("img").title("new title");
\r
2491 * @before <img src="test.jpg" title="my image"/>
\r
2492 * @result <img src="test.jpg" title="new image"/>
\r
2496 * @param String val Set the property to the specified value.
\r
2497 * @cat DOM/Attributes
\r
2502 * Get the current name of the first matched element.
\r
2504 * @example $("input").name();
\r
2505 * @before <input type="text" name="username"/>
\r
2506 * @result "username"
\r
2510 * @cat DOM/Attributes
\r
2514 * Set the name of every matched element.
\r
2516 * @example $("input").name("user");
\r
2517 * @before <input type="text" name="username"/>
\r
2518 * @result <input type="text" name="user"/>
\r
2522 * @param String val Set the property to the specified value.
\r
2523 * @cat DOM/Attributes
\r
2528 * Get the current href of the first matched element.
\r
2530 * @example $("a").href();
\r
2531 * @before <a href="test.html">my link</a>
\r
2532 * @result "test.html"
\r
2536 * @cat DOM/Attributes
\r
2540 * Set the href of every matched element.
\r
2542 * @example $("a").href("test2.html");
\r
2543 * @before <a href="test.html">my link</a>
\r
2544 * @result <a href="test2.html">my link</a>
\r
2548 * @param String val Set the property to the specified value.
\r
2549 * @cat DOM/Attributes
\r
2554 * Get the current src of the first matched element.
\r
2556 * @example $("img").src();
\r
2557 * @before <img src="test.jpg" title="my image"/>
\r
2558 * @result "test.jpg"
\r
2562 * @cat DOM/Attributes
\r
2566 * Set the src of every matched element.
\r
2568 * @example $("img").src("test2.jpg");
\r
2569 * @before <img src="test.jpg" title="my image"/>
\r
2570 * @result <img src="test2.jpg" title="my image"/>
\r
2574 * @param String val Set the property to the specified value.
\r
2575 * @cat DOM/Attributes
\r
2580 * Get the current rel of the first matched element.
\r
2582 * @example $("a").rel();
\r
2583 * @before <a href="test.html" rel="nofollow">my link</a>
\r
2584 * @result "nofollow"
\r
2588 * @cat DOM/Attributes
\r
2592 * Set the rel of every matched element.
\r
2594 * @example $("a").rel("nofollow");
\r
2595 * @before <a href="test.html">my link</a>
\r
2596 * @result <a href="test.html" rel="nofollow">my link</a>
\r
2600 * @param String val Set the property to the specified value.
\r
2601 * @cat DOM/Attributes
\r
2608 * Get a set of elements containing the unique parents of the matched
\r
2609 * set of elements.
\r
2611 * @example $("p").parent()
\r
2612 * @before <div><p>Hello</p><p>Hello</p></div>
\r
2613 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
\r
2617 * @cat DOM/Traversing
\r
2621 * Get a set of elements containing the unique parents of the matched
\r
2622 * set of elements, and filtered by an expression.
\r
2624 * @example $("p").parent(".selected")
\r
2625 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
\r
2626 * @result [ <div class="selected"><p>Hello Again</p></div> ]
\r
2630 * @param String expr An expression to filter the parents with
\r
2631 * @cat DOM/Traversing
\r
2633 parent: "a.parentNode",
\r
2636 * Get a set of elements containing the unique ancestors of the matched
\r
2637 * set of elements (except for the root element).
\r
2639 * @example $("span").ancestors()
\r
2640 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2641 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
\r
2645 * @cat DOM/Traversing
\r
2649 * Get a set of elements containing the unique ancestors of the matched
\r
2650 * set of elements, and filtered by an expression.
\r
2652 * @example $("span").ancestors("p")
\r
2653 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2654 * @result [ <p><span>Hello</span></p> ]
\r
2658 * @param String expr An expression to filter the ancestors with
\r
2659 * @cat DOM/Traversing
\r
2661 ancestors: jQuery.parents,
\r
2664 * Get a set of elements containing the unique ancestors of the matched
\r
2665 * set of elements (except for the root element).
\r
2667 * @example $("span").ancestors()
\r
2668 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2669 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
\r
2673 * @cat DOM/Traversing
\r
2677 * Get a set of elements containing the unique ancestors of the matched
\r
2678 * set of elements, and filtered by an expression.
\r
2680 * @example $("span").ancestors("p")
\r
2681 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2682 * @result [ <p><span>Hello</span></p> ]
\r
2686 * @param String expr An expression to filter the ancestors with
\r
2687 * @cat DOM/Traversing
\r
2689 parents: jQuery.parents,
\r
2692 * Get a set of elements containing the unique next siblings of each of the
\r
2693 * matched set of elements.
\r
2695 * It only returns the very next sibling, not all next siblings.
\r
2697 * @example $("p").next()
\r
2698 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
\r
2699 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
\r
2703 * @cat DOM/Traversing
\r
2707 * Get a set of elements containing the unique next siblings of each of the
\r
2708 * matched set of elements, and filtered by an expression.
\r
2710 * It only returns the very next sibling, not all next siblings.
\r
2712 * @example $("p").next(".selected")
\r
2713 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
\r
2714 * @result [ <p class="selected">Hello Again</p> ]
\r
2718 * @param String expr An expression to filter the next Elements with
\r
2719 * @cat DOM/Traversing
\r
2721 next: "jQuery.sibling(a).next",
\r
2724 * Get a set of elements containing the unique previous siblings of each of the
\r
2725 * matched set of elements.
\r
2727 * It only returns the immediately previous sibling, not all previous siblings.
\r
2729 * @example $("p").prev()
\r
2730 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
2731 * @result [ <div><span>Hello Again</span></div> ]
\r
2735 * @cat DOM/Traversing
\r
2739 * Get a set of elements containing the unique previous siblings of each of the
\r
2740 * matched set of elements, and filtered by an expression.
\r
2742 * It only returns the immediately previous sibling, not all previous siblings.
\r
2744 * @example $("p").prev(".selected")
\r
2745 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
\r
2746 * @result [ <div><span>Hello</span></div> ]
\r
2750 * @param String expr An expression to filter the previous Elements with
\r
2751 * @cat DOM/Traversing
\r
2753 prev: "jQuery.sibling(a).prev",
\r
2756 * Get a set of elements containing all of the unique siblings of each of the
\r
2757 * matched set of elements.
\r
2759 * @example $("div").siblings()
\r
2760 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
2761 * @result [ <p>Hello</p>, <p>And Again</p> ]
\r
2765 * @cat DOM/Traversing
\r
2769 * Get a set of elements containing all of the unique siblings of each of the
\r
2770 * matched set of elements, and filtered by an expression.
\r
2772 * @example $("div").siblings(".selected")
\r
2773 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
\r
2774 * @result [ <p class="selected">Hello Again</p> ]
\r
2778 * @param String expr An expression to filter the sibling Elements with
\r
2779 * @cat DOM/Traversing
\r
2781 siblings: "jQuery.sibling(a, null, true)",
\r
2785 * Get a set of elements containing all of the unique children of each of the
\r
2786 * matched set of elements.
\r
2788 * @example $("div").children()
\r
2789 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
2790 * @result [ <span>Hello Again</span> ]
\r
2794 * @cat DOM/Traversing
\r
2798 * Get a set of elements containing all of the unique children of each of the
\r
2799 * matched set of elements, and filtered by an expression.
\r
2801 * @example $("div").children(".selected")
\r
2802 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
\r
2803 * @result [ <p class="selected">Hello Again</p> ]
\r
2807 * @param String expr An expression to filter the child Elements with
\r
2808 * @cat DOM/Traversing
\r
2810 children: "jQuery.sibling(a.firstChild)"
\r
2816 * Remove an attribute from each of the matched elements.
\r
2818 * @example $("input").removeAttr("disabled")
\r
2819 * @before <input disabled="disabled"/>
\r
2820 * @result <input/>
\r
2822 * @name removeAttr
\r
2824 * @param String name The name of the attribute to remove.
\r
2827 removeAttr: function( key ) {
\r
2828 jQuery.attr( this, key, "" );
\r
2829 this.removeAttribute( key );
\r
2833 * Displays each of the set of matched elements if they are hidden.
\r
2835 * @example $("p").show()
\r
2836 * @before <p style="display: none">Hello</p>
\r
2837 * @result [ <p style="display: block">Hello</p> ]
\r
2844 this.style.display = this.oldblock ? this.oldblock : "";
\r
2845 if ( jQuery.css(this,"display") == "none" )
\r
2846 this.style.display = "block";
\r
2850 * Hides each of the set of matched elements if they are shown.
\r
2852 * @example $("p").hide()
\r
2853 * @before <p>Hello</p>
\r
2854 * @result [ <p style="display: none">Hello</p> ]
\r
2856 * var pass = true, div = $("div");
\r
2857 * div.hide().each(function(){
\r
2858 * if ( this.style.display != "none" ) pass = false;
\r
2860 * ok( pass, "Hide" );
\r
2867 this.oldblock = this.oldblock || jQuery.css(this,"display");
\r
2868 if ( this.oldblock == "none" )
\r
2869 this.oldblock = "block";
\r
2870 this.style.display = "none";
\r
2874 * Toggles each of the set of matched elements. If they are shown,
\r
2875 * toggle makes them hidden. If they are hidden, toggle
\r
2876 * makes them shown.
\r
2878 * @example $("p").toggle()
\r
2879 * @before <p>Hello</p><p style="display: none">Hello Again</p>
\r
2880 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
\r
2886 toggle: function(){
\r
2887 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
\r
2891 * Adds the specified class to each of the set of matched elements.
\r
2893 * @example $("p").addClass("selected")
\r
2894 * @before <p>Hello</p>
\r
2895 * @result [ <p class="selected">Hello</p> ]
\r
2899 * @param String class A CSS class to add to the elements
\r
2902 addClass: function(c){
\r
2903 jQuery.className.add(this,c);
\r
2907 * Removes the specified class from the set of matched elements.
\r
2909 * @example $("p").removeClass("selected")
\r
2910 * @before <p class="selected">Hello</p>
\r
2911 * @result [ <p>Hello</p> ]
\r
2913 * @name removeClass
\r
2915 * @param String class A CSS class to remove from the elements
\r
2918 removeClass: function(c){
\r
2919 jQuery.className.remove(this,c);
\r
2923 * Adds the specified class if it is not present, removes it if it is
\r
2926 * @example $("p").toggleClass("selected")
\r
2927 * @before <p>Hello</p><p class="selected">Hello Again</p>
\r
2928 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
\r
2930 * @name toggleClass
\r
2932 * @param String class A CSS class with which to toggle the elements
\r
2935 toggleClass: function( c ){
\r
2936 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
\r
2940 * Removes all matched elements from the DOM. This does NOT remove them from the
\r
2941 * jQuery object, allowing you to use the matched elements further.
\r
2943 * @example $("p").remove();
\r
2944 * @before <p>Hello</p> how are <p>you?</p>
\r
2949 * @cat DOM/Manipulation
\r
2953 * Removes only elements (out of the list of matched elements) that match
\r
2954 * the specified jQuery expression. This does NOT remove them from the
\r
2955 * jQuery object, allowing you to use the matched elements further.
\r
2957 * @example $("p").remove(".hello");
\r
2958 * @before <p class="hello">Hello</p> how are <p>you?</p>
\r
2959 * @result how are <p>you?</p>
\r
2963 * @param String expr A jQuery expression to filter elements by.
\r
2964 * @cat DOM/Manipulation
\r
2966 remove: function(a){
\r
2967 if ( !a || jQuery.filter( a, [this] ).r )
\r
2968 this.parentNode.removeChild( this );
\r
2972 * Removes all child nodes from the set of matched elements.
\r
2974 * @example $("p").empty()
\r
2975 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
\r
2976 * @result [ <p></p> ]
\r
2980 * @cat DOM/Manipulation
\r
2982 empty: function(){
\r
2983 while ( this.firstChild )
\r
2984 this.removeChild( this.firstChild );
\r
2988 * Binds a handler to a particular event (like click) for each matched element.
\r
2989 * The event handler is passed an event object that you can use to prevent
\r
2990 * default behaviour. To stop both default action and event bubbling, your handler
\r
2991 * has to return false.
\r
2993 * @example $("p").bind( "click", function() {
\r
2994 * alert( $(this).text() );
\r
2996 * @before <p>Hello</p>
\r
2997 * @result alert("Hello")
\r
2999 * @example $("form").bind( "submit", function() { return false; } )
\r
3000 * @desc Cancel a default action and prevent it from bubbling by returning false
\r
3001 * from your function.
\r
3003 * @example $("form").bind( "submit", function(event) {
\r
3004 * event.preventDefault();
\r
3006 * @desc Cancel only the default action by using the preventDefault method.
\r
3009 * @example $("form").bind( "submit", function(event) {
\r
3010 * event.stopPropagation();
\r
3012 * @desc Stop only an event from bubbling by using the stopPropagation method.
\r
3016 * @param String type An event type
\r
3017 * @param Function fn A function to bind to the event on each of the set of matched elements
\r
3020 bind: function( type, fn ) {
\r
3021 jQuery.event.add( this, type, fn );
\r
3025 * The opposite of bind, removes a bound event from each of the matched
\r
3026 * elements. You must pass the identical function that was used in the original
\r
3029 * @example $("p").unbind( "click", function() { alert("Hello"); } )
\r
3030 * @before <p onclick="alert('Hello');">Hello</p>
\r
3031 * @result [ <p>Hello</p> ]
\r
3035 * @param String type An event type
\r
3036 * @param Function fn A function to unbind from the event on each of the set of matched elements
\r
3041 * Removes all bound events of a particular type from each of the matched
\r
3044 * @example $("p").unbind( "click" )
\r
3045 * @before <p onclick="alert('Hello');">Hello</p>
\r
3046 * @result [ <p>Hello</p> ]
\r
3050 * @param String type An event type
\r
3055 * Removes all bound events from each of the matched elements.
\r
3057 * @example $("p").unbind()
\r
3058 * @before <p onclick="alert('Hello');">Hello</p>
\r
3059 * @result [ <p>Hello</p> ]
\r
3065 unbind: function( type, fn ) {
\r
3066 jQuery.event.remove( this, type, fn );
\r
3070 * Trigger a type of event on every matched element.
\r
3072 * @example $("p").trigger("click")
\r
3073 * @before <p click="alert('hello')">Hello</p>
\r
3074 * @result alert('hello')
\r
3078 * @param String type An event type to trigger.
\r
3081 trigger: function( type, data ) {
\r
3082 jQuery.event.trigger( type, data, this );
\r