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
\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
58 // See if an extra function was provided
\r
59 var fn = arguments[ arguments.length - 1 ];
\r
61 // If so, execute it in context
\r
62 if ( fn && typeof fn == "function" )
\r
68 // Map over the $ in case of overwrite
\r
69 if ( typeof $ != "undefined" )
\r
72 // Map the jQuery namespace to the '$' one
\r
76 * This function accepts a string containing a CSS or
\r
77 * basic XPath selector which is then used to match a set of elements.
\r
79 * The core functionality of jQuery centers around this function.
\r
80 * Everything in jQuery is based upon this, or uses this in some way.
\r
81 * The most basic use of this function is to pass in an expression
\r
82 * (usually consisting of CSS or XPath), which then finds all matching
\r
85 * By default, $() looks for DOM elements within the context of the
\r
86 * current HTML document.
\r
88 * @example $("div > p")
\r
89 * @desc This finds all p elements that are children of a div element.
\r
90 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
\r
91 * @result [ <p>two</p> ]
\r
93 * @example $("input:radio", document.forms[0])
\r
94 * @desc Searches for all inputs of type radio within the first form in the document
\r
96 * @example $("div", xml.responseXML)
\r
97 * @desc This finds all div elements within the specified XML document.
\r
100 * @param String expr An expression to search with
\r
101 * @param Element context (optional) A DOM Element, or Document, representing the base context.
\r
105 * @see $(Element<Array>)
\r
109 * This function accepts a string of raw HTML.
\r
111 * The HTML string is different from the traditional selectors in that
\r
112 * it creates the DOM elements representing that HTML string, on the fly,
\r
113 * to be (assumedly) inserted into the document later.
\r
115 * @example $("<div><p>Hello</p></div>").appendTo("#body")
\r
116 * @desc Creates a div element (and all of its contents) dynamically,
\r
117 * and appends it to the element with the ID of body. Internally, an
\r
118 * element is created and it's innerHTML property set to the given markup.
\r
119 * It is therefore both quite flexible and limited.
\r
122 * @param String html A string of HTML to create on the fly.
\r
128 * Wrap jQuery functionality around a specific DOM Element.
\r
129 * This function also accepts XML Documents and Window objects
\r
130 * as valid arguments (even though they are not DOM Elements).
\r
132 * @example $(document).find("div > p")
\r
133 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
\r
134 * @result [ <p>two</p> ]
\r
136 * @example $(document.body).background( "black" );
\r
137 * @desc Sets the background color of the page to black.
\r
140 * @param Element elem A DOM element to be encapsulated by a jQuery object.
\r
146 * Wrap jQuery functionality around a set of DOM Elements.
\r
148 * @example $( myForm.elements ).hide()
\r
149 * @desc Hides all the input elements within a form
\r
152 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
\r
158 * A shorthand for $(document).ready(), allowing you to bind a function
\r
159 * to be executed when the DOM document has finished loading. This function
\r
160 * behaves just like $(document).ready(), in that it should be used to wrap
\r
161 * all of the other $() operations on your page. While this function is,
\r
162 * technically, chainable - there really isn't much use for chaining against it.
\r
163 * You can have as many $(document).ready events on your page as you like.
\r
165 * @example $(function(){
\r
166 * // Document is ready
\r
168 * @desc Executes the function when the DOM is ready to be used.
\r
171 * @param Function fn The function to execute when the DOM is ready.
\r
177 * A means of creating a cloned copy of a jQuery object. This function
\r
178 * copies the set of matched elements from one jQuery object and creates
\r
179 * another, new, jQuery object containing the same elements.
\r
181 * @example var div = $("div");
\r
182 * $( div ).find("p");
\r
183 * @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
186 * @param jQuery obj The jQuery object to be cloned.
\r
191 jQuery.fn = jQuery.prototype = {
\r
193 * The current version of jQuery.
\r
201 jquery: "@VERSION",
\r
204 * The number of elements currently matched.
\r
206 * @example $("img").length;
\r
207 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
217 * The number of elements currently matched.
\r
219 * @example $("img").size();
\r
220 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
228 return this.length;
\r
232 * Access all matched elements. This serves as a backwards-compatible
\r
233 * way of accessing all matched elements (other than the jQuery object
\r
234 * itself, which is, in fact, an array of elements).
\r
236 * @example $("img").get();
\r
237 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
238 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
\r
241 * @type Array<Element>
\r
246 * Access a single matched element. num is used to access the
\r
247 * Nth element matched.
\r
249 * @example $("img").get(1);
\r
250 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
251 * @result [ <img src="test1.jpg"/> ]
\r
255 * @param Number num Access the element in the Nth position.
\r
258 get: function( num ) {
\r
259 return num == undefined ?
\r
261 // Return a 'clean' array
\r
262 jQuery.merge( this, [] ) :
\r
264 // Return just the object
\r
269 * Set the jQuery object to an array of elements.
\r
271 * @example $("img").set([ document.body ]);
\r
272 * @result $("img").set() == [ document.body ]
\r
277 * @param Elements elems An array of elements
\r
280 set: function( array ) {
\r
281 // Use a tricky hack to make the jQuery object
\r
282 // look and feel like an array
\r
284 [].push.apply( this, array );
\r
289 * Execute a function within the context of every matched element.
\r
290 * This means that every time the passed-in function is executed
\r
291 * (which is once for every element matched) the 'this' keyword
\r
292 * points to the specific element.
\r
294 * Additionally, the function, when executed, is passed a single
\r
295 * argument representing the position of the element in the matched
\r
298 * @example $("img").each(function(i){
\r
299 * this.src = "test" + i + ".jpg";
\r
301 * @before <img/> <img/>
\r
302 * @result <img src="test0.jpg"/> <img src="test1.jpg"/>
\r
303 * @desc Iterates over two images and sets their src property
\r
307 * @param Function fn A function to execute
\r
310 each: function( fn, args ) {
\r
311 return jQuery.each( this, fn, args );
\r
315 * Searches every matched element for the object and returns
\r
316 * the index of the element, if found, starting with zero.
\r
317 * Returns -1 if the object wasn't found.
\r
319 * @example $("*").index(document.getElementById('foobar'))
\r
320 * @before <div id="foobar"></div><b></b><span id="foo"></span>
\r
323 * @example $("*").index(document.getElementById('foo'))
\r
324 * @before <div id="foobar"></div><b></b><span id="foo"></span>
\r
327 * @example $("*").index(document.getElementById('bar'))
\r
328 * @before <div id="foobar"></div><b></b><span id="foo"></span>
\r
333 * @param Object obj Object to search for
\r
336 index: function( obj ) {
\r
338 this.each(function(i){
\r
339 if ( this == obj ) pos = i;
\r
345 * Access a property on the first matched element.
\r
346 * This method makes it easy to retrieve a property value
\r
347 * from the first matched element.
\r
349 * @example $("img").attr("src");
\r
350 * @before <img src="test.jpg"/>
\r
355 * @param String name The name of the property to access.
\r
360 * Set a hash of key/value object properties to all matched elements.
\r
361 * This serves as the best way to set a large number of properties
\r
362 * on all matched elements.
\r
364 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
\r
366 * @result <img src="test.jpg" alt="Test Image"/>
\r
370 * @param Hash prop A set of key/value pairs to set as object properties.
\r
375 * Set a single property to a value, on all matched elements.
\r
377 * Note that you can't set the name property of input elements in IE.
\r
378 * Use $(html) or $().append(html) or $().html(html) to create elements
\r
379 * on the fly including the name property.
\r
381 * @example $("img").attr("src","test.jpg");
\r
383 * @result <img src="test.jpg"/>
\r
387 * @param String key The name of the property to set.
\r
388 * @param Object value The value to set the property to.
\r
391 attr: function( key, value, type ) {
\r
392 // Check to see if we're setting style values
\r
393 return key.constructor != String || value != undefined ?
\r
394 this.each(function(){
\r
395 // See if we're setting a hash of styles
\r
396 if ( value == undefined )
\r
397 // Set all the styles
\r
398 for ( var prop in key )
\r
400 type ? this.style : this,
\r
404 // See if we're setting a single key/value style
\r
407 type ? this.style : this,
\r
412 // Look for the case where we're accessing a style value
\r
413 jQuery[ type || "attr" ]( this[0], key );
\r
417 * Access a style property on the first matched element.
\r
418 * This method makes it easy to retrieve a style property value
\r
419 * from the first matched element.
\r
421 * @example $("p").css("color");
\r
422 * @before <p style="color:red;">Test Paragraph.</p>
\r
424 * @desc Retrieves the color style of the first paragraph
\r
426 * @example $("p").css("fontWeight");
\r
427 * @before <p style="font-weight: bold;">Test Paragraph.</p>
\r
429 * @desc Retrieves the font-weight style of the first paragraph.
\r
430 * Note that for all style properties with a dash (like 'font-weight'), you have to
\r
431 * write it in camelCase. In other words: Every time you have a '-' in a
\r
432 * property, remove it and replace the next character with an uppercase
\r
433 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
\r
434 * borderStyle, borderBottomWidth etc.
\r
438 * @param String name The name of the property to access.
\r
443 * Set a hash of key/value style properties to all matched elements.
\r
444 * This serves as the best way to set a large number of style properties
\r
445 * on all matched elements.
\r
447 * @example $("p").css({ color: "red", background: "blue" });
\r
448 * @before <p>Test Paragraph.</p>
\r
449 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
\r
453 * @param Hash prop A set of key/value pairs to set as style properties.
\r
458 * Set a single style property to a value, on all matched elements.
\r
460 * @example $("p").css("color","red");
\r
461 * @before <p>Test Paragraph.</p>
\r
462 * @result <p style="color:red;">Test Paragraph.</p>
\r
463 * @desc Changes the color of all paragraphs to red
\r
467 * @param String key The name of the property to set.
\r
468 * @param Object value The value to set the property to.
\r
471 css: function( key, value ) {
\r
472 return this.attr( key, value, "curCSS" );
\r
476 * Retrieve the text contents of all matched elements. The result is
\r
477 * a string that contains the combined text contents of all matched
\r
478 * elements. This method works on both HTML and XML documents.
\r
480 * @example $("p").text();
\r
481 * @before <p>Test Paragraph.</p>
\r
482 * @result Test Paragraph.
\r
488 text: function(e) {
\r
491 for ( var j = 0; j < e.length; j++ ) {
\r
492 var r = e[j].childNodes;
\r
493 for ( var i = 0; i < r.length; i++ )
\r
494 if ( r[i].nodeType != 8 )
\r
495 t += r[i].nodeType != 1 ?
\r
496 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
\r
502 * Wrap all matched elements with a structure of other elements.
\r
503 * This wrapping process is most useful for injecting additional
\r
504 * stucture into a document, without ruining the original semantic
\r
505 * qualities of a document.
\r
507 * This works by going through the first element
\r
508 * provided (which is generated, on the fly, from the provided HTML)
\r
509 * and finds the deepest ancestor element within its
\r
510 * structure - it is that element that will en-wrap everything else.
\r
512 * This does not work with elements that contain text. Any necessary text
\r
513 * must be added after the wrapping is done.
\r
515 * @example $("p").wrap("<div class='wrap'></div>");
\r
516 * @before <p>Test Paragraph.</p>
\r
517 * @result <div class='wrap'><p>Test Paragraph.</p></div>
\r
521 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
\r
522 * @cat DOM/Manipulation
\r
526 * Wrap all matched elements with a structure of other elements.
\r
527 * This wrapping process is most useful for injecting additional
\r
528 * stucture into a document, without ruining the original semantic
\r
529 * qualities of a document.
\r
531 * This works by going through the first element
\r
532 * provided and finding the deepest ancestor element within its
\r
533 * structure - it is that element that will en-wrap everything else.
\r
535 * This does not work with elements that contain text. Any necessary text
\r
536 * must be added after the wrapping is done.
\r
538 * @example $("p").wrap( document.getElementById('content') );
\r
539 * @before <p>Test Paragraph.</p><div id="content"></div>
\r
540 * @result <div id="content"><p>Test Paragraph.</p></div>
\r
544 * @param Element elem A DOM element that will be wrapped.
\r
545 * @cat DOM/Manipulation
\r
548 // The elements to wrap the target around
\r
549 var a = jQuery.clean(arguments);
\r
551 // Wrap each of the matched elements individually
\r
552 return this.each(function(){
\r
553 // Clone the structure that we're using to wrap
\r
554 var b = a[0].cloneNode(true);
\r
556 // Insert it before the element to be wrapped
\r
557 this.parentNode.insertBefore( b, this );
\r
559 // Find the deepest point in the wrap structure
\r
560 while ( b.firstChild )
\r
563 // Move the matched element to within the wrap structure
\r
564 b.appendChild( this );
\r
569 * Append any number of elements to the inside of every matched elements,
\r
570 * generated from the provided HTML.
\r
571 * This operation is similar to doing an appendChild to all the
\r
572 * specified elements, adding them into the document.
\r
574 * @example $("p").append("<b>Hello</b>");
\r
575 * @before <p>I would like to say: </p>
\r
576 * @result <p>I would like to say: <b>Hello</b></p>
\r
580 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
581 * @cat DOM/Manipulation
\r
585 * Append an element to the inside of all matched elements.
\r
586 * This operation is similar to doing an appendChild to all the
\r
587 * specified elements, adding them into the document.
\r
589 * @example $("p").append( $("#foo")[0] );
\r
590 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
591 * @result <p>I would like to say: <b id="foo">Hello</b></p>
\r
595 * @param Element elem A DOM element that will be appended.
\r
596 * @cat DOM/Manipulation
\r
600 * Append any number of elements to the inside of all matched elements.
\r
601 * This operation is similar to doing an appendChild to all the
\r
602 * specified elements, adding them into the document.
\r
604 * @example $("p").append( $("b") );
\r
605 * @before <p>I would like to say: </p><b>Hello</b>
\r
606 * @result <p>I would like to say: <b>Hello</b></p>
\r
610 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
611 * @cat DOM/Manipulation
\r
613 append: function() {
\r
614 return this.domManip(arguments, true, 1, function(a){
\r
615 this.appendChild( a );
\r
620 * Prepend any number of elements to the inside of every matched elements,
\r
621 * generated from the provided HTML.
\r
622 * This operation is the best way to insert dynamically created elements
\r
623 * inside, at the beginning, of all the matched element.
\r
625 * @example $("p").prepend("<b>Hello</b>");
\r
626 * @before <p>I would like to say: </p>
\r
627 * @result <p><b>Hello</b>I would like to say: </p>
\r
631 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
632 * @cat DOM/Manipulation
\r
636 * Prepend an element to the inside of all matched elements.
\r
637 * This operation is the best way to insert an element inside, at the
\r
638 * beginning, of all the matched element.
\r
640 * @example $("p").prepend( $("#foo")[0] );
\r
641 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
642 * @result <p><b id="foo">Hello</b>I would like to say: </p>
\r
646 * @param Element elem A DOM element that will be appended.
\r
647 * @cat DOM/Manipulation
\r
651 * Prepend any number of elements to the inside of all matched elements.
\r
652 * This operation is the best way to insert a set of elements inside, at the
\r
653 * beginning, of all the matched element.
\r
655 * @example $("p").prepend( $("b") );
\r
656 * @before <p>I would like to say: </p><b>Hello</b>
\r
657 * @result <p><b>Hello</b>I would like to say: </p>
\r
661 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
662 * @cat DOM/Manipulation
\r
664 prepend: function() {
\r
665 return this.domManip(arguments, true, -1, function(a){
\r
666 this.insertBefore( a, this.firstChild );
\r
671 * Insert any number of dynamically generated elements before each of the
\r
672 * matched elements.
\r
674 * @example $("p").before("<b>Hello</b>");
\r
675 * @before <p>I would like to say: </p>
\r
676 * @result <b>Hello</b><p>I would like to say: </p>
\r
680 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
681 * @cat DOM/Manipulation
\r
685 * Insert an element before each of the matched elements.
\r
687 * @example $("p").before( $("#foo")[0] );
\r
688 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
689 * @result <b id="foo">Hello</b><p>I would like to say: </p>
\r
693 * @param Element elem A DOM element that will be appended.
\r
694 * @cat DOM/Manipulation
\r
698 * Insert any number of elements before each of the matched elements.
\r
700 * @example $("p").before( $("b") );
\r
701 * @before <p>I would like to say: </p><b>Hello</b>
\r
702 * @result <b>Hello</b><p>I would like to say: </p>
\r
706 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
707 * @cat DOM/Manipulation
\r
709 before: function() {
\r
710 return this.domManip(arguments, false, 1, function(a){
\r
711 this.parentNode.insertBefore( a, this );
\r
716 * Insert any number of dynamically generated elements after each of the
\r
717 * matched elements.
\r
719 * @example $("p").after("<b>Hello</b>");
\r
720 * @before <p>I would like to say: </p>
\r
721 * @result <p>I would like to say: </p><b>Hello</b>
\r
725 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
726 * @cat DOM/Manipulation
\r
730 * Insert an element after each of the matched elements.
\r
732 * @example $("p").after( $("#foo")[0] );
\r
733 * @before <b id="foo">Hello</b><p>I would like to say: </p>
\r
734 * @result <p>I would like to say: </p><b id="foo">Hello</b>
\r
738 * @param Element elem A DOM element that will be appended.
\r
739 * @cat DOM/Manipulation
\r
743 * Insert any number of elements after each of the matched elements.
\r
745 * @example $("p").after( $("b") );
\r
746 * @before <b>Hello</b><p>I would like to say: </p>
\r
747 * @result <p>I would like to say: </p><b>Hello</b>
\r
751 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
752 * @cat DOM/Manipulation
\r
754 after: function() {
\r
755 return this.domManip(arguments, false, -1, function(a){
\r
756 this.parentNode.insertBefore( a, this.nextSibling );
\r
761 * End the most recent 'destructive' operation, reverting the list of matched elements
\r
762 * back to its previous state. After an end operation, the list of matched elements will
\r
763 * revert to the last state of matched elements.
\r
765 * @example $("p").find("span").end();
\r
766 * @before <p><span>Hello</span>, how are you?</p>
\r
767 * @result $("p").find("span").end() == [ <p>...</p> ]
\r
771 * @cat DOM/Traversing
\r
774 if( !(this.stack && this.stack.length) )
\r
776 return this.set( this.stack.pop() );
\r
780 * Searches for all elements that match the specified expression.
\r
781 * This method is the optimal way of finding additional descendant
\r
782 * elements with which to process.
\r
784 * All searching is done using a jQuery expression. The expression can be
\r
785 * written using CSS 1-3 Selector syntax, or basic XPath.
\r
787 * @example $("p").find("span");
\r
788 * @before <p><span>Hello</span>, how are you?</p>
\r
789 * @result $("p").find("span") == [ <span>Hello</span> ]
\r
793 * @param String expr An expression to search with.
\r
794 * @cat DOM/Traversing
\r
796 find: function(t) {
\r
797 return this.pushStack( jQuery.map( this, function(a){
\r
798 return jQuery.find(t,a);
\r
803 * Create cloned copies of all matched DOM Elements. This does
\r
804 * not create a cloned copy of this particular jQuery object,
\r
805 * instead it creates duplicate copies of all DOM Elements.
\r
806 * This is useful for moving copies of the elements to another
\r
807 * location in the DOM.
\r
809 * @example $("b").clone().prependTo("p");
\r
810 * @before <b>Hello</b><p>, how are you?</p>
\r
811 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
\r
815 * @cat DOM/Manipulation
\r
817 clone: function(deep) {
\r
818 return this.pushStack( jQuery.map( this, function(a){
\r
819 return a.cloneNode( deep != undefined ? deep : true );
\r
824 * Removes all elements from the set of matched elements that do not
\r
825 * match the specified expression. This method is used to narrow down
\r
826 * the results of a search.
\r
828 * All searching is done using a jQuery expression. The expression
\r
829 * can be written using CSS 1-3 Selector syntax, or basic XPath.
\r
831 * @example $("p").filter(".selected")
\r
832 * @before <p class="selected">Hello</p><p>How are you?</p>
\r
833 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
\r
837 * @param String expr An expression to search with.
\r
838 * @cat DOM/Traversing
\r
842 * Removes all elements from the set of matched elements that do not
\r
843 * match at least one of the expressions passed to the function. This
\r
844 * method is used when you want to filter the set of matched elements
\r
845 * through more than one expression.
\r
847 * Elements will be retained in the jQuery object if they match at
\r
848 * least one of the expressions passed.
\r
850 * @example $("p").filter([".selected", ":first"])
\r
851 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
\r
852 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
\r
856 * @param Array<String> exprs A set of expressions to evaluate against
\r
857 * @cat DOM/Traversing
\r
859 filter: function(t) {
\r
860 return this.pushStack(
\r
861 t.constructor == Array &&
\r
862 jQuery.map(this,function(a){
\r
863 for ( var i = 0; i < t.length; i++ )
\r
864 if ( jQuery.filter(t[i],[a]).r.length )
\r
869 t.constructor == Boolean &&
\r
870 ( t ? this.get() : [] ) ||
\r
872 typeof t == "function" &&
\r
873 jQuery.grep( this, t ) ||
\r
875 jQuery.filter(t,this).r, arguments );
\r
879 * Removes the specified Element from the set of matched elements. This
\r
880 * method is used to remove a single Element from a jQuery object.
\r
882 * @example $("p").not( document.getElementById("selected") )
\r
883 * @before <p>Hello</p><p id="selected">Hello Again</p>
\r
884 * @result [ <p>Hello</p> ]
\r
888 * @param Element el An element to remove from the set
\r
889 * @cat DOM/Traversing
\r
893 * Removes elements matching the specified expression from the set
\r
894 * of matched elements. This method is used to remove one or more
\r
895 * elements from a jQuery object.
\r
897 * @example $("p").not("#selected")
\r
898 * @before <p>Hello</p><p id="selected">Hello Again</p>
\r
899 * @result [ <p>Hello</p> ]
\r
903 * @param String expr An expression with which to remove matching elements
\r
904 * @cat DOM/Traversing
\r
907 return this.pushStack( typeof t == "string" ?
\r
908 jQuery.filter(t,this,false).r :
\r
909 jQuery.grep(this,function(a){ return a != t; }), arguments );
\r
913 * Adds the elements matched by the expression to the jQuery object. This
\r
914 * can be used to concatenate the result sets of two expressions.
\r
916 * @example $("p").add("span")
\r
917 * @before <p>Hello</p><p><span>Hello Again</span></p>
\r
918 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
\r
922 * @param String expr An expression whose matched elements are added
\r
923 * @cat DOM/Traversing
\r
927 * Adds each of the Elements in the array to the set of matched elements.
\r
928 * This is used to add a set of Elements to a jQuery object.
\r
930 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
\r
931 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
\r
932 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
\r
936 * @param Array<Element> els An array of Elements to add
\r
937 * @cat DOM/Traversing
\r
941 * Adds a single Element to the set of matched elements. This is used to
\r
942 * add a single Element to a jQuery object.
\r
944 * @example $("p").add( document.getElementById("a") )
\r
945 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
\r
946 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
\r
950 * @param Element el An Element to add
\r
951 * @cat DOM/Traversing
\r
954 return this.pushStack( jQuery.merge( this, typeof t == "string" ?
\r
955 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
\r
959 * Checks the current selection against an expression and returns true,
\r
960 * if at least one element of the selection fits the given expression.
\r
961 * Does return false, if no element fits or the expression is not valid.
\r
963 * @example $("input[@type='checkbox']").parent().is("form")
\r
964 * @before <form><input type="checkbox" /></form>
\r
966 * @desc Returns true, because the parent of the input is a form element
\r
968 * @example $("input[@type='checkbox']").parent().is("form")
\r
969 * @before <form><p><input type="checkbox" /></p></form>
\r
971 * @desc Returns false, because the parent of the input is a p element
\r
973 * @example $("form").is(null)
\r
974 * @before <form></form>
\r
976 * @desc An invalid expression always returns false.
\r
980 * @param String expr The expression with which to filter
\r
981 * @cat DOM/Traversing
\r
983 is: function(expr) {
\r
984 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
\r
990 * @param Array args
\r
991 * @param Boolean table
\r
992 * @param Number dir
\r
993 * @param Function fn The function doing the DOM manipulation.
\r
997 domManip: function(args, table, dir, fn){
\r
998 var clone = this.size() > 1;
\r
999 var a = jQuery.clean(args);
\r
1001 return this.each(function(){
\r
1004 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
\r
1005 var tbody = this.getElementsByTagName("tbody");
\r
1007 if ( !tbody.length ) {
\r
1008 obj = document.createElement("tbody");
\r
1009 this.appendChild( obj );
\r
1014 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
\r
1015 i != ( dir < 0 ? dir : a.length ); i += dir ) {
\r
1016 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
\r
1027 * @param Array args
\r
1031 pushStack: function(a,args) {
\r
1032 var fn = args && args[args.length-1];
\r
1033 var fn2 = args && args[args.length-2];
\r
1035 if ( fn && fn.constructor != Function ) fn = null;
\r
1036 if ( fn2 && fn2.constructor != Function ) fn2 = null;
\r
1039 if ( !this.stack ) this.stack = [];
\r
1040 this.stack.push( this.get() );
\r
1043 var old = this.get();
\r
1046 if ( fn2 && a.length || !fn2 )
\r
1047 this.each( fn2 || fn ).set( old );
\r
1049 this.set( old ).each( fn );
\r
1057 * Extends the jQuery object itself. Can be used to add functions into
\r
1058 * the jQuery namespace and to add plugin methods (plugins).
\r
1060 * @example jQuery.fn.extend({
\r
1061 * check: function() {
\r
1062 * return this.each(function() { this.checked = true; });
\r
1064 * uncheck: function() {
\r
1065 * return this.each(function() { this.checked = false; });
\r
1068 * $("input[@type=checkbox]").check();
\r
1069 * $("input[@type=radio]").uncheck();
\r
1070 * @desc Adds two plugin methods.
\r
1072 * @example jQuery.extend({
\r
1073 * min: function(a, b) { return a < b ? a : b; },
\r
1074 * max: function(a, b) { return a > b ? a : b; }
\r
1076 * @desc Adds two functions into the jQuery namespace
\r
1079 * @param Object prop The object that will be merged into the jQuery object
\r
1085 * Extend one object with one or more others, returning the original,
\r
1086 * modified, object. This is a great utility for simple inheritance.
\r
1088 * @example var settings = { validate: false, limit: 5, name: "foo" };
\r
1089 * var options = { validate: true, name: "bar" };
\r
1090 * jQuery.extend(settings, options);
\r
1091 * @result settings == { validate: true, limit: 5, name: "bar" }
\r
1092 * @desc Merge settings and options, modifying settings
\r
1094 * @example var defaults = { validate: false, limit: 5, name: "foo" };
\r
1095 * var options = { validate: true, name: "bar" };
\r
1096 * var settings = jQuery.extend({}, defaults, options);
\r
1097 * @result settings == { validate: true, limit: 5, name: "bar" }
\r
1098 * @desc Merge defaults and options, without modifying the defaults
\r
1101 * @param Object target The object to extend
\r
1102 * @param Object prop1 The object that will be merged into the first.
\r
1103 * @param Object propN (optional) More objects to merge into the first
\r
1107 jQuery.extend = jQuery.fn.extend = function() {
\r
1108 // copy reference to target object
\r
1109 var target = arguments[0],
\r
1112 // extend jQuery itself if only one argument is passed
\r
1113 if ( arguments.length == 1 ) {
\r
1118 while (prop = arguments[a++])
\r
1119 // Extend the base object
\r
1120 for ( var i in prop ) target[i] = prop[i];
\r
1122 // Return the modified object
\r
1134 jQuery.initDone = true;
\r
1136 jQuery.each( jQuery.macros.axis, function(i,n){
\r
1137 jQuery.fn[ i ] = function(a) {
\r
1138 var ret = jQuery.map(this,n);
\r
1139 if ( a && typeof a == "string" )
\r
1140 ret = jQuery.filter(a,ret).r;
\r
1141 return this.pushStack( ret, arguments );
\r
1145 jQuery.each( jQuery.macros.to, function(i,n){
\r
1146 jQuery.fn[ i ] = function(){
\r
1147 var a = arguments;
\r
1148 return this.each(function(){
\r
1149 for ( var j = 0; j < a.length; j++ )
\r
1150 jQuery(a[j])[n]( this );
\r
1155 jQuery.each( jQuery.macros.each, function(i,n){
\r
1156 jQuery.fn[ i ] = function() {
\r
1157 return this.each( n, arguments );
\r
1161 jQuery.each( jQuery.macros.filter, function(i,n){
\r
1162 jQuery.fn[ n ] = function(num,fn) {
\r
1163 return this.filter( ":" + n + "(" + num + ")", fn );
\r
1167 jQuery.each( jQuery.macros.attr, function(i,n){
\r
1169 jQuery.fn[ i ] = function(h) {
\r
1170 return h == undefined ?
\r
1171 this.length ? this[0][n] : null :
\r
1172 this.attr( n, h );
\r
1176 jQuery.each( jQuery.macros.css, function(i,n){
\r
1177 jQuery.fn[ n ] = function(h) {
\r
1178 return h == undefined ?
\r
1179 ( this.length ? jQuery.css( this[0], n ) : null ) :
\r
1187 * A generic iterator function, which can be used to seemlessly
\r
1188 * iterate over both objects and arrays. This function is not the same
\r
1189 * as $().each() - which is used to iterate, exclusively, over a jQuery
\r
1190 * object. This function can be used to iterate over anything.
\r
1192 * @example $.each( [0,1,2], function(i){
\r
1193 * alert( "Item #" + i + ": " + this );
\r
1195 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
\r
1197 * @example $.each( { name: "John", lang: "JS" }, function(i){
\r
1198 * alert( "Name: " + i + ", Value: " + this );
\r
1200 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
\r
1203 * @param Object obj The object, or array, to iterate over.
\r
1204 * @param Function fn The function that will be executed on every object.
\r
1208 // args is for internal usage only
\r
1209 each: function( obj, fn, args ) {
\r
1210 if ( obj.length == undefined )
\r
1211 for ( var i in obj )
\r
1212 fn.apply( obj[i], args || [i, obj[i]] );
\r
1214 for ( var i = 0; i < obj.length; i++ )
\r
1215 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
\r
1220 add: function(o,c){
\r
1221 if (jQuery.className.has(o,c)) return;
\r
1222 o.className += ( o.className ? " " : "" ) + c;
\r
1224 remove: function(o,c){
\r
1228 var classes = o.className.split(" ");
\r
1229 for(var i=0; i<classes.length; i++) {
\r
1230 if(classes[i] == c) {
\r
1231 classes.splice(i, 1);
\r
1235 o.className = classes.join(' ');
\r
1238 has: function(e,a) {
\r
1239 if ( e.className != undefined )
\r
1241 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
\r
1246 * Swap in/out style options.
\r
1249 swap: function(e,o,f) {
\r
1250 for ( var i in o ) {
\r
1251 e.style["old"+i] = e.style[i];
\r
1252 e.style[i] = o[i];
\r
1255 for ( var i in o )
\r
1256 e.style[i] = e.style["old"+i];
\r
1259 css: function(e,p) {
\r
1260 if ( p == "height" || p == "width" ) {
\r
1261 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
\r
1263 for ( var i=0; i<d.length; i++ ) {
\r
1264 old["padding" + d[i]] = 0;
\r
1265 old["border" + d[i] + "Width"] = 0;
\r
1268 jQuery.swap( e, old, function() {
\r
1269 if (jQuery.css(e,"display") != "none") {
\r
1270 oHeight = e.offsetHeight;
\r
1271 oWidth = e.offsetWidth;
\r
1273 e = jQuery(e.cloneNode(true))
\r
1274 .find(":radio").removeAttr("checked").end()
\r
1276 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
\r
1277 }).appendTo(e.parentNode)[0];
\r
1279 var parPos = jQuery.css(e.parentNode,"position");
\r
1280 if ( parPos == "" || parPos == "static" )
\r
1281 e.parentNode.style.position = "relative";
\r
1283 oHeight = e.clientHeight;
\r
1284 oWidth = e.clientWidth;
\r
1286 if ( parPos == "" || parPos == "static" )
\r
1287 e.parentNode.style.position = "static";
\r
1289 e.parentNode.removeChild(e);
\r
1293 return p == "height" ? oHeight : oWidth;
\r
1296 return jQuery.curCSS( e, p );
\r
1299 curCSS: function(elem, prop, force) {
\r
1302 if (prop == 'opacity' && jQuery.browser.msie)
\r
1303 return jQuery.attr(elem.style, 'opacity');
\r
1305 if (prop == "float" || prop == "cssFloat")
\r
1306 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
\r
1308 if (!force && elem.style[prop]) {
\r
1310 ret = elem.style[prop];
\r
1312 } else if (document.defaultView && document.defaultView.getComputedStyle) {
\r
1314 if (prop == "cssFloat" || prop == "styleFloat")
\r
1317 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
\r
1318 var cur = document.defaultView.getComputedStyle(elem, null);
\r
1321 ret = cur.getPropertyValue(prop);
\r
1322 else if ( prop == 'display' )
\r
1325 jQuery.swap(elem, { display: 'block' }, function() {
\r
1326 var c = document.defaultView.getComputedStyle(this, '');
\r
1327 ret = c && c.getPropertyValue(prop) || '';
\r
1330 } else if (elem.currentStyle) {
\r
1332 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
\r
1333 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
\r
1340 clean: function(a) {
\r
1342 for ( var i = 0; i < a.length; i++ ) {
\r
1344 if ( typeof arg == "string" ) { // Convert html string into DOM nodes
\r
1345 // Trim whitespace, otherwise indexOf won't work as expected
\r
1346 var s = jQuery.trim(arg), div = document.createElement("div"), wrap = [0,"",""];
\r
1348 if ( !s.indexOf("<opt") ) // option or optgroup
\r
1349 wrap = [1, "<select>", "</select>"];
\r
1350 else if ( !s.indexOf("<thead") || !s.indexOf("<tbody") )
\r
1351 wrap = [1, "<table>", "</table>"];
\r
1352 else if ( !s.indexOf("<tr") )
\r
1353 wrap = [2, "<table>", "</table>"]; // tbody auto-inserted
\r
1354 else if ( !s.indexOf("<td") || !s.indexOf("<th") )
\r
1355 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
\r
1357 // Go to html and back, then peel off extra wrappers
\r
1358 div.innerHTML = wrap[1] + s + wrap[2];
\r
1359 while ( wrap[0]-- ) div = div.firstChild;
\r
1360 arg = div.childNodes;
\r
1364 if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
\r
1365 for ( var n = 0; n < arg.length; n++ ) // Handles Array, jQuery, DOM NodeList collections
\r
1368 r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
\r
1375 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
\r
1376 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
\r
1378 // Position Checks
\r
1384 last: "i==r.length-1",
\r
1389 "nth-child": "jQuery.sibling(a,m[3]).cur",
\r
1390 "first-child": "jQuery.sibling(a,0).cur",
\r
1391 "last-child": "jQuery.sibling(a,0).last",
\r
1392 "only-child": "jQuery.sibling(a).length==1",
\r
1395 parent: "a.childNodes.length",
\r
1396 empty: "!a.childNodes.length",
\r
1399 contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
\r
1402 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
\r
1403 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
\r
1405 // Form attributes
\r
1406 enabled: "!a.disabled",
\r
1407 disabled: "a.disabled",
\r
1408 checked: "a.checked",
\r
1409 selected: "a.selected || jQuery.attr(a, 'selected')",
\r
1412 text: "a.type=='text'",
\r
1413 radio: "a.type=='radio'",
\r
1414 checkbox: "a.type=='checkbox'",
\r
1415 file: "a.type=='file'",
\r
1416 password: "a.type=='password'",
\r
1417 submit: "a.type=='submit'",
\r
1418 image: "a.type=='image'",
\r
1419 reset: "a.type=='reset'",
\r
1420 button: "a.type=='button'",
\r
1421 input: "/input|select|textarea|button/i.test(a.nodeName)"
\r
1423 ".": "jQuery.className.has(a,m[2])",
\r
1427 "^=": "z && !z.indexOf(m[4])",
\r
1428 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
\r
1429 "*=": "z && z.indexOf(m[4])>=0",
\r
1432 "[": "jQuery.find(m[2],a).length"
\r
1436 "\\.\\.|/\\.\\.", "a.parentNode",
\r
1437 ">|/", "jQuery.sibling(a.firstChild)",
\r
1438 "\\+", "jQuery.sibling(a).next",
\r
1440 var s = jQuery.sibling(a);
\r
1441 return s.n >= 0 ? s.slice(s.n+1) : [];
\r
1447 * @type Array<Element>
\r
1451 find: function( t, context ) {
\r
1452 // Make sure that the context is a DOM Element
\r
1453 if ( context && context.nodeType == undefined )
\r
1456 // Set the correct context (if none is provided)
\r
1457 context = context || document;
\r
1459 if ( t.constructor != String ) return [t];
\r
1461 if ( !t.indexOf("//") ) {
\r
1462 context = context.documentElement;
\r
1463 t = t.substr(2,t.length);
\r
1464 } else if ( !t.indexOf("/") ) {
\r
1465 context = context.documentElement;
\r
1466 t = t.substr(1,t.length);
\r
1467 // FIX Assume the root element is right :(
\r
1468 if ( t.indexOf("/") >= 1 )
\r
1469 t = t.substr(t.indexOf("/"),t.length);
\r
1472 var ret = [context];
\r
1476 while ( t.length > 0 && last != t ) {
\r
1480 t = jQuery.trim(t).replace( /^\/\//i, "" );
\r
1482 var foundToken = false;
\r
1484 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
\r
1485 if ( foundToken ) continue;
\r
1487 var re = new RegExp("^(" + jQuery.token[i] + ")");
\r
1488 var m = re.exec(t);
\r
1491 r = ret = jQuery.map( ret, jQuery.token[i+1] );
\r
1492 t = jQuery.trim( t.replace( re, "" ) );
\r
1493 foundToken = true;
\r
1497 if ( !foundToken ) {
\r
1498 if ( !t.indexOf(",") || !t.indexOf("|") ) {
\r
1499 if ( ret[0] == context ) ret.shift();
\r
1500 done = jQuery.merge( done, ret );
\r
1501 r = ret = [context];
\r
1502 t = " " + t.substr(1,t.length);
\r
1504 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
\r
1505 var m = re2.exec(t);
\r
1507 if ( m[1] == "#" ) {
\r
1508 // Ummm, should make this work in all XML docs
\r
1509 var oid = document.getElementById(m[2]);
\r
1510 r = ret = oid ? [oid] : [];
\r
1511 t = t.replace( re2, "" );
\r
1513 if ( !m[2] || m[1] == "." ) m[2] = "*";
\r
1515 for ( var i = 0; i < ret.length; i++ )
\r
1516 r = jQuery.merge( r,
\r
1518 jQuery.getAll(ret[i]) :
\r
1519 ret[i].getElementsByTagName(m[2])
\r
1527 var val = jQuery.filter(t,r);
\r
1529 t = jQuery.trim(val.t);
\r
1533 if ( ret && ret[0] == context ) ret.shift();
\r
1534 done = jQuery.merge( done, ret );
\r
1539 getAll: function(o,r) {
\r
1541 var s = o.childNodes;
\r
1542 for ( var i = 0; i < s.length; i++ )
\r
1543 if ( s[i].nodeType == 1 ) {
\r
1545 jQuery.getAll( s[i], r );
\r
1550 attr: function(elem, name, value){
\r
1553 "class": "className",
\r
1554 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
\r
1555 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
\r
1556 innerHTML: "innerHTML",
\r
1557 className: "className",
\r
1559 disabled: "disabled",
\r
1560 checked: "checked",
\r
1561 readonly: "readOnly"
\r
1564 // IE actually uses filters for opacity ... elem is actually elem.style
\r
1565 if (name == "opacity" && jQuery.browser.msie && value != undefined) {
\r
1566 // IE has trouble with opacity if it does not have layout
\r
1567 // Would prefer to check element.hasLayout first but don't have access to the element here
\r
1568 elem['zoom'] = 1;
\r
1569 if (value == 1) // Remove filter to avoid more IE weirdness
\r
1570 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"");
\r
1572 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"") + "alpha(opacity=" + value * 100 + ")";
\r
1573 } else if (name == "opacity" && jQuery.browser.msie) {
\r
1574 return elem["filter"] ? parseFloat( elem["filter"].match(/alpha\(opacity=(.*)\)/)[1] )/100 : 1;
\r
1577 // Mozilla doesn't play well with opacity 1
\r
1578 if (name == "opacity" && jQuery.browser.mozilla && value == 1) value = 0.9999;
\r
1580 if ( fix[name] ) {
\r
1581 if ( value != undefined ) elem[fix[name]] = value;
\r
1582 return elem[fix[name]];
\r
1583 } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
\r
1584 return elem.getAttributeNode(name).nodeValue;
\r
1585 } else if ( elem.tagName ) { // IE elem.getAttribute passes even for style
\r
1586 if ( value != undefined ) elem.setAttribute( name, value );
\r
1587 return elem.getAttribute( name );
\r
1589 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
\r
1590 if ( value != undefined ) elem[name] = value;
\r
1591 return elem[name];
\r
1595 // The regular expressions that power the parsing engine
\r
1597 // Match: [@value='test'], [@foo]
\r
1598 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
\r
1600 // Match: [div], [div p]
\r
1601 "(\\[)\s*(.*?)\s*\\]",
\r
1603 // Match: :contains('foo')
\r
1604 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
\r
1606 // Match: :even, :last-chlid
\r
1610 filter: function(t,r,not) {
\r
1611 // Figure out if we're doing regular, or inverse, filtering
\r
1612 var g = not !== false ? jQuery.grep :
\r
1613 function(a,f) {return jQuery.grep(a,f,true);};
\r
1615 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
\r
1617 var p = jQuery.parse;
\r
1619 for ( var i = 0; i < p.length; i++ ) {
\r
1621 // Look for, and replace, string-like sequences
\r
1622 // and finally build a regexp out of it
\r
1623 var re = new RegExp(
\r
1624 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
\r
1626 var m = re.exec( t );
\r
1629 // Re-organize the first match
\r
1631 m = ["",m[1], m[3], m[2], m[5]];
\r
1633 // Remove what we just matched
\r
1634 t = t.replace( re, "" );
\r
1640 // :not() is a special case that can be optimized by
\r
1641 // keeping it out of the expression list
\r
1642 if ( m[1] == ":" && m[2] == "not" )
\r
1643 r = jQuery.filter(m[3],r,false).r;
\r
1645 // Otherwise, find the expression to execute
\r
1647 var f = jQuery.expr[m[1]];
\r
1648 if ( f.constructor != String )
\r
1649 f = jQuery.expr[m[1]][m[2]];
\r
1651 // Build a custom macro to enclose it
\r
1652 eval("f = function(a,i){" +
\r
1653 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
\r
1654 "return " + f + "}");
\r
1656 // Execute it against the current filter
\r
1661 // Return an array of filtered elements (r)
\r
1662 // and the modified expression string (t)
\r
1663 return { r: r, t: t };
\r
1667 * Remove the whitespace from the beginning and end of a string.
\r
1669 * @example $.trim(" hello, how are you? ");
\r
1670 * @result "hello, how are you?"
\r
1674 * @param String str The string to trim.
\r
1677 trim: function(t){
\r
1678 return t.replace(/^\s+|\s+$/g, "");
\r
1682 * All ancestors of a given element.
\r
1686 * @type Array<Element>
\r
1687 * @param Element elem The element to find the ancestors of.
\r
1688 * @cat DOM/Traversing
\r
1690 parents: function( elem ){
\r
1692 var cur = elem.parentNode;
\r
1693 while ( cur && cur != document ) {
\r
1694 matched.push( cur );
\r
1695 cur = cur.parentNode;
\r
1701 * All elements on a specified axis.
\r
1706 * @param Element elem The element to find all the siblings of (including itself).
\r
1707 * @cat DOM/Traversing
\r
1709 sibling: function(elem, pos, not) {
\r
1713 var siblings = elem.parentNode.childNodes;
\r
1714 for ( var i = 0; i < siblings.length; i++ ) {
\r
1715 if ( not === true && siblings[i] == elem ) continue;
\r
1717 if ( siblings[i].nodeType == 1 )
\r
1718 elems.push( siblings[i] );
\r
1719 if ( siblings[i] == elem )
\r
1720 elems.n = elems.length - 1;
\r
1724 return jQuery.extend( elems, {
\r
1725 last: elems.n == elems.length - 1,
\r
1726 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
\r
1727 prev: elems[elems.n - 1],
\r
1728 next: elems[elems.n + 1]
\r
1733 * Merge two arrays together, removing all duplicates. The final order
\r
1734 * or the new array is: All the results from the first array, followed
\r
1735 * by the unique results from the second array.
\r
1737 * @example $.merge( [0,1,2], [2,3,4] )
\r
1738 * @result [0,1,2,3,4]
\r
1740 * @example $.merge( [3,2,1], [4,3,2] )
\r
1741 * @result [3,2,1,4]
\r
1745 * @param Array first The first array to merge.
\r
1746 * @param Array second The second array to merge.
\r
1749 merge: function(first, second) {
\r
1752 // Move b over to the new array (this helps to avoid
\r
1753 // StaticNodeList instances)
\r
1754 for ( var k = 0; k < first.length; k++ )
\r
1755 result[k] = first[k];
\r
1757 // Now check for duplicates between a and b and only
\r
1758 // add the unique items
\r
1759 for ( var i = 0; i < second.length; i++ ) {
\r
1760 var noCollision = true;
\r
1762 // The collision-checking process
\r
1763 for ( var j = 0; j < first.length; j++ )
\r
1764 if ( second[i] == first[j] )
\r
1765 noCollision = false;
\r
1767 // If the item is unique, add it
\r
1768 if ( noCollision )
\r
1769 result.push( second[i] );
\r
1776 * Filter items out of an array, by using a filter function.
\r
1777 * The specified function will be passed two arguments: The
\r
1778 * current array item and the index of the item in the array. The
\r
1779 * function should return 'true' if you wish to keep the item in
\r
1780 * the array, false if it should be removed.
\r
1782 * @example $.grep( [0,1,2], function(i){
\r
1789 * @param Array array The Array to find items in.
\r
1790 * @param Function fn The function to process each item against.
\r
1791 * @param Boolean inv Invert the selection - select the opposite of the function.
\r
1794 grep: function(elems, fn, inv) {
\r
1795 // If a string is passed in for the function, make a function
\r
1796 // for it (a handy shortcut)
\r
1797 if ( typeof fn == "string" )
\r
1798 fn = new Function("a","i","return " + fn);
\r
1802 // Go through the array, only saving the items
\r
1803 // that pass the validator function
\r
1804 for ( var i = 0; i < elems.length; i++ )
\r
1805 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
\r
1806 result.push( elems[i] );
\r
1812 * Translate all items in an array to another array of items.
\r
1813 * The translation function that is provided to this method is
\r
1814 * called for each item in the array and is passed one argument:
\r
1815 * The item to be translated. The function can then return:
\r
1816 * The translated value, 'null' (to remove the item), or
\r
1817 * an array of values - which will be flattened into the full array.
\r
1819 * @example $.map( [0,1,2], function(i){
\r
1822 * @result [4, 5, 6]
\r
1824 * @example $.map( [0,1,2], function(i){
\r
1825 * return i > 0 ? i + 1 : null;
\r
1829 * @example $.map( [0,1,2], function(i){
\r
1830 * return [ i, i + 1 ];
\r
1832 * @result [0, 1, 1, 2, 2, 3]
\r
1836 * @param Array array The Array to translate.
\r
1837 * @param Function fn The function to process each item against.
\r
1840 map: function(elems, fn) {
\r
1841 // If a string is passed in for the function, make a function
\r
1842 // for it (a handy shortcut)
\r
1843 if ( typeof fn == "string" )
\r
1844 fn = new Function("a","return " + fn);
\r
1848 // Go through the array, translating each of the items to their
\r
1849 // new value (or values).
\r
1850 for ( var i = 0; i < elems.length; i++ ) {
\r
1851 var val = fn(elems[i],i);
\r
1853 if ( val !== null && val != undefined ) {
\r
1854 if ( val.constructor != Array ) val = [val];
\r
1855 result = jQuery.merge( result, val );
\r
1863 * A number of helper functions used for managing events.
\r
1864 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
\r
1868 // Bind an event to an element
\r
1869 // Original by Dean Edwards
\r
1870 add: function(element, type, handler) {
\r
1871 // For whatever reason, IE has trouble passing the window object
\r
1872 // around, causing it to be cloned in the process
\r
1873 if ( jQuery.browser.msie && element.setInterval != undefined )
\r
1876 // Make sure that the function being executed has a unique ID
\r
1877 if ( !handler.guid )
\r
1878 handler.guid = this.guid++;
\r
1880 // Init the element's event structure
\r
1881 if (!element.events)
\r
1882 element.events = {};
\r
1884 // Get the current list of functions bound to this event
\r
1885 var handlers = element.events[type];
\r
1887 // If it hasn't been initialized yet
\r
1889 // Init the event handler queue
\r
1890 handlers = element.events[type] = {};
\r
1892 // Remember an existing handler, if it's already there
\r
1893 if (element["on" + type])
\r
1894 handlers[0] = element["on" + type];
\r
1897 // Add the function to the element's handler list
\r
1898 handlers[handler.guid] = handler;
\r
1900 // And bind the global event handler to the element
\r
1901 element["on" + type] = this.handle;
\r
1903 // Remember the function in a global list (for triggering)
\r
1904 if (!this.global[type])
\r
1905 this.global[type] = [];
\r
1906 this.global[type].push( element );
\r
1912 // Detach an event or set of events from an element
\r
1913 remove: function(element, type, handler) {
\r
1914 if (element.events)
\r
1915 if (type && element.events[type])
\r
1917 delete element.events[type][handler.guid];
\r
1919 for ( var i in element.events[type] )
\r
1920 delete element.events[type][i];
\r
1922 for ( var j in element.events )
\r
1923 this.remove( element, j );
\r
1926 trigger: function(type,data,element) {
\r
1927 // Clone the incoming data, if any
\r
1928 data = $.merge([], data || []);
\r
1930 // Handle a global trigger
\r
1932 var g = this.global[type];
\r
1934 for ( var i = 0; i < g.length; i++ )
\r
1935 this.trigger( type, data, g[i] );
\r
1937 // Handle triggering a single element
\r
1938 } else if ( element["on" + type] ) {
\r
1939 // Pass along a fake event
\r
1940 data.unshift( this.fix({ type: type, target: element }) );
\r
1942 // Trigger the event
\r
1943 element["on" + type].apply( element, data );
\r
1947 handle: function(event) {
\r
1948 if ( typeof jQuery == "undefined" ) return false;
\r
1950 event = jQuery.event.fix( event || window.event || {} ); // Empty object is for triggered events with no data
\r
1952 // If no correct event was found, fail
\r
1953 if ( !event ) return false;
\r
1955 var returnValue = true;
\r
1957 var c = this.events[event.type];
\r
1959 var args = [].slice.call( arguments, 1 );
\r
1960 args.unshift( event );
\r
1962 for ( var j in c ) {
\r
1963 if ( c[j].apply( this, args ) === false ) {
\r
1964 event.preventDefault();
\r
1965 event.stopPropagation();
\r
1966 returnValue = false;
\r
1970 // Clean up added properties in IE to prevent memory leak
\r
1971 if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = null;
\r
1973 return returnValue;
\r
1976 fix: function(event) {
\r
1978 if(jQuery.browser.msie) {
\r
1979 // fix target property, if available
\r
1980 // check prevents overwriting of fake target coming from trigger
\r
1981 if(event.srcElement)
\r
1982 event.target = event.srcElement;
\r
1984 // calculate pageX/Y
\r
1985 var e = document.documentElement, b = document.body;
\r
1986 event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft);
\r
1987 event.pageY = event.clientY + (e.scrollTop || b.scrollTop);
\r
1989 // check safari and if target is a textnode
\r
1990 } else if(jQuery.browser.safari && event.target.nodeType == 3) {
\r
1991 // target is readonly, clone the event object
\r
1992 event = jQuery.extend({}, event);
\r
1993 // get parentnode from textnode
\r
1994 event.target = event.target.parentNode;
\r
1997 // fix preventDefault and stopPropagation
\r
1998 if (!event.preventDefault)
\r
1999 event.preventDefault = function() {
\r
2000 this.returnValue = false;
\r
2003 if (!event.stopPropagation)
\r
2004 event.stopPropagation = function() {
\r
2005 this.cancelBubble = true;
\r
2014 * Contains flags for the useragent, read from navigator.userAgent.
\r
2015 * Available flags are: safari, opera, msie, mozilla
\r
2016 * This property is available before the DOM is ready, therefore you can
\r
2017 * use it to add ready events only for certain browsers.
\r
2019 * There are situations where object detections is not reliable enough, in that
\r
2020 * cases it makes sense to use browser detection. Simply try to avoid both!
\r
2022 * A combination of browser and object detection yields quite reliable results.
\r
2024 * @example $.browser.msie
\r
2025 * @desc Returns true if the current useragent is some version of microsoft's internet explorer
\r
2027 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
\r
2028 * @desc Alerts "this is safari!" only for safari browsers
\r
2037 * Wheather the W3C compliant box model is being used.
\r
2040 * @name $.boxModel
\r
2045 var b = navigator.userAgent.toLowerCase();
\r
2047 // Figure out what browser is being used
\r
2048 jQuery.browser = {
\r
2049 safari: /webkit/.test(b),
\r
2050 opera: /opera/.test(b),
\r
2051 msie: /msie/.test(b) && !/opera/.test(b),
\r
2052 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
\r
2055 // Check to see if the W3C box model is being used
\r
2056 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
\r
2062 * Append all of the matched elements to another, specified, set of elements.
\r
2063 * This operation is, essentially, the reverse of doing a regular
\r
2064 * $(A).append(B), in that instead of appending B to A, you're appending
\r
2067 * @example $("p").appendTo("#foo");
\r
2068 * @before <p>I would like to say: </p><div id="foo"></div>
\r
2069 * @result <div id="foo"><p>I would like to say: </p></div>
\r
2073 * @param String expr A jQuery expression of elements to match.
\r
2074 * @cat DOM/Manipulation
\r
2076 appendTo: "append",
\r
2079 * Prepend all of the matched elements to another, specified, set of elements.
\r
2080 * This operation is, essentially, the reverse of doing a regular
\r
2081 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
\r
2084 * @example $("p").prependTo("#foo");
\r
2085 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
\r
2086 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
\r
2090 * @param String expr A jQuery expression of elements to match.
\r
2091 * @cat DOM/Manipulation
\r
2093 prependTo: "prepend",
\r
2096 * Insert all of the matched elements before another, specified, set of elements.
\r
2097 * This operation is, essentially, the reverse of doing a regular
\r
2098 * $(A).before(B), in that instead of inserting B before A, you're inserting
\r
2101 * @example $("p").insertBefore("#foo");
\r
2102 * @before <div id="foo">Hello</div><p>I would like to say: </p>
\r
2103 * @result <p>I would like to say: </p><div id="foo">Hello</div>
\r
2105 * @name insertBefore
\r
2107 * @param String expr A jQuery expression of elements to match.
\r
2108 * @cat DOM/Manipulation
\r
2110 insertBefore: "before",
\r
2113 * Insert all of the matched elements after another, specified, set of elements.
\r
2114 * This operation is, essentially, the reverse of doing a regular
\r
2115 * $(A).after(B), in that instead of inserting B after A, you're inserting
\r
2118 * @example $("p").insertAfter("#foo");
\r
2119 * @before <p>I would like to say: </p><div id="foo">Hello</div>
\r
2120 * @result <div id="foo">Hello</div><p>I would like to say: </p>
\r
2122 * @name insertAfter
\r
2124 * @param String expr A jQuery expression of elements to match.
\r
2125 * @cat DOM/Manipulation
\r
2127 insertAfter: "after"
\r
2131 * Get the current CSS width of the first matched element.
\r
2133 * @example $("p").width();
\r
2134 * @before <p>This is just a test.</p>
\r
2143 * Set the CSS width of every matched element. Be sure to include
\r
2144 * the "px" (or other unit of measurement) after the number that you
\r
2145 * specify, otherwise you might get strange results.
\r
2147 * @example $("p").width("20px");
\r
2148 * @before <p>This is just a test.</p>
\r
2149 * @result <p style="width:20px;">This is just a test.</p>
\r
2153 * @param String val Set the CSS property to the specified value.
\r
2158 * Get the current CSS height of the first matched element.
\r
2160 * @example $("p").height();
\r
2161 * @before <p>This is just a test.</p>
\r
2170 * Set the CSS height of every matched element. Be sure to include
\r
2171 * the "px" (or other unit of measurement) after the number that you
\r
2172 * specify, otherwise you might get strange results.
\r
2174 * @example $("p").height("20px");
\r
2175 * @before <p>This is just a test.</p>
\r
2176 * @result <p style="height:20px;">This is just a test.</p>
\r
2180 * @param String val Set the CSS property to the specified value.
\r
2185 * Get the current CSS top of the first matched element.
\r
2187 * @example $("p").top();
\r
2188 * @before <p>This is just a test.</p>
\r
2197 * Set the CSS top of every matched element. Be sure to include
\r
2198 * the "px" (or other unit of measurement) after the number that you
\r
2199 * specify, otherwise you might get strange results.
\r
2201 * @example $("p").top("20px");
\r
2202 * @before <p>This is just a test.</p>
\r
2203 * @result <p style="top:20px;">This is just a test.</p>
\r
2207 * @param String val Set the CSS property to the specified value.
\r
2212 * Get the current CSS left of the first matched element.
\r
2214 * @example $("p").left();
\r
2215 * @before <p>This is just a test.</p>
\r
2224 * Set the CSS left of every matched element. Be sure to include
\r
2225 * the "px" (or other unit of measurement) after the number that you
\r
2226 * specify, otherwise you might get strange results.
\r
2228 * @example $("p").left("20px");
\r
2229 * @before <p>This is just a test.</p>
\r
2230 * @result <p style="left:20px;">This is just a test.</p>
\r
2234 * @param String val Set the CSS property to the specified value.
\r
2239 * Get the current CSS position of the first matched element.
\r
2241 * @example $("p").position();
\r
2242 * @before <p>This is just a test.</p>
\r
2243 * @result "static"
\r
2251 * Set the CSS position of every matched element.
\r
2253 * @example $("p").position("relative");
\r
2254 * @before <p>This is just a test.</p>
\r
2255 * @result <p style="position:relative;">This is just a test.</p>
\r
2259 * @param String val Set the CSS property to the specified value.
\r
2264 * Get the current CSS float of the first matched element.
\r
2266 * @example $("p").float();
\r
2267 * @before <p>This is just a test.</p>
\r
2276 * Set the CSS float of every matched element.
\r
2278 * @example $("p").float("left");
\r
2279 * @before <p>This is just a test.</p>
\r
2280 * @result <p style="float:left;">This is just a test.</p>
\r
2284 * @param String val Set the CSS property to the specified value.
\r
2289 * Get the current CSS overflow of the first matched element.
\r
2291 * @example $("p").overflow();
\r
2292 * @before <p>This is just a test.</p>
\r
2301 * Set the CSS overflow of every matched element.
\r
2303 * @example $("p").overflow("auto");
\r
2304 * @before <p>This is just a test.</p>
\r
2305 * @result <p style="overflow:auto;">This is just a test.</p>
\r
2309 * @param String val Set the CSS property to the specified value.
\r
2314 * Get the current CSS color of the first matched element.
\r
2316 * @example $("p").color();
\r
2317 * @before <p>This is just a test.</p>
\r
2326 * Set the CSS color of every matched element.
\r
2328 * @example $("p").color("blue");
\r
2329 * @before <p>This is just a test.</p>
\r
2330 * @result <p style="color:blue;">This is just a test.</p>
\r
2334 * @param String val Set the CSS property to the specified value.
\r
2339 * Get the current CSS background of the first matched element.
\r
2341 * @example $("p").background();
\r
2342 * @before <p style="background:blue;">This is just a test.</p>
\r
2345 * @name background
\r
2351 * Set the CSS background of every matched element.
\r
2353 * @example $("p").background("blue");
\r
2354 * @before <p>This is just a test.</p>
\r
2355 * @result <p style="background:blue;">This is just a test.</p>
\r
2357 * @name background
\r
2359 * @param String val Set the CSS property to the specified value.
\r
2363 css: "width,height,top,left,position,float,overflow,color,background".split(","),
\r
2366 * Reduce the set of matched elements to a single element.
\r
2367 * The position of the element in the set of matched elements
\r
2368 * starts at 0 and goes to length - 1.
\r
2370 * @example $("p").eq(1)
\r
2371 * @before <p>This is just a test.</p><p>So is this</p>
\r
2372 * @result [ <p>So is this</p> ]
\r
2376 * @param Number pos The index of the element that you wish to limit to.
\r
2381 * Reduce the set of matched elements to all elements before a given position.
\r
2382 * The position of the element in the set of matched elements
\r
2383 * starts at 0 and goes to length - 1.
\r
2385 * @example $("p").lt(1)
\r
2386 * @before <p>This is just a test.</p><p>So is this</p>
\r
2387 * @result [ <p>This is just a test.</p> ]
\r
2391 * @param Number pos Reduce the set to all elements below this position.
\r
2396 * Reduce the set of matched elements to all elements after a given position.
\r
2397 * The position of the element in the set of matched elements
\r
2398 * starts at 0 and goes to length - 1.
\r
2400 * @example $("p").gt(0)
\r
2401 * @before <p>This is just a test.</p><p>So is this</p>
\r
2402 * @result [ <p>So is this</p> ]
\r
2406 * @param Number pos Reduce the set to all elements after this position.
\r
2411 * Filter the set of elements to those that contain the specified text.
\r
2413 * @example $("p").contains("test")
\r
2414 * @before <p>This is just a test.</p><p>So is this</p>
\r
2415 * @result [ <p>This is just a test.</p> ]
\r
2419 * @param String str The string that will be contained within the text of an element.
\r
2420 * @cat DOM/Traversing
\r
2423 filter: [ "eq", "lt", "gt", "contains" ],
\r
2427 * Get the current value of the first matched element.
\r
2429 * @example $("input").val();
\r
2430 * @before <input type="text" value="some text"/>
\r
2431 * @result "some text"
\r
2435 * @cat DOM/Attributes
\r
2439 * Set the value of every matched element.
\r
2441 * @example $("input").val("test");
\r
2442 * @before <input type="text" value="some text"/>
\r
2443 * @result <input type="text" value="test"/>
\r
2447 * @param String val Set the property to the specified value.
\r
2448 * @cat DOM/Attributes
\r
2453 * Get the html contents of the first matched element.
\r
2455 * @example $("div").html();
\r
2456 * @before <div><input/></div>
\r
2457 * @result <input/>
\r
2461 * @cat DOM/Attributes
\r
2465 * Set the html contents of every matched element.
\r
2467 * @example $("div").html("<b>new stuff</b>");
\r
2468 * @before <div><input/></div>
\r
2469 * @result <div><b>new stuff</b></div>
\r
2473 * @param String val Set the html contents to the specified value.
\r
2474 * @cat DOM/Attributes
\r
2476 html: "innerHTML",
\r
2479 * Get the current id of the first matched element.
\r
2481 * @example $("input").id();
\r
2482 * @before <input type="text" id="test" value="some text"/>
\r
2487 * @cat DOM/Attributes
\r
2491 * Set the id of every matched element.
\r
2493 * @example $("input").id("newid");
\r
2494 * @before <input type="text" id="test" value="some text"/>
\r
2495 * @result <input type="text" id="newid" value="some text"/>
\r
2499 * @param String val Set the property to the specified value.
\r
2500 * @cat DOM/Attributes
\r
2505 * Get the current title of the first matched element.
\r
2507 * @example $("img").title();
\r
2508 * @before <img src="test.jpg" title="my image"/>
\r
2509 * @result "my image"
\r
2513 * @cat DOM/Attributes
\r
2517 * Set the title of every matched element.
\r
2519 * @example $("img").title("new title");
\r
2520 * @before <img src="test.jpg" title="my image"/>
\r
2521 * @result <img src="test.jpg" title="new image"/>
\r
2525 * @param String val Set the property to the specified value.
\r
2526 * @cat DOM/Attributes
\r
2531 * Get the current name of the first matched element.
\r
2533 * @example $("input").name();
\r
2534 * @before <input type="text" name="username"/>
\r
2535 * @result "username"
\r
2539 * @cat DOM/Attributes
\r
2543 * Set the name of every matched element.
\r
2545 * @example $("input").name("user");
\r
2546 * @before <input type="text" name="username"/>
\r
2547 * @result <input type="text" name="user"/>
\r
2551 * @param String val Set the property to the specified value.
\r
2552 * @cat DOM/Attributes
\r
2557 * Get the current href of the first matched element.
\r
2559 * @example $("a").href();
\r
2560 * @before <a href="test.html">my link</a>
\r
2561 * @result "test.html"
\r
2565 * @cat DOM/Attributes
\r
2569 * Set the href of every matched element.
\r
2571 * @example $("a").href("test2.html");
\r
2572 * @before <a href="test.html">my link</a>
\r
2573 * @result <a href="test2.html">my link</a>
\r
2577 * @param String val Set the property to the specified value.
\r
2578 * @cat DOM/Attributes
\r
2583 * Get the current src of the first matched element.
\r
2585 * @example $("img").src();
\r
2586 * @before <img src="test.jpg" title="my image"/>
\r
2587 * @result "test.jpg"
\r
2591 * @cat DOM/Attributes
\r
2595 * Set the src of every matched element.
\r
2597 * @example $("img").src("test2.jpg");
\r
2598 * @before <img src="test.jpg" title="my image"/>
\r
2599 * @result <img src="test2.jpg" title="my image"/>
\r
2603 * @param String val Set the property to the specified value.
\r
2604 * @cat DOM/Attributes
\r
2609 * Get the current rel of the first matched element.
\r
2611 * @example $("a").rel();
\r
2612 * @before <a href="test.html" rel="nofollow">my link</a>
\r
2613 * @result "nofollow"
\r
2617 * @cat DOM/Attributes
\r
2621 * Set the rel of every matched element.
\r
2623 * @example $("a").rel("nofollow");
\r
2624 * @before <a href="test.html">my link</a>
\r
2625 * @result <a href="test.html" rel="nofollow">my link</a>
\r
2629 * @param String val Set the property to the specified value.
\r
2630 * @cat DOM/Attributes
\r
2637 * Get a set of elements containing the unique parents of the matched
\r
2638 * set of elements.
\r
2640 * @example $("p").parent()
\r
2641 * @before <div><p>Hello</p><p>Hello</p></div>
\r
2642 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
\r
2646 * @cat DOM/Traversing
\r
2650 * Get a set of elements containing the unique parents of the matched
\r
2651 * set of elements, and filtered by an expression.
\r
2653 * @example $("p").parent(".selected")
\r
2654 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
\r
2655 * @result [ <div class="selected"><p>Hello Again</p></div> ]
\r
2659 * @param String expr An expression to filter the parents with
\r
2660 * @cat DOM/Traversing
\r
2662 parent: "a.parentNode",
\r
2665 * Get a set of elements containing the unique ancestors of the matched
\r
2666 * set of elements (except for the root element).
\r
2668 * @example $("span").ancestors()
\r
2669 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2670 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
\r
2674 * @cat DOM/Traversing
\r
2678 * Get a set of elements containing the unique ancestors of the matched
\r
2679 * set of elements, and filtered by an expression.
\r
2681 * @example $("span").ancestors("p")
\r
2682 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2683 * @result [ <p><span>Hello</span></p> ]
\r
2687 * @param String expr An expression to filter the ancestors with
\r
2688 * @cat DOM/Traversing
\r
2690 ancestors: jQuery.parents,
\r
2693 * Get a set of elements containing the unique ancestors of the matched
\r
2694 * set of elements (except for the root element).
\r
2696 * @example $("span").ancestors()
\r
2697 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2698 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
\r
2702 * @cat DOM/Traversing
\r
2706 * Get a set of elements containing the unique ancestors of the matched
\r
2707 * set of elements, and filtered by an expression.
\r
2709 * @example $("span").ancestors("p")
\r
2710 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2711 * @result [ <p><span>Hello</span></p> ]
\r
2715 * @param String expr An expression to filter the ancestors with
\r
2716 * @cat DOM/Traversing
\r
2718 parents: jQuery.parents,
\r
2721 * Get a set of elements containing the unique next siblings of each of the
\r
2722 * matched set of elements.
\r
2724 * It only returns the very next sibling, not all next siblings.
\r
2726 * @example $("p").next()
\r
2727 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
\r
2728 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
\r
2732 * @cat DOM/Traversing
\r
2736 * Get a set of elements containing the unique next siblings of each of the
\r
2737 * matched set of elements, and filtered by an expression.
\r
2739 * It only returns the very next sibling, not all next siblings.
\r
2741 * @example $("p").next(".selected")
\r
2742 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
\r
2743 * @result [ <p class="selected">Hello Again</p> ]
\r
2747 * @param String expr An expression to filter the next Elements with
\r
2748 * @cat DOM/Traversing
\r
2750 next: "jQuery.sibling(a).next",
\r
2753 * Get a set of elements containing the unique previous siblings of each of the
\r
2754 * matched set of elements.
\r
2756 * It only returns the immediately previous sibling, not all previous siblings.
\r
2758 * @example $("p").prev()
\r
2759 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
2760 * @result [ <div><span>Hello Again</span></div> ]
\r
2764 * @cat DOM/Traversing
\r
2768 * Get a set of elements containing the unique previous siblings of each of the
\r
2769 * matched set of elements, and filtered by an expression.
\r
2771 * It only returns the immediately previous sibling, not all previous siblings.
\r
2773 * @example $("p").prev(".selected")
\r
2774 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
\r
2775 * @result [ <div><span>Hello</span></div> ]
\r
2779 * @param String expr An expression to filter the previous Elements with
\r
2780 * @cat DOM/Traversing
\r
2782 prev: "jQuery.sibling(a).prev",
\r
2785 * Get a set of elements containing all of the unique siblings of each of the
\r
2786 * matched set of elements.
\r
2788 * @example $("div").siblings()
\r
2789 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
2790 * @result [ <p>Hello</p>, <p>And Again</p> ]
\r
2794 * @cat DOM/Traversing
\r
2798 * Get a set of elements containing all of the unique siblings of each of the
\r
2799 * matched set of elements, and filtered by an expression.
\r
2801 * @example $("div").siblings(".selected")
\r
2802 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
\r
2803 * @result [ <p class="selected">Hello Again</p> ]
\r
2807 * @param String expr An expression to filter the sibling Elements with
\r
2808 * @cat DOM/Traversing
\r
2810 siblings: "jQuery.sibling(a, null, true)",
\r
2814 * Get a set of elements containing all of the unique children of each of the
\r
2815 * matched set of elements.
\r
2817 * @example $("div").children()
\r
2818 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
2819 * @result [ <span>Hello Again</span> ]
\r
2823 * @cat DOM/Traversing
\r
2827 * Get a set of elements containing all of the unique children of each of the
\r
2828 * matched set of elements, and filtered by an expression.
\r
2830 * @example $("div").children(".selected")
\r
2831 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
\r
2832 * @result [ <p class="selected">Hello Again</p> ]
\r
2836 * @param String expr An expression to filter the child Elements with
\r
2837 * @cat DOM/Traversing
\r
2839 children: "jQuery.sibling(a.firstChild)"
\r
2845 * Remove an attribute from each of the matched elements.
\r
2847 * @example $("input").removeAttr("disabled")
\r
2848 * @before <input disabled="disabled"/>
\r
2849 * @result <input/>
\r
2851 * @name removeAttr
\r
2853 * @param String name The name of the attribute to remove.
\r
2856 removeAttr: function( key ) {
\r
2857 jQuery.attr( this, key, "" );
\r
2858 this.removeAttribute( key );
\r
2862 * Displays each of the set of matched elements if they are hidden.
\r
2864 * @example $("p").show()
\r
2865 * @before <p style="display: none">Hello</p>
\r
2866 * @result [ <p style="display: block">Hello</p> ]
\r
2873 this.style.display = this.oldblock ? this.oldblock : "";
\r
2874 if ( jQuery.css(this,"display") == "none" )
\r
2875 this.style.display = "block";
\r
2879 * Hides each of the set of matched elements if they are shown.
\r
2881 * @example $("p").hide()
\r
2882 * @before <p>Hello</p>
\r
2883 * @result [ <p style="display: none">Hello</p> ]
\r
2885 * var pass = true, div = $("div");
\r
2886 * div.hide().each(function(){
\r
2887 * if ( this.style.display != "none" ) pass = false;
\r
2889 * ok( pass, "Hide" );
\r
2896 this.oldblock = this.oldblock || jQuery.css(this,"display");
\r
2897 if ( this.oldblock == "none" )
\r
2898 this.oldblock = "block";
\r
2899 this.style.display = "none";
\r
2903 * Toggles each of the set of matched elements. If they are shown,
\r
2904 * toggle makes them hidden. If they are hidden, toggle
\r
2905 * makes them shown.
\r
2907 * @example $("p").toggle()
\r
2908 * @before <p>Hello</p><p style="display: none">Hello Again</p>
\r
2909 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
\r
2915 toggle: function(){
\r
2916 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
\r
2920 * Adds the specified class to each of the set of matched elements.
\r
2922 * @example $("p").addClass("selected")
\r
2923 * @before <p>Hello</p>
\r
2924 * @result [ <p class="selected">Hello</p> ]
\r
2928 * @param String class A CSS class to add to the elements
\r
2931 addClass: function(c){
\r
2932 jQuery.className.add(this,c);
\r
2936 * Removes the specified class from the set of matched elements.
\r
2938 * @example $("p").removeClass("selected")
\r
2939 * @before <p class="selected">Hello</p>
\r
2940 * @result [ <p>Hello</p> ]
\r
2942 * @name removeClass
\r
2944 * @param String class A CSS class to remove from the elements
\r
2947 removeClass: function(c){
\r
2948 jQuery.className.remove(this,c);
\r
2952 * Adds the specified class if it is not present, removes it if it is
\r
2955 * @example $("p").toggleClass("selected")
\r
2956 * @before <p>Hello</p><p class="selected">Hello Again</p>
\r
2957 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
\r
2959 * @name toggleClass
\r
2961 * @param String class A CSS class with which to toggle the elements
\r
2964 toggleClass: function( c ){
\r
2965 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
\r
2969 * Removes all matched elements from the DOM. This does NOT remove them from the
\r
2970 * jQuery object, allowing you to use the matched elements further.
\r
2972 * @example $("p").remove();
\r
2973 * @before <p>Hello</p> how are <p>you?</p>
\r
2978 * @cat DOM/Manipulation
\r
2982 * Removes only elements (out of the list of matched elements) that match
\r
2983 * the specified jQuery expression. This does NOT remove them from the
\r
2984 * jQuery object, allowing you to use the matched elements further.
\r
2986 * @example $("p").remove(".hello");
\r
2987 * @before <p class="hello">Hello</p> how are <p>you?</p>
\r
2988 * @result how are <p>you?</p>
\r
2992 * @param String expr A jQuery expression to filter elements by.
\r
2993 * @cat DOM/Manipulation
\r
2995 remove: function(a){
\r
2996 if ( !a || jQuery.filter( a, [this] ).r )
\r
2997 this.parentNode.removeChild( this );
\r
3001 * Removes all child nodes from the set of matched elements.
\r
3003 * @example $("p").empty()
\r
3004 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
\r
3005 * @result [ <p></p> ]
\r
3009 * @cat DOM/Manipulation
\r
3011 empty: function(){
\r
3012 while ( this.firstChild )
\r
3013 this.removeChild( this.firstChild );
\r
3017 * Binds a handler to a particular event (like click) for each matched element.
\r
3018 * The event handler is passed an event object that you can use to prevent
\r
3019 * default behaviour. To stop both default action and event bubbling, your handler
\r
3020 * has to return false.
\r
3022 * @example $("p").bind( "click", function() {
\r
3023 * alert( $(this).text() );
\r
3025 * @before <p>Hello</p>
\r
3026 * @result alert("Hello")
\r
3028 * @example $("form").bind( "submit", function() { return false; } )
\r
3029 * @desc Cancel a default action and prevent it from bubbling by returning false
\r
3030 * from your function.
\r
3032 * @example $("form").bind( "submit", function(event) {
\r
3033 * event.preventDefault();
\r
3035 * @desc Cancel only the default action by using the preventDefault method.
\r
3038 * @example $("form").bind( "submit", function(event) {
\r
3039 * event.stopPropagation();
\r
3041 * @desc Stop only an event from bubbling by using the stopPropagation method.
\r
3045 * @param String type An event type
\r
3046 * @param Function fn A function to bind to the event on each of the set of matched elements
\r
3049 bind: function( type, fn ) {
\r
3050 jQuery.event.add( this, type, fn );
\r
3054 * The opposite of bind, removes a bound event from each of the matched
\r
3055 * elements. You must pass the identical function that was used in the original
\r
3058 * @example $("p").unbind( "click", function() { alert("Hello"); } )
\r
3059 * @before <p onclick="alert('Hello');">Hello</p>
\r
3060 * @result [ <p>Hello</p> ]
\r
3064 * @param String type An event type
\r
3065 * @param Function fn A function to unbind from the event on each of the set of matched elements
\r
3070 * Removes all bound events of a particular type from each of the matched
\r
3073 * @example $("p").unbind( "click" )
\r
3074 * @before <p onclick="alert('Hello');">Hello</p>
\r
3075 * @result [ <p>Hello</p> ]
\r
3079 * @param String type An event type
\r
3084 * Removes all bound events from each of the matched elements.
\r
3086 * @example $("p").unbind()
\r
3087 * @before <p onclick="alert('Hello');">Hello</p>
\r
3088 * @result [ <p>Hello</p> ]
\r
3094 unbind: function( type, fn ) {
\r
3095 jQuery.event.remove( this, type, fn );
\r
3099 * Trigger a type of event on every matched element.
\r
3101 * @example $("p").trigger("click")
\r
3102 * @before <p click="alert('hello')">Hello</p>
\r
3103 * @result alert('hello')
\r
3107 * @param String type An event type to trigger.
\r
3110 trigger: function( type, data ) {
\r
3111 jQuery.event.trigger( type, data, this );
\r