2 * jQuery - 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
18 * @test ok( Array.prototype.push, "Array.push()" );
\r
19 * ok( Function.prototype.apply, "Function.apply()" );
\r
20 * ok( document.getElementById, "getElementById" );
\r
21 * ok( document.getElementsByTagName, "getElementsByTagName" );
\r
22 * ok( RegExp, "RegExp" );
\r
23 * ok( jQuery, "jQuery" );
\r
31 jQuery = function(a,c) {
\r
33 // Shortcut for document ready (because $(document).each() is silly)
\r
34 if ( a && typeof a == "function" && jQuery.fn.ready )
\r
35 return jQuery(document).ready(a);
\r
37 // Make sure that a selection was provided
\r
38 a = a || jQuery.context || document;
\r
40 // Watch for when a jQuery object is passed as the selector
\r
42 return jQuery( jQuery.merge( a, [] ) );
\r
44 // Watch for when a jQuery object is passed at the context
\r
45 if ( c && c.jquery )
\r
46 return jQuery( c ).find(a);
\r
48 // If the context is global, return a new object
\r
49 if ( window == this )
\r
50 return new jQuery(a,c);
\r
52 // Handle HTML strings
\r
53 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
\r
54 if ( m ) a = jQuery.clean( [ m[1] ] );
\r
56 // Watch for when an array is passed in
\r
57 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
\r
58 // Assume that it is an array of DOM Elements
\r
59 jQuery.merge( a, [] ) :
\r
61 // Find the matching elements and save them for later
\r
62 jQuery.find( a, c ) );
\r
64 // See if an extra function was provided
\r
65 var fn = arguments[ arguments.length - 1 ];
\r
67 // If so, execute it in context
\r
68 if ( fn && typeof fn == "function" )
\r
72 // Map over the $ in case of overwrite
\r
73 if ( typeof $ != "undefined" )
\r
77 * This function accepts a string containing a CSS selector,
\r
78 * basic XPath, or raw HTML, which is then used to match a set of elements.
\r
79 * The HTML string is different from the traditional selectors in that
\r
80 * it creates the DOM elements representing that HTML string, on the fly,
\r
81 * to be (assumedly) inserted into the document later.
\r
83 * The core functionality of jQuery centers around this function.
\r
84 * Everything in jQuery is based upon this, or uses this in some way.
\r
85 * The most basic use of this function is to pass in an expression
\r
86 * (usually consisting of CSS or XPath), which then finds all matching
\r
87 * elements and remembers them for later use.
\r
89 * By default, $() looks for DOM elements within the context of the
\r
90 * current HTML document.
\r
92 * @example $("div > p")
\r
93 * @desc This finds all p elements that are children of a div element.
\r
94 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
\r
95 * @result [ <p>two</p> ]
\r
97 * @example $("<div><p>Hello</p></div>").appendTo("#body")
\r
98 * @desc Creates a div element (and all of its contents) dynamically,
\r
99 * and appends it to the element with the ID of body. Internally, an
\r
100 * element is created and it's innerHTML property set to the given markup.
\r
101 * It is therefore both quite flexible and limited.
104 * @param String expr An expression to search with, or a string of HTML to create on the fly.
\r
110 * This function accepts a string containing a CSS selector, or
\r
111 * basic XPath, which is then used to match a set of elements with the
\r
112 * context of the specified DOM element, or document
\r
114 * @example $("div", xml.responseXML)
\r
115 * @desc This finds all div elements within the specified XML document.
\r
118 * @param String expr An expression to search with.
\r
119 * @param Element context A DOM Element, or Document, representing the base context.
\r
125 * Wrap jQuery functionality around a specific DOM Element.
\r
126 * This function also accepts XML Documents and Window objects
\r
127 * as valid arguments (even though they are not DOM Elements).
\r
129 * @example $(document).find("div > p")
\r
130 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
\r
131 * @result [ <p>two</p> ]
\r
133 * @example $(document.body).background( "black" );
\r
134 * @desc Sets the background color of the page to black.
\r
137 * @param Element elem A DOM element to be encapsulated by a jQuery object.
\r
143 * Wrap jQuery functionality around a set of DOM Elements.
\r
145 * @example $( myForm.elements ).hide()
\r
146 * @desc Hides all the input elements within a form
\r
149 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
\r
155 * A shorthand for $(document).ready(), allowing you to bind a function
\r
156 * to be executed when the DOM document has finished loading. This function
\r
157 * behaves just like $(document).ready(), in that it should be used to wrap
\r
158 * all of the other $() operations on your page. While this function is,
\r
159 * technically, chainable - there really isn't much use for chaining against it.
\r
160 * You can have as many $(document).ready events on your page as you like.
\r
162 * @example $(function(){
\r
163 * // Document is ready
\r
165 * @desc Executes the function when the DOM is ready to be used.
\r
168 * @param Function fn The function to execute when the DOM is ready.
\r
174 * A means of creating a cloned copy of a jQuery object. This function
\r
175 * copies the set of matched elements from one jQuery object and creates
\r
176 * another, new, jQuery object containing the same elements.
\r
178 * @example var div = $("div");
\r
179 * $( div ).find("p");
\r
180 * @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
183 * @param jQuery obj The jQuery object to be cloned.
\r
188 // Map the jQuery namespace to the '$' one
\r
191 jQuery.fn = jQuery.prototype = {
\r
193 * The current SVN version of jQuery.
\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
210 * @test ok( $("div").length == 2, "Get Number of Elements Found" );
\r
219 * The number of elements currently matched.
\r
221 * @example $("img").size();
\r
222 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
225 * @test ok( $("div").size() == 2, "Get Number of Elements Found" );
\r
232 return this.length;
\r
236 * Access all matched elements. This serves as a backwards-compatible
\r
237 * way of accessing all matched elements (other than the jQuery object
\r
238 * itself, which is, in fact, an array of elements).
\r
240 * @example $("img").get();
\r
241 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
242 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
\r
244 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
\r
247 * @type Array<Element>
\r
252 * Access a single matched element. num is used to access the
\r
253 * Nth element matched.
\r
255 * @example $("img").get(1);
\r
256 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
257 * @result [ <img src="test1.jpg"/> ]
\r
259 * @test ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
\r
263 * @param Number num Access the element in the Nth position.
\r
268 * Set the jQuery object to an array of elements.
\r
270 * @example $("img").get([ document.body ]);
\r
271 * @result $("img").get() == [ document.body ]
\r
276 * @param Elements elems An array of elements
\r
279 get: function( num ) {
\r
280 // Watch for when an array (of elements) is passed in
\r
281 if ( num && num.constructor == Array ) {
\r
283 // Use a tricky hack to make the jQuery object
\r
284 // look and feel like an array
\r
286 [].push.apply( this, num );
\r
290 return num == undefined ?
\r
292 // Return a 'clean' array
\r
293 jQuery.merge( this, [] ) :
\r
295 // Return just the object
\r
300 * Execute a function within the context of every matched element.
\r
301 * This means that every time the passed-in function is executed
\r
302 * (which is once for every element matched) the 'this' keyword
\r
303 * points to the specific element.
\r
305 * Additionally, the function, when executed, is passed a single
\r
306 * argument representing the position of the element in the matched
\r
309 * @example $("img").each(function(){
\r
310 * this.src = "test.jpg";
\r
312 * @before <img/> <img/>
\r
313 * @result <img src="test.jpg"/> <img src="test.jpg"/>
\r
315 * @example $("img").each(function(i){
\r
316 * alert( "Image #" + i + " is " + this );
\r
318 * @before <img/> <img/>
\r
319 * @result <img src="test.jpg"/> <img src="test.jpg"/>
\r
321 * @test var div = $("div");
\r
322 * div.each(function(){this.foo = 'zoo';});
\r
324 * for ( var i = 0; i < div.size(); i++ ) {
\r
325 * if ( div.get(i).foo != "zoo" ) pass = false;
\r
327 * ok( pass, "Execute a function, Relative" );
\r
331 * @param Function fn A function to execute
\r
334 each: function( fn, args ) {
\r
335 return jQuery.each( this, fn, args );
\r
339 * Searches every matched element for the object and returns
\r
340 * the index of the element, if found, starting with zero.
\r
341 * Returns -1 if the object wasn't found.
\r
343 * @example $("*").index(document.getElementById('foobar'))
\r
344 * @before <div id="foobar"></div><b></b><span id="foo"></span>
\r
347 * @example $("*").index(document.getElementById('foo'))
\r
348 * @before <div id="foobar"></div><b></b><span id="foo"></span>
\r
351 * @example $("*").index(document.getElementById('bar'))
\r
352 * @before <div id="foobar"></div><b></b><span id="foo"></span>
\r
355 * @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );
\r
356 * ok( $([window, document]).index(document) == 1, "Check for index of elements" );
\r
357 * var inputElements = $('#radio1,#radio2,#check1,#check2');
\r
358 * ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
\r
359 * ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
\r
360 * ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
\r
361 * ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
\r
362 * ok( inputElements.index(window) == -1, "Check for not found index" );
\r
363 * ok( inputElements.index(document) == -1, "Check for not found index" );
\r
367 * @param Object obj Object to search for
\r
370 index: function( obj ) {
\r
372 this.each(function(i){
\r
373 if ( this == obj ) pos = i;
\r
379 * Access a property on the first matched element.
\r
380 * This method makes it easy to retrieve a property value
\r
381 * from the first matched element.
\r
383 * @example $("img").attr("src");
\r
384 * @before <img src="test.jpg"/>
\r
387 * @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
\r
388 * ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
\r
389 * ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
\r
390 * ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
\r
391 * ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
\r
392 * ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
\r
393 * ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
\r
394 * ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
\r
395 * ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
\r
396 * ok( $('#name').attr('name') == "name", 'Check for name attribute' );
\r
397 * ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
\r
398 * ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
\r
402 * @param String name The name of the property to access.
\r
407 * Set a hash of key/value object properties to all matched elements.
\r
408 * This serves as the best way to set a large number of properties
\r
409 * on all matched elements.
\r
411 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
\r
413 * @result <img src="test.jpg" alt="Test Image"/>
\r
415 * @test var pass = true;
\r
416 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
\r
417 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
\r
419 * ok( pass, "Set Multiple Attributes" );
\r
423 * @param Hash prop A set of key/value pairs to set as object properties.
\r
428 * Set a single property to a value, on all matched elements.
\r
430 * @example $("img").attr("src","test.jpg");
\r
432 * @result <img src="test.jpg"/>
\r
434 * @test var div = $("div");
\r
435 * div.attr("foo", "bar");
\r
437 * for ( var i = 0; i < div.size(); i++ ) {
\r
438 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
\r
440 * ok( pass, "Set Attribute" );
\r
442 * $("#name").attr('name', 'something');
\r
443 * ok( $("#name").name() == 'something', 'Set name attribute' );
\r
444 * $("#check2").attr('checked', true);
\r
445 * ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
\r
446 * $("#check2").attr('checked', false);
\r
447 * ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
\r
451 * @param String key The name of the property to set.
\r
452 * @param Object value The value to set the property to.
\r
455 attr: function( key, value, type ) {
\r
456 // Check to see if we're setting style values
\r
457 return key.constructor != String || value != undefined ?
\r
458 this.each(function(){
\r
459 // See if we're setting a hash of styles
\r
460 if ( value == undefined )
\r
461 // Set all the styles
\r
462 for ( var prop in key )
\r
464 type ? this.style : this,
\r
468 // See if we're setting a single key/value style
\r
471 type ? this.style : this,
\r
476 // Look for the case where we're accessing a style value
\r
477 jQuery[ type || "attr" ]( this[0], key );
\r
481 * Access a style property on the first matched element.
\r
482 * This method makes it easy to retrieve a style property value
\r
483 * from the first matched element.
\r
485 * @example $("p").css("color");
\r
486 * @before <p style="color:red;">Test Paragraph.</p>
\r
488 * @desc Retrieves the color style of the first paragraph
\r
490 * @example $("p").css("fontWeight");
\r
491 * @before <p style="font-weight: bold;">Test Paragraph.</p>
\r
493 * @desc Retrieves the font-weight style of the first paragraph.
\r
494 * Note that for all style properties with a dash (like 'font-weight'), you have to
\r
495 * write it in camelCase. In other words: Every time you have a '-' in a
\r
496 * property, remove it and replace the next character with an uppercase
\r
497 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
\r
498 * borderStyle, borderBottomWidth etc.
\r
500 * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"');
\r
504 * @param String name The name of the property to access.
\r
509 * Set a hash of key/value style properties to all matched elements.
\r
510 * This serves as the best way to set a large number of style properties
\r
511 * on all matched elements.
\r
513 * @example $("p").css({ color: "red", background: "blue" });
\r
514 * @before <p>Test Paragraph.</p>
\r
515 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
\r
517 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
518 * $('#foo').css({display: 'none'});
\r
519 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
520 * $('#foo').css({display: 'block'});
\r
521 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
525 * @param Hash prop A set of key/value pairs to set as style properties.
\r
530 * Set a single style property to a value, on all matched elements.
\r
532 * @example $("p").css("color","red");
\r
533 * @before <p>Test Paragraph.</p>
\r
534 * @result <p style="color:red;">Test Paragraph.</p>
\r
535 * @desc Changes the color of all paragraphs to red
\r
538 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
539 * $('#foo').css('display', 'none');
\r
540 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
541 * $('#foo').css('display', 'block');
\r
542 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
546 * @param String key The name of the property to set.
\r
547 * @param Object value The value to set the property to.
\r
550 css: function( key, value ) {
\r
551 return this.attr( key, value, "curCSS" );
\r
555 * Retrieve the text contents of all matched elements. The result is
\r
556 * a string that contains the combined text contents of all matched
\r
557 * elements. This method works on both HTML and XML documents.
\r
559 * @example $("p").text();
\r
560 * @before <p>Test Paragraph.</p>
\r
561 * @result Test Paragraph.
\r
563 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
\r
564 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
\r
570 text: function(e) {
\r
573 for ( var j = 0; j < e.length; j++ ) {
\r
574 var r = e[j].childNodes;
\r
575 for ( var i = 0; i < r.length; i++ )
\r
576 if ( r[i].nodeType != 8 )
\r
577 t += r[i].nodeType != 1 ?
\r
578 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
\r
584 * Wrap all matched elements with a structure of other elements.
\r
585 * This wrapping process is most useful for injecting additional
\r
586 * stucture into a document, without ruining the original semantic
\r
587 * qualities of a document.
\r
589 * This works by going through the first element
\r
590 * provided (which is generated, on the fly, from the provided HTML)
\r
591 * and finds the deepest ancestor element within its
\r
592 * structure - it is that element that will en-wrap everything else.
\r
594 * This does not work with elements that contain text. Any necessary text
\r
595 * must be added after the wrapping is done.
\r
597 * @example $("p").wrap("<div class='wrap'></div>");
\r
598 * @before <p>Test Paragraph.</p>
\r
599 * @result <div class='wrap'><p>Test Paragraph.</p></div>
\r
601 * @test var defaultText = 'Try them out:'
\r
602 * var result = $('#first').wrap('<div class="red"><span></span></div>').text();
\r
603 * ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
\r
604 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
608 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
\r
609 * @cat DOM/Manipulation
\r
613 * Wrap all matched elements with a structure of other elements.
\r
614 * This wrapping process is most useful for injecting additional
\r
615 * stucture into a document, without ruining the original semantic
\r
616 * qualities of a document.
\r
618 * This works by going through the first element
\r
619 * provided and finding the deepest ancestor element within its
\r
620 * structure - it is that element that will en-wrap everything else.
\r
622 * This does not work with elements that contain text. Any necessary text
\r
623 * must be added after the wrapping is done.
\r
625 * @example $("p").wrap( document.getElementById('content') );
\r
626 * @before <p>Test Paragraph.</p><div id="content"></div>
\r
627 * @result <div id="content"><p>Test Paragraph.</p></div>
\r
629 * @test var defaultText = 'Try them out:'
\r
630 * var result = $('#first').wrap(document.getElementById('empty')).parent();
\r
631 * ok( result.is('ol'), 'Check for element wrapping' );
\r
632 * ok( result.text() == defaultText, 'Check for element wrapping' );
\r
636 * @param Element elem A DOM element that will be wrapped.
\r
637 * @cat DOM/Manipulation
\r
640 // The elements to wrap the target around
\r
641 var a = jQuery.clean(arguments);
\r
643 // Wrap each of the matched elements individually
\r
644 return this.each(function(){
\r
645 // Clone the structure that we're using to wrap
\r
646 var b = a[0].cloneNode(true);
\r
648 // Insert it before the element to be wrapped
\r
649 this.parentNode.insertBefore( b, this );
\r
651 // Find the deepest point in the wrap structure
\r
652 while ( b.firstChild )
\r
655 // Move the matched element to within the wrap structure
\r
656 b.appendChild( this );
\r
661 * Append any number of elements to the inside of every matched elements,
\r
662 * generated from the provided HTML.
\r
663 * This operation is similar to doing an appendChild to all the
\r
664 * specified elements, adding them into the document.
\r
666 * @example $("p").append("<b>Hello</b>");
\r
667 * @before <p>I would like to say: </p>
\r
668 * @result <p>I would like to say: <b>Hello</b></p>
\r
670 * @test var defaultText = 'Try them out:'
\r
671 * var result = $('#first').append('<b>buga</b>');
\r
672 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
\r
676 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
677 * @cat DOM/Manipulation
\r
681 * Append an element to the inside of all matched elements.
\r
682 * This operation is similar to doing an appendChild to all the
\r
683 * specified elements, adding them into the document.
\r
685 * @example $("p").append( $("#foo")[0] );
\r
686 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
687 * @result <p>I would like to say: <b id="foo">Hello</b></p>
\r
689 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
690 * $('#sap').append(document.getElementById('first'));
\r
691 * ok( expected == $('#sap').text(), "Check for appending of element" );
\r
695 * @param Element elem A DOM element that will be appended.
\r
696 * @cat DOM/Manipulation
\r
700 * Append any number of elements to the inside of all matched elements.
\r
701 * This operation is similar to doing an appendChild to all the
\r
702 * specified elements, adding them into the document.
\r
704 * @example $("p").append( $("b") );
\r
705 * @before <p>I would like to say: </p><b>Hello</b>
\r
706 * @result <p>I would like to say: <b>Hello</b></p>
\r
708 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
709 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
\r
710 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
714 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
715 * @cat DOM/Manipulation
\r
717 append: function() {
\r
718 return this.domManip(arguments, true, 1, function(a){
\r
719 this.appendChild( a );
\r
724 * Prepend any number of elements to the inside of every matched elements,
\r
725 * generated from the provided HTML.
\r
726 * This operation is the best way to insert dynamically created elements
\r
727 * inside, at the beginning, of all the matched element.
\r
729 * @example $("p").prepend("<b>Hello</b>");
\r
730 * @before <p>I would like to say: </p>
\r
731 * @result <p><b>Hello</b>I would like to say: </p>
\r
733 * @test var defaultText = 'Try them out:'
\r
734 * var result = $('#first').prepend('<b>buga</b>');
\r
735 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
739 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
740 * @cat DOM/Manipulation
\r
744 * Prepend an element to the inside of all matched elements.
\r
745 * This operation is the best way to insert an element inside, at the
\r
746 * beginning, of all the matched element.
\r
748 * @example $("p").prepend( $("#foo")[0] );
\r
749 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
750 * @result <p><b id="foo">Hello</b>I would like to say: </p>
\r
752 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
753 * $('#sap').prepend(document.getElementById('first'));
\r
754 * ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
758 * @param Element elem A DOM element that will be appended.
\r
759 * @cat DOM/Manipulation
\r
763 * Prepend any number of elements to the inside of all matched elements.
\r
764 * This operation is the best way to insert a set of elements inside, at the
\r
765 * beginning, of all the matched element.
\r
767 * @example $("p").prepend( $("b") );
\r
768 * @before <p>I would like to say: </p><b>Hello</b>
\r
769 * @result <p><b>Hello</b>I would like to say: </p>
\r
771 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
772 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
\r
773 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
777 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
778 * @cat DOM/Manipulation
\r
780 prepend: function() {
\r
781 return this.domManip(arguments, true, -1, function(a){
\r
782 this.insertBefore( a, this.firstChild );
\r
787 * Insert any number of dynamically generated elements before each of the
\r
788 * matched elements.
\r
790 * @example $("p").before("<b>Hello</b>");
\r
791 * @before <p>I would like to say: </p>
\r
792 * @result <b>Hello</b><p>I would like to say: </p>
\r
794 * @test var expected = 'This is a normal link: bugaYahoo';
\r
795 * $('#yahoo').before('<b>buga</b>');
\r
796 * ok( expected == $('#en').text(), 'Insert String before' );
\r
800 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
801 * @cat DOM/Manipulation
\r
805 * Insert an element before each of the matched elements.
\r
807 * @example $("p").before( $("#foo")[0] );
\r
808 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
809 * @result <b id="foo">Hello</b><p>I would like to say: </p>
\r
811 * @test var expected = "This is a normal link: Try them out:Yahoo";
\r
812 * $('#yahoo').before(document.getElementById('first'));
\r
813 * ok( expected == $('#en').text(), "Insert element before" );
\r
817 * @param Element elem A DOM element that will be appended.
\r
818 * @cat DOM/Manipulation
\r
822 * Insert any number of elements before each of the matched elements.
\r
824 * @example $("p").before( $("b") );
\r
825 * @before <p>I would like to say: </p><b>Hello</b>
\r
826 * @result <b>Hello</b><p>I would like to say: </p>
\r
828 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
829 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
\r
830 * ok( expected == $('#en').text(), "Insert array of elements before" );
\r
834 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
835 * @cat DOM/Manipulation
\r
837 before: function() {
\r
838 return this.domManip(arguments, false, 1, function(a){
\r
839 this.parentNode.insertBefore( a, this );
\r
844 * Insert any number of dynamically generated elements after each of the
\r
845 * matched elements.
\r
847 * @example $("p").after("<b>Hello</b>");
\r
848 * @before <p>I would like to say: </p>
\r
849 * @result <p>I would like to say: </p><b>Hello</b>
\r
851 * @test var expected = 'This is a normal link: Yahoobuga';
\r
852 * $('#yahoo').after('<b>buga</b>');
\r
853 * ok( expected == $('#en').text(), 'Insert String after' );
\r
857 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
858 * @cat DOM/Manipulation
\r
862 * Insert an element after each of the matched elements.
\r
864 * @example $("p").after( $("#foo")[0] );
\r
865 * @before <b id="foo">Hello</b><p>I would like to say: </p>
\r
866 * @result <p>I would like to say: </p><b id="foo">Hello</b>
\r
868 * @test var expected = "This is a normal link: YahooTry them out:";
\r
869 * $('#yahoo').after(document.getElementById('first'));
\r
870 * ok( expected == $('#en').text(), "Insert element after" );
\r
874 * @param Element elem A DOM element that will be appended.
\r
875 * @cat DOM/Manipulation
\r
879 * Insert any number of elements after each of the matched elements.
\r
881 * @example $("p").after( $("b") );
\r
882 * @before <b>Hello</b><p>I would like to say: </p>
\r
883 * @result <p>I would like to say: </p><b>Hello</b>
\r
885 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
\r
886 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
\r
887 * ok( expected == $('#en').text(), "Insert array of elements after" );
\r
891 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
892 * @cat DOM/Manipulation
\r
894 after: function() {
\r
895 return this.domManip(arguments, false, -1, function(a){
\r
896 this.parentNode.insertBefore( a, this.nextSibling );
\r
901 * End the most recent 'destructive' operation, reverting the list of matched elements
\r
902 * back to its previous state. After an end operation, the list of matched elements will
\r
903 * revert to the last state of matched elements.
\r
905 * @example $("p").find("span").end();
\r
906 * @before <p><span>Hello</span>, how are you?</p>
\r
907 * @result $("p").find("span").end() == [ <p>...</p> ]
\r
909 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
\r
913 * @cat DOM/Traversing
\r
916 return this.get( this.stack.pop() );
\r
920 * Searches for all elements that match the specified expression.
\r
921 * This method is the optimal way of finding additional descendant
\r
922 * elements with which to process.
\r
924 * All searching is done using a jQuery expression. The expression can be
\r
925 * written using CSS 1-3 Selector syntax, or basic XPath.
\r
927 * @example $("p").find("span");
\r
928 * @before <p><span>Hello</span>, how are you?</p>
\r
929 * @result $("p").find("span") == [ <span>Hello</span> ]
\r
931 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
\r
935 * @param String expr An expression to search with.
\r
936 * @cat DOM/Traversing
\r
938 find: function(t) {
\r
939 return this.pushStack( jQuery.map( this, function(a){
\r
940 return jQuery.find(t,a);
\r
945 * Create cloned copies of all matched DOM Elements. This does
\r
946 * not create a cloned copy of this particular jQuery object,
\r
947 * instead it creates duplicate copies of all DOM Elements.
\r
948 * This is useful for moving copies of the elements to another
\r
949 * location in the DOM.
\r
951 * @example $("b").clone().prependTo("p");
\r
952 * @before <b>Hello</b><p>, how are you?</p>
\r
953 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
\r
955 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
\r
956 * var clone = $('#yahoo').clone();
\r
957 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
\r
958 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
\r
962 * @cat DOM/Manipulation
\r
964 clone: function(deep) {
\r
965 return this.pushStack( jQuery.map( this, function(a){
\r
966 return a.cloneNode( deep != undefined ? deep : true );
\r
971 * Removes all elements from the set of matched elements that do not
\r
972 * match the specified expression. This method is used to narrow down
\r
973 * the results of a search.
\r
975 * All searching is done using a jQuery expression. The expression
\r
976 * can be written using CSS 1-3 Selector syntax, or basic XPath.
\r
978 * @example $("p").filter(".selected")
\r
979 * @before <p class="selected">Hello</p><p>How are you?</p>
\r
980 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
\r
982 * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
\r
983 * @test $("input").filter(":checked",function(i){
\r
984 * ok( this == q("radio2", "check1")[i], "Filter elements, context" );
\r
986 * @test $("#main > p#ap > a").filter("#foobar",function(){},function(i){
\r
987 * ok( this == q("google","groups", "mark")[i], "Filter elements, else context" );
\r
992 * @param String expr An expression to search with.
\r
993 * @cat DOM/Traversing
\r
997 * Removes all elements from the set of matched elements that do not
\r
998 * match at least one of the expressions passed to the function. This
\r
999 * method is used when you want to filter the set of matched elements
\r
1000 * through more than one expression.
\r
1002 * Elements will be retained in the jQuery object if they match at
\r
1003 * least one of the expressions passed.
\r
1005 * @example $("p").filter([".selected", ":first"])
\r
1006 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
\r
1007 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
\r
1011 * @param Array<String> exprs A set of expressions to evaluate against
\r
1012 * @cat DOM/Traversing
\r
1014 filter: function(t) {
\r
1015 return this.pushStack(
\r
1016 t.constructor == Array &&
\r
1017 jQuery.map(this,function(a){
\r
1018 for ( var i = 0; i < t.length; i++ )
\r
1019 if ( jQuery.filter(t[i],[a]).r.length )
\r
1023 t.constructor == Boolean &&
\r
1024 ( t ? this.get() : [] ) ||
\r
1026 typeof t == "function" &&
\r
1027 jQuery.grep( this, t ) ||
\r
1029 jQuery.filter(t,this).r, arguments );
\r
1033 * Removes the specified Element from the set of matched elements. This
\r
1034 * method is used to remove a single Element from a jQuery object.
\r
1036 * @example $("p").not( document.getElementById("selected") )
\r
1037 * @before <p>Hello</p><p id="selected">Hello Again</p>
\r
1038 * @result [ <p>Hello</p> ]
\r
1042 * @param Element el An element to remove from the set
\r
1043 * @cat DOM/Traversing
\r
1047 * Removes elements matching the specified expression from the set
\r
1048 * of matched elements. This method is used to remove one or more
\r
1049 * elements from a jQuery object.
\r
1051 * @example $("p").not("#selected")
\r
1052 * @before <p>Hello</p><p id="selected">Hello Again</p>
\r
1053 * @result [ <p>Hello</p> ]
\r
1055 * @test ok($("#main > p#ap > a").not("#google").length == 2, ".not")
\r
1059 * @param String expr An expression with which to remove matching elements
\r
1060 * @cat DOM/Traversing
\r
1062 not: function(t) {
\r
1063 return this.pushStack( t.constructor == String ?
\r
1064 jQuery.filter(t,this,false).r :
\r
1065 jQuery.grep(this,function(a){ return a != t; }), arguments );
\r
1069 * Adds the elements matched by the expression to the jQuery object. This
\r
1070 * can be used to concatenate the result sets of two expressions.
\r
1072 * @example $("p").add("span")
\r
1073 * @before <p>Hello</p><p><span>Hello Again</span></p>
\r
1074 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
\r
1078 * @param String expr An expression whose matched elements are added
\r
1079 * @cat DOM/Traversing
\r
1083 * Adds each of the Elements in the array to the set of matched elements.
\r
1084 * This is used to add a set of Elements to a jQuery object.
\r
1086 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
\r
1087 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
\r
1088 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
\r
1092 * @param Array<Element> els An array of Elements to add
\r
1093 * @cat DOM/Traversing
\r
1097 * Adds a single Element to the set of matched elements. This is used to
\r
1098 * add a single Element to a jQuery object.
\r
1100 * @example $("p").add( document.getElementById("a") )
\r
1101 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
\r
1102 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
\r
1106 * @param Element el An Element to add
\r
1107 * @cat DOM/Traversing
\r
1109 add: function(t) {
\r
1110 return this.pushStack( jQuery.merge( this, t.constructor == String ?
\r
1111 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
\r
1115 * Checks the current selection against an expression and returns true,
\r
1116 * if the selection fits the given expression. Does return false, if the
\r
1117 * selection does not fit or the expression is not valid.
\r
1119 * @example $("input[@type='checkbox']").parent().is("form")
\r
1120 * @before <form><input type="checkbox" /></form>
\r
1122 * @desc Returns true, because the parent of the input is a form element
\r
1124 * @example $("input[@type='checkbox']").parent().is("form")
\r
1125 * @before <form><p><input type="checkbox" /></p></form>
\r
1127 * @desc Returns false, because the parent of the input is a p element
\r
1129 * @example $("form").is(null)
\r
1130 * @before <form></form>
\r
1132 * @desc An invalid expression always returns false.
\r
1134 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
\r
1135 * ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
\r
1136 * ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
\r
1137 * ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
\r
1138 * ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
\r
1139 * ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
\r
1140 * ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
\r
1141 * ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
\r
1142 * ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
\r
1143 * ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
\r
1144 * ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
\r
1145 * ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
\r
1146 * ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
\r
1147 * ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
\r
1148 * ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
\r
1149 * ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
\r
1150 * ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
\r
1151 * ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
\r
1152 * ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
\r
1153 * ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
\r
1154 * ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
\r
1155 * ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
\r
1159 * @param String expr The expression with which to filter
\r
1160 * @cat DOM/Traversing
\r
1162 is: function(expr) {
\r
1163 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
\r
1171 * @param Array args
\r
1172 * @param Boolean table
\r
1173 * @param Number int
\r
1174 * @param Function fn The function doing the DOM manipulation.
\r
1178 domManip: function(args, table, dir, fn){
\r
1179 var clone = this.size() > 1;
\r
1180 var a = jQuery.clean(args);
\r
1182 return this.each(function(){
\r
1185 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
\r
1186 var tbody = this.getElementsByTagName("tbody");
\r
1188 if ( !tbody.length ) {
\r
1189 obj = document.createElement("tbody");
\r
1190 this.appendChild( obj );
\r
1195 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
\r
1196 i != ( dir < 0 ? dir : a.length ); i += dir ) {
\r
1197 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
\r
1208 * @param Array args
\r
1212 pushStack: function(a,args) {
\r
1213 var fn = args && args[args.length-1];
\r
1214 var fn2 = args && args[args.length-2];
\r
1216 if ( fn && fn.constructor != Function ) fn = null;
\r
1217 if ( fn2 && fn2.constructor != Function ) fn2 = null;
\r
1220 if ( !this.stack ) this.stack = [];
\r
1221 this.stack.push( this.get() );
\r
1224 var old = this.get();
\r
1227 if ( fn2 && a.length || !fn2 )
\r
1228 this.each( fn2 || fn ).get( old );
\r
1230 this.get( old ).each( fn );
\r
1238 * Extends the jQuery object itself. Can be used to add both static
\r
1239 * functions and plugin methods.
\r
1241 * @example $.fn.extend({
\r
1242 * check: function() {
\r
1243 * this.each(function() { this.checked = true; });
\r
1245 * uncheck: function() {
\r
1246 * this.each(function() { this.checked = false; });
\r
1249 * $("input[@type=checkbox]").check();
\r
1250 * $("input[@type=radio]").uncheck();
\r
1251 * @desc Adds two plugin methods.
\r
1255 * @param Object obj
\r
1261 * Extend one object with another, returning the original,
\r
1262 * modified, object. This is a great utility for simple inheritance.
\r
1264 * @example var settings = { validate: false, limit: 5, name: "foo" };
\r
1265 * var options = { validate: true, name: "bar" };
\r
1266 * jQuery.extend(settings, options);
\r
1267 * @result settings == { validate: true, limit: 5, name: "bar" }
\r
1269 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
\r
1270 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
\r
1271 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
\r
1272 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
\r
1273 * jQuery.extend(settings, options);
\r
1274 * isSet( settings, merged, "Check if extended: settings must be extended" );
\r
1275 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
1278 * @param Object obj The object to extend
\r
1279 * @param Object prop The object that will be merged into the first.
\r
1283 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
\r
1284 if ( !prop ) { prop = obj; obj = this; }
\r
1285 for ( var i in prop ) obj[i] = prop[i];
\r
1297 jQuery.initDone = true;
\r
1299 jQuery.each( jQuery.macros.axis, function(i,n){
\r
1300 jQuery.fn[ i ] = function(a) {
\r
1301 var ret = jQuery.map(this,n);
\r
1302 if ( a && a.constructor == String )
\r
1303 ret = jQuery.filter(a,ret).r;
\r
1304 return this.pushStack( ret, arguments );
\r
1308 jQuery.each( jQuery.macros.to, function(i,n){
\r
1309 jQuery.fn[ i ] = function(){
\r
1310 var a = arguments;
\r
1311 return this.each(function(){
\r
1312 for ( var j = 0; j < a.length; j++ )
\r
1313 jQuery(a[j])[n]( this );
\r
1318 jQuery.each( jQuery.macros.each, function(i,n){
\r
1319 jQuery.fn[ i ] = function() {
\r
1320 return this.each( n, arguments );
\r
1324 jQuery.each( jQuery.macros.filter, function(i,n){
\r
1325 jQuery.fn[ n ] = function(num,fn) {
\r
1326 return this.filter( ":" + n + "(" + num + ")", fn );
\r
1330 jQuery.each( jQuery.macros.attr, function(i,n){
\r
1332 jQuery.fn[ i ] = function(h) {
\r
1333 return h == undefined ?
\r
1334 this.length ? this[0][n] : null :
\r
1335 this.attr( n, h );
\r
1339 jQuery.each( jQuery.macros.css, function(i,n){
\r
1340 jQuery.fn[ n ] = function(h) {
\r
1341 return h == undefined ?
\r
1342 ( this.length ? jQuery.css( this[0], n ) : null ) :
\r
1350 * A generic iterator function, which can be used to seemlessly
\r
1351 * iterate over both objects and arrays. This function is not the same
\r
1352 * as $().each() - which is used to iterate, exclusively, over a jQuery
\r
1353 * object. This function can be used to iterate over anything.
\r
1355 * @example $.each( [0,1,2], function(i){
\r
1356 * alert( "Item #" + i + ": " + this );
\r
1358 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
\r
1360 * @example $.each( { name: "John", lang: "JS" }, function(i){
\r
1361 * alert( "Name: " + i + ", Value: " + this );
\r
1363 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
\r
1366 * @param Object obj The object, or array, to iterate over.
\r
1367 * @param Function fn The function that will be executed on every object.
\r
1371 each: function( obj, fn, args ) {
\r
1372 if ( obj.length == undefined )
\r
1373 for ( var i in obj )
\r
1374 fn.apply( obj[i], args || [i, obj[i]] );
\r
1376 for ( var i = 0; i < obj.length; i++ )
\r
1377 fn.apply( obj[i], args || [i, obj[i]] );
\r
1382 add: function(o,c){
\r
1383 if (jQuery.className.has(o,c)) return;
\r
1384 o.className += ( o.className ? " " : "" ) + c;
\r
1386 remove: function(o,c){
\r
1388 o.className = !c ? "" :
\r
1389 o.className.replace(
\r
1390 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");*/
\r
1394 var classes = o.className.split(" ");
\r
1395 for(var i=0; i<classes.length; i++) {
\r
1396 if(classes[i] == c) {
\r
1397 classes.splice(i, 1);
\r
1401 o.className = classes.join(' ');
\r
1404 has: function(e,a) {
\r
1405 if ( e.className != undefined )
\r
1407 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
\r
1412 * Swap in/out style options.
\r
1415 swap: function(e,o,f) {
\r
1416 for ( var i in o ) {
\r
1417 e.style["old"+i] = e.style[i];
\r
1418 e.style[i] = o[i];
\r
1421 for ( var i in o )
\r
1422 e.style[i] = e.style["old"+i];
\r
1425 css: function(e,p) {
\r
1426 if ( p == "height" || p == "width" ) {
\r
1427 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
\r
1429 for ( var i in d ) {
\r
1430 old["padding" + d[i]] = 0;
\r
1431 old["border" + d[i] + "Width"] = 0;
\r
1434 jQuery.swap( e, old, function() {
\r
1435 if (jQuery.css(e,"display") != "none") {
\r
1436 oHeight = e.offsetHeight;
\r
1437 oWidth = e.offsetWidth;
\r
1439 e = jQuery(e.cloneNode(true)).css({
\r
1440 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
\r
1441 }).appendTo(e.parentNode)[0];
\r
1443 var parPos = jQuery.css(e.parentNode,"position");
\r
1444 if ( parPos == "" || parPos == "static" )
\r
1445 e.parentNode.style.position = "relative";
\r
1447 oHeight = e.clientHeight;
\r
1448 oWidth = e.clientWidth;
\r
1450 if ( parPos == "" || parPos == "static" )
\r
1451 e.parentNode.style.position = "static";
\r
1453 e.parentNode.removeChild(e);
\r
1457 return p == "height" ? oHeight : oWidth;
\r
1458 } else if ( p == "opacity" && jQuery.browser.msie )
\r
1459 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
\r
1461 return jQuery.curCSS( e, p );
\r
1464 curCSS: function(elem, prop, force) {
\r
1467 if (!force && elem.style[prop]) {
\r
1469 ret = elem.style[prop];
\r
1471 } else if (elem.currentStyle) {
\r
1473 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
\r
1474 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
\r
1476 } else if (document.defaultView && document.defaultView.getComputedStyle) {
\r
1478 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
\r
1479 var cur = document.defaultView.getComputedStyle(elem, null);
\r
1482 ret = cur.getPropertyValue(prop);
\r
1483 else if ( prop == 'display' )
\r
1486 jQuery.swap(elem, { display: 'block' }, function() {
\r
1487 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
\r
1495 clean: function(a) {
\r
1497 for ( var i = 0; i < a.length; i++ ) {
\r
1498 if ( a[i].constructor == String ) {
\r
1502 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
\r
1504 a[i] = "<table>" + a[i] + "</table>";
\r
1505 } else if ( !a[i].indexOf("<tr") ) {
\r
1507 a[i] = "<table>" + a[i] + "</table>";
\r
1508 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
\r
1510 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
\r
1513 var div = document.createElement("div");
\r
1514 div.innerHTML = a[i];
\r
1517 div = div.firstChild;
\r
1518 if ( table != "thead" ) div = div.firstChild;
\r
1519 if ( table == "td" ) div = div.firstChild;
\r
1522 for ( var j = 0; j < div.childNodes.length; j++ )
\r
1523 r.push( div.childNodes[j] );
\r
1524 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
\r
1525 for ( var k = 0; k < a[i].length; k++ )
\r
1526 r.push( a[i][k] );
\r
1527 else if ( a[i] !== null )
\r
1528 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
\r
1534 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
\r
1535 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
\r
1537 // Position Checks
\r
1543 last: "i==r.length-1",
\r
1548 "nth-child": "jQuery.sibling(a,m[3]).cur",
\r
1549 "first-child": "jQuery.sibling(a,0).cur",
\r
1550 "last-child": "jQuery.sibling(a,0).last",
\r
1551 "only-child": "jQuery.sibling(a).length==1",
\r
1554 parent: "a.childNodes.length",
\r
1555 empty: "!a.childNodes.length",
\r
1558 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
\r
1561 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
\r
1562 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
\r
1564 // Form attributes
\r
1565 enabled: "!a.disabled",
\r
1566 disabled: "a.disabled",
\r
1567 checked: "a.checked",
\r
1568 selected: "a.selected",
\r
1571 text: "a.type=='text'",
\r
1572 radio: "a.type=='radio'",
\r
1573 checkbox: "a.type=='checkbox'",
\r
1574 file: "a.type=='file'",
\r
1575 password: "a.type=='password'",
\r
1576 submit: "a.type=='submit'",
\r
1577 image: "a.type=='image'",
\r
1578 reset: "a.type=='reset'",
\r
1579 button: "a.type=='button'",
\r
1580 input: "a.nodeName.toLowerCase().match(/input|select|textarea|button/)"
\r
1582 ".": "jQuery.className.has(a,m[2])",
\r
1586 "^=": "z && !z.indexOf(m[4])",
\r
1587 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
\r
1588 "*=": "z && z.indexOf(m[4])>=0",
\r
1591 "[": "jQuery.find(m[2],a).length"
\r
1595 "\\.\\.|/\\.\\.", "a.parentNode",
\r
1596 ">|/", "jQuery.sibling(a.firstChild)",
\r
1597 "\\+", "jQuery.sibling(a).next",
\r
1600 var s = jQuery.sibling(a);
\r
1602 for ( var i = s.n; i < s.length; i++ )
\r
1610 * @test t( "Element Selector", "div", ["main","foo"] );
\r
1611 * t( "Element Selector", "body", ["body"] );
\r
1612 * t( "Element Selector", "html", ["html"] );
\r
1613 * ok( $("*").size() >= 30, "Element Selector" );
\r
1614 * t( "Parent Element", "div div", ["foo"] );
\r
1616 * t( "ID Selector", "#body", ["body"] );
\r
1617 * t( "ID Selector w/ Element", "body#body", ["body"] );
\r
1618 * t( "ID Selector w/ Element", "ul#first", [] );
\r
1620 * t( "Class Selector", ".blog", ["mark","simon"] );
\r
1621 * t( "Class Selector", ".blog.link", ["simon"] );
\r
1622 * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
\r
1623 * t( "Parent Class Selector", "p .blog", ["mark","simon"] );
\r
1625 * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
\r
1626 * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
\r
1627 * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
\r
1628 * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
\r
1630 * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
1631 * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
1632 * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
1633 * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
1634 * t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
\r
1635 * t( "All Children", "code > *", ["anchor1","anchor2"] );
\r
1636 * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
\r
1637 * t( "Adjacent", "a + a", ["groups"] );
\r
1638 * t( "Adjacent", "a +a", ["groups"] );
\r
1639 * t( "Adjacent", "a+ a", ["groups"] );
\r
1640 * t( "Adjacent", "a+a", ["groups"] );
\r
1641 * t( "Adjacent", "p + p", ["ap","en","sap"] );
\r
1642 * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
\r
1643 * t( "First Child", "p:first-child", ["firstp","sndp"] );
\r
1644 * t( "Attribute Exists", "a[@title]", ["google"] );
\r
1645 * t( "Attribute Exists", "*[@title]", ["google"] );
\r
1646 * t( "Attribute Exists", "[@title]", ["google"] );
\r
1648 * t( "Non-existing part of attribute [@name*=bla]", "[@name*=bla]", [] );
\r
1649 * t( "Non-existing start of attribute [@name^=bla]", "[@name^=bla]", [] );
\r
1650 * t( "Non-existing end of attribute [@name$=bla]", "[@name$=bla]", [] );
\r
1652 * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
\r
1653 * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
\r
1654 * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
\r
1655 * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
\r
1656 * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
\r
1657 * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
\r
1659 * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
\r
1660 * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
\r
1661 * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
\r
1662 * t( "First Child", "p:first-child", ["firstp","sndp"] );
\r
1663 * t( "Last Child", "p:last-child", ["sap"] );
\r
1664 * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
\r
1665 * t( "Empty", "ul:empty", ["firstUL"] );
\r
1666 * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
\r
1667 * t( "Disabled UI Element", "input:disabled", ["text2"] );
\r
1668 * t( "Checked UI Element", "input:checked", ["radio2","check1"] );
\r
1669 * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
\r
1670 * t( "Text Contains", "a:contains('Google')", ["google","groups"] );
\r
1671 * t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
\r
1672 * t( "Element Preceded By", "p ~ div", ["foo"] );
\r
1673 * t( "Not", "a.blog:not(.link)", ["mark"] );
\r
1675 * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
\r
1676 * t( "All Div Elements", "//div", ["main","foo"] );
\r
1677 * t( "Absolute Path", "/html/body", ["body"] );
\r
1678 * t( "Absolute Path w/ *", "/* /body", ["body"] );
\r
1679 * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
\r
1680 * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
\r
1681 * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
\r
1682 * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
\r
1683 * t( "Attribute Exists", "//a[@title]", ["google"] );
\r
1684 * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
\r
1685 * t( "Parent Axis", "//p/..", ["main","foo"] );
\r
1686 * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
\r
1687 * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
\r
1688 * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
\r
1690 * t( "nth Element", "p:nth(1)", ["ap"] );
\r
1691 * t( "First Element", "p:first", ["firstp"] );
\r
1692 * t( "Last Element", "p:last", ["first"] );
\r
1693 * t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
\r
1694 * t( "Odd Elements", "p:odd", ["ap","en","first"] );
\r
1695 * t( "Position Equals", "p:eq(1)", ["ap"] );
\r
1696 * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
\r
1697 * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
\r
1698 * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
\r
1699 * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
\r
1700 * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
\r
1702 * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
\r
1704 * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
\r
1705 * t( "All Children of ID with no children", "#firstUL/*", [] );
\r
1707 * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
\r
1708 * t( "Form element :radio", ":radio", ["radio1", "radio2"] );
\r
1709 * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
\r
1710 * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
\r
1711 * t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
\r
1712 * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
\r
1713 * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
\r
1715 * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
\r
1716 * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
\r
1717 * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
\r
1720 * @type Array<Element>
\r
1724 find: function( t, context ) {
\r
1725 // Make sure that the context is a DOM Element
\r
1726 if ( context && context.nodeType == undefined )
\r
1729 // Set the correct context (if none is provided)
\r
1730 context = context || jQuery.context || document;
\r
1732 if ( t.constructor != String ) return [t];
\r
1734 if ( !t.indexOf("//") ) {
\r
1735 context = context.documentElement;
\r
1736 t = t.substr(2,t.length);
\r
1737 } else if ( !t.indexOf("/") ) {
\r
1738 context = context.documentElement;
\r
1739 t = t.substr(1,t.length);
\r
1740 // FIX Assume the root element is right :(
\r
1741 if ( t.indexOf("/") >= 1 )
\r
1742 t = t.substr(t.indexOf("/"),t.length);
\r
1745 var ret = [context];
\r
1749 while ( t.length > 0 && last != t ) {
\r
1753 t = jQuery.trim(t).replace( /^\/\//i, "" );
\r
1755 var foundToken = false;
\r
1757 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
\r
1758 if ( foundToken ) continue;
\r
1760 var re = new RegExp("^(" + jQuery.token[i] + ")");
\r
1761 var m = re.exec(t);
\r
1764 r = ret = jQuery.map( ret, jQuery.token[i+1] );
\r
1765 t = jQuery.trim( t.replace( re, "" ) );
\r
1766 foundToken = true;
\r
1770 if ( !foundToken ) {
\r
1771 if ( !t.indexOf(",") || !t.indexOf("|") ) {
\r
1772 if ( ret[0] == context ) ret.shift();
\r
1773 done = jQuery.merge( done, ret );
\r
1774 r = ret = [context];
\r
1775 t = " " + t.substr(1,t.length);
\r
1777 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
\r
1778 var m = re2.exec(t);
\r
1780 if ( m[1] == "#" ) {
\r
1781 // Ummm, should make this work in all XML docs
\r
1782 var oid = document.getElementById(m[2]);
\r
1783 r = ret = oid ? [oid] : [];
\r
1784 t = t.replace( re2, "" );
\r
1786 if ( !m[2] || m[1] == "." ) m[2] = "*";
\r
1788 for ( var i = 0; i < ret.length; i++ )
\r
1789 r = jQuery.merge( r,
\r
1791 jQuery.getAll(ret[i]) :
\r
1792 ret[i].getElementsByTagName(m[2])
\r
1800 var val = jQuery.filter(t,r);
\r
1802 t = jQuery.trim(val.t);
\r
1806 if ( ret && ret[0] == context ) ret.shift();
\r
1807 done = jQuery.merge( done, ret );
\r
1812 getAll: function(o,r) {
\r
1814 var s = o.childNodes;
\r
1815 for ( var i = 0; i < s.length; i++ )
\r
1816 if ( s[i].nodeType == 1 ) {
\r
1818 jQuery.getAll( s[i], r );
\r
1823 attr: function(elem, name, value){
\r
1826 "class": "className",
\r
1827 "float": "cssFloat",
\r
1828 innerHTML: "innerHTML",
\r
1829 className: "className",
\r
1831 disabled: "disabled",
\r
1832 checked: "checked"
\r
1835 if ( fix[name] ) {
\r
1836 if ( value != undefined ) elem[fix[name]] = value;
\r
1837 return elem[fix[name]];
\r
1838 } else if( value == undefined && $.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
\r
1839 return elem.getAttributeNode(name).nodeValue;
\r
1840 } else if ( elem.getAttribute != undefined ) {
\r
1841 if ( value != undefined ) elem.setAttribute( name, value );
\r
1842 return elem.getAttribute( name, 2 );
\r
1844 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
\r
1845 if ( value != undefined ) elem[name] = value;
\r
1846 return elem[name];
\r
1850 // The regular expressions that power the parsing engine
\r
1852 // Match: [@value='test'], [@foo]
\r
1853 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
\r
1855 // Match: [div], [div p]
\r
1856 "(\\[)\s*(.*?)\s*\\]",
\r
1858 // Match: :contains('foo')
\r
1859 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
\r
1861 // Match: :even, :last-chlid
\r
1865 filter: function(t,r,not) {
\r
1866 // Figure out if we're doing regular, or inverse, filtering
\r
1867 var g = not !== false ? jQuery.grep :
\r
1868 function(a,f) {return jQuery.grep(a,f,true);};
\r
1870 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
\r
1872 var p = jQuery.parse;
\r
1874 for ( var i = 0; i < p.length; i++ ) {
\r
1876 // Look for, and replace, string-like sequences
\r
1877 // and finally build a regexp out of it
\r
1878 var re = new RegExp(
\r
1879 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
\r
1881 var m = re.exec( t );
\r
1884 // Re-organize the first match
\r
1886 m = ["",m[1], m[3], m[2], m[5]];
\r
1888 // Remove what we just matched
\r
1889 t = t.replace( re, "" );
\r
1895 // :not() is a special case that can be optimized by
\r
1896 // keeping it out of the expression list
\r
1897 if ( m[1] == ":" && m[2] == "not" )
\r
1898 r = jQuery.filter(m[3],r,false).r;
\r
1900 // Otherwise, find the expression to execute
\r
1902 var f = jQuery.expr[m[1]];
\r
1903 if ( f.constructor != String )
\r
1904 f = jQuery.expr[m[1]][m[2]];
\r
1906 // Build a custom macro to enclose it
\r
1907 eval("f = function(a,i){" +
\r
1908 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
\r
1909 "return " + f + "}");
\r
1911 // Execute it against the current filter
\r
1916 // Return an array of filtered elements (r)
\r
1917 // and the modified expression string (t)
\r
1918 return { r: r, t: t };
\r
1922 * Remove the whitespace from the beginning and end of a string.
\r
1924 * @example $.trim(" hello, how are you? ");
\r
1925 * @result "hello, how are you?"
\r
1929 * @param String str The string to trim.
\r
1932 trim: function(t){
\r
1933 return t.replace(/^\s+|\s+$/g, "");
\r
1937 * All ancestors of a given element.
\r
1941 * @type Array<Element>
\r
1942 * @param Element elem The element to find the ancestors of.
\r
1943 * @cat DOM/Traversing
\r
1945 parents: function( elem ){
\r
1947 var cur = elem.parentNode;
\r
1948 while ( cur && cur != document ) {
\r
1949 matched.push( cur );
\r
1950 cur = cur.parentNode;
\r
1956 * All elements on a specified axis.
\r
1961 * @param Element elem The element to find all the siblings of (including itself).
\r
1962 * @cat DOM/Traversing
\r
1964 sibling: function(elem, pos, not) {
\r
1968 var siblings = elem.parentNode.childNodes;
\r
1969 for ( var i = 0; i < siblings.length; i++ ) {
\r
1970 if ( not === true && siblings[i] == elem ) continue;
\r
1972 if ( siblings[i].nodeType == 1 )
\r
1973 elems.push( siblings[i] );
\r
1974 if ( siblings[i] == elem )
\r
1975 elems.n = elems.length - 1;
\r
1979 return jQuery.extend( elems, {
\r
1980 last: elems.n == elems.length - 1,
\r
1981 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
\r
1982 prev: elems[elems.n - 1],
\r
1983 next: elems[elems.n + 1]
\r
1988 * Merge two arrays together, removing all duplicates. The final order
\r
1989 * or the new array is: All the results from the first array, followed
\r
1990 * by the unique results from the second array.
\r
1992 * @example $.merge( [0,1,2], [2,3,4] )
\r
1993 * @result [0,1,2,3,4]
\r
1995 * @example $.merge( [3,2,1], [4,3,2] )
\r
1996 * @result [3,2,1,4]
\r
2000 * @param Array first The first array to merge.
\r
2001 * @param Array second The second array to merge.
\r
2004 merge: function(first, second) {
\r
2007 // Move b over to the new array (this helps to avoid
\r
2008 // StaticNodeList instances)
\r
2009 for ( var k = 0; k < first.length; k++ )
\r
2010 result[k] = first[k];
\r
2012 // Now check for duplicates between a and b and only
\r
2013 // add the unique items
\r
2014 for ( var i = 0; i < second.length; i++ ) {
\r
2015 var noCollision = true;
\r
2017 // The collision-checking process
\r
2018 for ( var j = 0; j < first.length; j++ )
\r
2019 if ( second[i] == first[j] )
\r
2020 noCollision = false;
\r
2022 // If the item is unique, add it
\r
2023 if ( noCollision )
\r
2024 result.push( second[i] );
\r
2031 * Filter items out of an array, by using a filter function.
\r
2032 * The specified function will be passed two arguments: The
\r
2033 * current array item and the index of the item in the array. The
\r
2034 * function should return 'true' if you wish to keep the item in
\r
2035 * the array, false if it should be removed.
\r
2037 * @example $.grep( [0,1,2], function(i){
\r
2044 * @param Array array The Array to find items in.
\r
2045 * @param Function fn The function to process each item against.
\r
2046 * @param Boolean inv Invert the selection - select the opposite of the function.
\r
2049 grep: function(elems, fn, inv) {
\r
2050 // If a string is passed in for the function, make a function
\r
2051 // for it (a handy shortcut)
\r
2052 if ( fn.constructor == String )
\r
2053 fn = new Function("a","i","return " + fn);
\r
2057 // Go through the array, only saving the items
\r
2058 // that pass the validator function
\r
2059 for ( var i = 0; i < elems.length; i++ )
\r
2060 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
\r
2061 result.push( elems[i] );
\r
2067 * Translate all items in an array to another array of items.
\r
2068 * The translation function that is provided to this method is
\r
2069 * called for each item in the array and is passed one argument:
\r
2070 * The item to be translated. The function can then return:
\r
2071 * The translated value, 'null' (to remove the item), or
\r
2072 * an array of values - which will be flattened into the full array.
\r
2074 * @example $.map( [0,1,2], function(i){
\r
2077 * @result [4, 5, 6]
\r
2079 * @example $.map( [0,1,2], function(i){
\r
2080 * return i > 0 ? i + 1 : null;
\r
2084 * @example $.map( [0,1,2], function(i){
\r
2085 * return [ i, i + 1 ];
\r
2087 * @result [0, 1, 1, 2, 2, 3]
\r
2091 * @param Array array The Array to translate.
\r
2092 * @param Function fn The function to process each item against.
\r
2095 map: function(elems, fn) {
\r
2096 // If a string is passed in for the function, make a function
\r
2097 // for it (a handy shortcut)
\r
2098 if ( fn.constructor == String )
\r
2099 fn = new Function("a","return " + fn);
\r
2103 // Go through the array, translating each of the items to their
\r
2104 // new value (or values).
\r
2105 for ( var i = 0; i < elems.length; i++ ) {
\r
2106 var val = fn(elems[i],i);
\r
2108 if ( val !== null && val != undefined ) {
\r
2109 if ( val.constructor != Array ) val = [val];
\r
2110 result = jQuery.merge( result, val );
\r
2118 * A number of helper functions used for managing events.
\r
2119 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
\r
2123 // Bind an event to an element
\r
2124 // Original by Dean Edwards
\r
2125 add: function(element, type, handler) {
\r
2126 // For whatever reason, IE has trouble passing the window object
\r
2127 // around, causing it to be cloned in the process
\r
2128 if ( jQuery.browser.msie && element.setInterval != undefined )
\r
2131 // Make sure that the function being executed has a unique ID
\r
2132 if ( !handler.guid )
\r
2133 handler.guid = this.guid++;
\r
2135 // Init the element's event structure
\r
2136 if (!element.events)
\r
2137 element.events = {};
\r
2139 // Get the current list of functions bound to this event
\r
2140 var handlers = element.events[type];
\r
2142 // If it hasn't been initialized yet
\r
2144 // Init the event handler queue
\r
2145 handlers = element.events[type] = {};
\r
2147 // Remember an existing handler, if it's already there
\r
2148 if (element["on" + type])
\r
2149 handlers[0] = element["on" + type];
\r
2152 // Add the function to the element's handler list
\r
2153 handlers[handler.guid] = handler;
\r
2155 // And bind the global event handler to the element
\r
2156 element["on" + type] = this.handle;
\r
2158 // Remember the function in a global list (for triggering)
\r
2159 if (!this.global[type])
\r
2160 this.global[type] = [];
\r
2161 this.global[type].push( element );
\r
2167 // Detach an event or set of events from an element
\r
2168 remove: function(element, type, handler) {
\r
2169 if (element.events)
\r
2170 if (type && element.events[type])
\r
2172 delete element.events[type][handler.guid];
\r
2174 for ( var i in element.events[type] )
\r
2175 delete element.events[type][i];
\r
2177 for ( var j in element.events )
\r
2178 this.remove( element, j );
\r
2181 trigger: function(type,data,element) {
\r
2182 // Touch up the incoming data
\r
2183 data = data || [];
\r
2185 // Handle a global trigger
\r
2187 var g = this.global[type];
\r
2189 for ( var i = 0; i < g.length; i++ )
\r
2190 this.trigger( type, data, g[i] );
\r
2192 // Handle triggering a single element
\r
2193 } else if ( element["on" + type] ) {
\r
2194 // Pass along a fake event
\r
2195 data.unshift( this.fix({ type: type, target: element }) );
\r
2197 // Trigger the event
\r
2198 element["on" + type].apply( element, data );
\r
2202 handle: function(event) {
\r
2203 if ( typeof jQuery == "undefined" ) return;
\r
2205 event = event || jQuery.event.fix( window.event );
\r
2207 // If no correct event was found, fail
\r
2208 if ( !event ) return;
\r
2210 var returnValue = true;
\r
2212 var c = this.events[event.type];
\r
2214 var args = [].slice.call( arguments, 1 );
\r
2215 args.unshift( event );
\r
2217 for ( var j in c ) {
\r
2218 if ( c[j].apply( this, args ) === false ) {
\r
2219 event.preventDefault();
\r
2220 event.stopPropagation();
\r
2221 returnValue = false;
\r
2225 return returnValue;
\r
2228 fix: function(event) {
\r
2230 event.preventDefault = function() {
\r
2231 this.returnValue = false;
\r
2234 event.stopPropagation = function() {
\r
2235 this.cancelBubble = true;
\r
2246 * Contains flags for the useragent, read from navigator.userAgent.
\r
2247 * Available flags are: safari, opera, msie, mozilla
\r
2248 * This property is available before the DOM is ready, therefore you can
\r
2249 * use it to add ready events only for certain browsers.
\r
2251 * See <a href="http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/">
\r
2252 * jQBrowser plugin</a> for advanced browser detection:
\r
2254 * @example $.browser.msie
\r
2255 * @desc returns true if the current useragent is some version of microsoft's internet explorer
\r
2257 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
\r
2258 * @desc Alerts "this is safari!" only for safari browsers
\r
2265 var b = navigator.userAgent.toLowerCase();
\r
2267 // Figure out what browser is being used
\r
2268 jQuery.browser = {
\r
2269 safari: /webkit/.test(b),
\r
2270 opera: /opera/.test(b),
\r
2271 msie: /msie/.test(b) && !/opera/.test(b),
\r
2272 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
\r
2275 // Check to see if the W3C box model is being used
\r
2276 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
\r
2282 * Append all of the matched elements to another, specified, set of elements.
\r
2283 * This operation is, essentially, the reverse of doing a regular
\r
2284 * $(A).append(B), in that instead of appending B to A, you're appending
\r
2287 * @example $("p").appendTo("#foo");
\r
2288 * @before <p>I would like to say: </p><div id="foo"></div>
\r
2289 * @result <div id="foo"><p>I would like to say: </p></div>
\r
2293 * @param String expr A jQuery expression of elements to match.
\r
2294 * @cat DOM/Manipulation
\r
2296 appendTo: "append",
\r
2299 * Prepend all of the matched elements to another, specified, set of elements.
\r
2300 * This operation is, essentially, the reverse of doing a regular
\r
2301 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
\r
2304 * @example $("p").prependTo("#foo");
\r
2305 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
\r
2306 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
\r
2310 * @param String expr A jQuery expression of elements to match.
\r
2311 * @cat DOM/Manipulation
\r
2313 prependTo: "prepend",
\r
2316 * Insert all of the matched elements before another, specified, set of elements.
\r
2317 * This operation is, essentially, the reverse of doing a regular
\r
2318 * $(A).before(B), in that instead of inserting B before A, you're inserting
\r
2321 * @example $("p").insertBefore("#foo");
\r
2322 * @before <div id="foo">Hello</div><p>I would like to say: </p>
\r
2323 * @result <p>I would like to say: </p><div id="foo">Hello</div>
\r
2325 * @name insertBefore
\r
2327 * @param String expr A jQuery expression of elements to match.
\r
2328 * @cat DOM/Manipulation
\r
2330 insertBefore: "before",
\r
2333 * Insert all of the matched elements after another, specified, set of elements.
\r
2334 * This operation is, essentially, the reverse of doing a regular
\r
2335 * $(A).after(B), in that instead of inserting B after A, you're inserting
\r
2338 * @example $("p").insertAfter("#foo");
\r
2339 * @before <p>I would like to say: </p><div id="foo">Hello</div>
\r
2340 * @result <div id="foo">Hello</div><p>I would like to say: </p>
\r
2342 * @name insertAfter
\r
2344 * @param String expr A jQuery expression of elements to match.
\r
2345 * @cat DOM/Manipulation
\r
2347 insertAfter: "after"
\r
2351 * Get the current CSS width of the first matched element.
\r
2353 * @example $("p").width();
\r
2354 * @before <p>This is just a test.</p>
\r
2363 * Set the CSS width of every matched element. Be sure to include
\r
2364 * the "px" (or other unit of measurement) after the number that you
\r
2365 * specify, otherwise you might get strange results.
\r
2367 * @example $("p").width("20px");
\r
2368 * @before <p>This is just a test.</p>
\r
2369 * @result <p style="width:20px;">This is just a test.</p>
\r
2373 * @param String val Set the CSS property to the specified value.
\r
2378 * Get the current CSS height of the first matched element.
\r
2380 * @example $("p").height();
\r
2381 * @before <p>This is just a test.</p>
\r
2390 * Set the CSS height of every matched element. Be sure to include
\r
2391 * the "px" (or other unit of measurement) after the number that you
\r
2392 * specify, otherwise you might get strange results.
\r
2394 * @example $("p").height("20px");
\r
2395 * @before <p>This is just a test.</p>
\r
2396 * @result <p style="height:20px;">This is just a test.</p>
\r
2400 * @param String val Set the CSS property to the specified value.
\r
2405 * Get the current CSS top of the first matched element.
\r
2407 * @example $("p").top();
\r
2408 * @before <p>This is just a test.</p>
\r
2417 * Set the CSS top of every matched element. Be sure to include
\r
2418 * the "px" (or other unit of measurement) after the number that you
\r
2419 * specify, otherwise you might get strange results.
\r
2421 * @example $("p").top("20px");
\r
2422 * @before <p>This is just a test.</p>
\r
2423 * @result <p style="top:20px;">This is just a test.</p>
\r
2427 * @param String val Set the CSS property to the specified value.
\r
2432 * Get the current CSS left of the first matched element.
\r
2434 * @example $("p").left();
\r
2435 * @before <p>This is just a test.</p>
\r
2444 * Set the CSS left of every matched element. Be sure to include
\r
2445 * the "px" (or other unit of measurement) after the number that you
\r
2446 * specify, otherwise you might get strange results.
\r
2448 * @example $("p").left("20px");
\r
2449 * @before <p>This is just a test.</p>
\r
2450 * @result <p style="left:20px;">This is just a test.</p>
\r
2454 * @param String val Set the CSS property to the specified value.
\r
2459 * Get the current CSS position of the first matched element.
\r
2461 * @example $("p").position();
\r
2462 * @before <p>This is just a test.</p>
\r
2463 * @result "static"
\r
2471 * Set the CSS position of every matched element.
\r
2473 * @example $("p").position("relative");
\r
2474 * @before <p>This is just a test.</p>
\r
2475 * @result <p style="position:relative;">This is just a test.</p>
\r
2479 * @param String val Set the CSS property to the specified value.
\r
2484 * Get the current CSS float of the first matched element.
\r
2486 * @example $("p").float();
\r
2487 * @before <p>This is just a test.</p>
\r
2496 * Set the CSS float of every matched element.
\r
2498 * @example $("p").float("left");
\r
2499 * @before <p>This is just a test.</p>
\r
2500 * @result <p style="float:left;">This is just a test.</p>
\r
2504 * @param String val Set the CSS property to the specified value.
\r
2509 * Get the current CSS overflow of the first matched element.
\r
2511 * @example $("p").overflow();
\r
2512 * @before <p>This is just a test.</p>
\r
2521 * Set the CSS overflow of every matched element.
\r
2523 * @example $("p").overflow("auto");
\r
2524 * @before <p>This is just a test.</p>
\r
2525 * @result <p style="overflow:auto;">This is just a test.</p>
\r
2529 * @param String val Set the CSS property to the specified value.
\r
2534 * Get the current CSS color of the first matched element.
\r
2536 * @example $("p").color();
\r
2537 * @before <p>This is just a test.</p>
\r
2546 * Set the CSS color of every matched element.
\r
2548 * @example $("p").color("blue");
\r
2549 * @before <p>This is just a test.</p>
\r
2550 * @result <p style="color:blue;">This is just a test.</p>
\r
2554 * @param String val Set the CSS property to the specified value.
\r
2559 * Get the current CSS background of the first matched element.
\r
2561 * @example $("p").background();
\r
2562 * @before <p style="background:blue;">This is just a test.</p>
\r
2565 * @name background
\r
2571 * Set the CSS background of every matched element.
\r
2573 * @example $("p").background("blue");
\r
2574 * @before <p>This is just a test.</p>
\r
2575 * @result <p style="background:blue;">This is just a test.</p>
\r
2577 * @name background
\r
2579 * @param String val Set the CSS property to the specified value.
\r
2583 css: "width,height,top,left,position,float,overflow,color,background".split(","),
\r
2586 * Reduce the set of matched elements to a single element.
\r
2587 * The position of the element in the set of matched elements
\r
2588 * starts at 0 and goes to length - 1.
\r
2590 * @example $("p").eq(1)
\r
2591 * @before <p>This is just a test.</p><p>So is this</p>
\r
2592 * @result [ <p>So is this</p> ]
\r
2596 * @param Number pos The index of the element that you wish to limit to.
\r
2601 * Reduce the set of matched elements to all elements before a given position.
\r
2602 * The position of the element in the set of matched elements
\r
2603 * starts at 0 and goes to length - 1.
\r
2605 * @example $("p").lt(1)
\r
2606 * @before <p>This is just a test.</p><p>So is this</p>
\r
2607 * @result [ <p>This is just a test.</p> ]
\r
2611 * @param Number pos Reduce the set to all elements below this position.
\r
2616 * Reduce the set of matched elements to all elements after a given position.
\r
2617 * The position of the element in the set of matched elements
\r
2618 * starts at 0 and goes to length - 1.
\r
2620 * @example $("p").gt(0)
\r
2621 * @before <p>This is just a test.</p><p>So is this</p>
\r
2622 * @result [ <p>So is this</p> ]
\r
2626 * @param Number pos Reduce the set to all elements after this position.
\r
2631 * Filter the set of elements to those that contain the specified text.
\r
2633 * @example $("p").contains("test")
\r
2634 * @before <p>This is just a test.</p><p>So is this</p>
\r
2635 * @result [ <p>This is just a test.</p> ]
\r
2639 * @param String str The string that will be contained within the text of an element.
\r
2640 * @cat DOM/Traversing
\r
2643 filter: [ "eq", "lt", "gt", "contains" ],
\r
2647 * Get the current value of the first matched element.
\r
2649 * @example $("input").val();
\r
2650 * @before <input type="text" value="some text"/>
\r
2651 * @result "some text"
\r
2653 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
\r
2654 * ok( !$("#text1").val() == "", "Check for value of input element" );
\r
2658 * @cat DOM/Attributes
\r
2662 * Set the value of every matched element.
\r
2664 * @example $("input").value("test");
\r
2665 * @before <input type="text" value="some text"/>
\r
2666 * @result <input type="text" value="test"/>
\r
2668 * @test document.getElementById('text1').value = "bla";
\r
2669 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
\r
2670 * $("#text1").val('test');
\r
2671 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
\r
2675 * @param String val Set the property to the specified value.
\r
2676 * @cat DOM/Attributes
\r
2681 * Get the html contents of the first matched element.
\r
2683 * @example $("div").html();
\r
2684 * @before <div><input/></div>
\r
2685 * @result <input/>
\r
2689 * @cat DOM/Attributes
\r
2693 * Set the html contents of every matched element.
\r
2695 * @example $("div").html("<b>new stuff</b>");
\r
2696 * @before <div><input/></div>
\r
2697 * @result <div><b>new stuff</b></div>
\r
2699 * @test var div = $("div");
\r
2700 * div.html("<b>test</b>");
\r
2701 * var pass = true;
\r
2702 * for ( var i = 0; i < div.size(); i++ ) {
\r
2703 * if ( div.get(i).childNodes.length == 0 ) pass = false;
\r
2705 * ok( pass, "Set HTML" );
\r
2709 * @param String val Set the html contents to the specified value.
\r
2710 * @cat DOM/Attributes
\r
2712 html: "innerHTML",
\r
2715 * Get the current id of the first matched element.
\r
2717 * @example $("input").id();
\r
2718 * @before <input type="text" id="test" value="some text"/>
\r
2721 * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" );
\r
2722 * ok( $("#foo").id() == "foo", "Check for id" );
\r
2723 * ok( !$("head").id(), "Check for id" );
\r
2727 * @cat DOM/Attributes
\r
2731 * Set the id of every matched element.
\r
2733 * @example $("input").id("newid");
\r
2734 * @before <input type="text" id="test" value="some text"/>
\r
2735 * @result <input type="text" id="newid" value="some text"/>
\r
2739 * @param String val Set the property to the specified value.
\r
2740 * @cat DOM/Attributes
\r
2745 * Get the current title of the first matched element.
\r
2747 * @example $("img").title();
\r
2748 * @before <img src="test.jpg" title="my image"/>
\r
2749 * @result "my image"
\r
2751 * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
\r
2752 * ok( !$("#yahoo").title(), "Check for title" );
\r
2756 * @cat DOM/Attributes
\r
2760 * Set the title of every matched element.
\r
2762 * @example $("img").title("new title");
\r
2763 * @before <img src="test.jpg" title="my image"/>
\r
2764 * @result <img src="test.jpg" title="new image"/>
\r
2768 * @param String val Set the property to the specified value.
\r
2769 * @cat DOM/Attributes
\r
2774 * Get the current name of the first matched element.
\r
2776 * @example $("input").name();
\r
2777 * @before <input type="text" name="username"/>
\r
2778 * @result "username"
\r
2780 * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
\r
2781 * ok( $("#hidden1").name() == "hidden", "Check for name" );
\r
2782 * ok( !$("#area1").name(), "Check for name" );
\r
2786 * @cat DOM/Attributes
\r
2790 * Set the name of every matched element.
\r
2792 * @example $("input").name("user");
\r
2793 * @before <input type="text" name="username"/>
\r
2794 * @result <input type="text" name="user"/>
\r
2798 * @param String val Set the property to the specified value.
\r
2799 * @cat DOM/Attributes
\r
2804 * Get the current href of the first matched element.
\r
2806 * @example $("a").href();
\r
2807 * @before <a href="test.html">my link</a>
\r
2808 * @result "test.html"
\r
2812 * @cat DOM/Attributes
\r
2816 * Set the href of every matched element.
\r
2818 * @example $("a").href("test2.html");
\r
2819 * @before <a href="test.html">my link</a>
\r
2820 * @result <a href="test2.html">my link</a>
\r
2824 * @param String val Set the property to the specified value.
\r
2825 * @cat DOM/Attributes
\r
2830 * Get the current src of the first matched element.
\r
2832 * @example $("img").src();
\r
2833 * @before <img src="test.jpg" title="my image"/>
\r
2834 * @result "test.jpg"
\r
2838 * @cat DOM/Attributes
\r
2842 * Set the src of every matched element.
\r
2844 * @example $("img").src("test2.jpg");
\r
2845 * @before <img src="test.jpg" title="my image"/>
\r
2846 * @result <img src="test2.jpg" title="my image"/>
\r
2850 * @param String val Set the property to the specified value.
\r
2851 * @cat DOM/Attributes
\r
2856 * Get the current rel of the first matched element.
\r
2858 * @example $("a").rel();
\r
2859 * @before <a href="test.html" rel="nofollow">my link</a>
\r
2860 * @result "nofollow"
\r
2864 * @cat DOM/Attributes
\r
2868 * Set the rel of every matched element.
\r
2870 * @example $("a").rel("nofollow");
\r
2871 * @before <a href="test.html">my link</a>
\r
2872 * @result <a href="test.html" rel="nofollow">my link</a>
\r
2876 * @param String val Set the property to the specified value.
\r
2877 * @cat DOM/Attributes
\r
2884 * Get a set of elements containing the unique parents of the matched
\r
2885 * set of elements.
\r
2887 * @example $("p").parent()
\r
2888 * @before <div><p>Hello</p><p>Hello</p></div>
\r
2889 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
\r
2893 * @cat DOM/Traversing
\r
2897 * Get a set of elements containing the unique parents of the matched
\r
2898 * set of elements, and filtered by an expression.
\r
2900 * @example $("p").parent(".selected")
\r
2901 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
\r
2902 * @result [ <div class="selected"><p>Hello Again</p></div> ]
\r
2906 * @param String expr An expression to filter the parents with
\r
2907 * @cat DOM/Traversing
\r
2909 parent: "a.parentNode",
\r
2912 * Get a set of elements containing the unique ancestors of the matched
\r
2913 * set of elements (except for the root element).
\r
2915 * @example $("span").ancestors()
\r
2916 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2917 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
\r
2921 * @cat DOM/Traversing
\r
2925 * Get a set of elements containing the unique ancestors of the matched
\r
2926 * set of elements, and filtered by an expression.
\r
2928 * @example $("span").ancestors("p")
\r
2929 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2930 * @result [ <p><span>Hello</span></p> ]
\r
2934 * @param String expr An expression to filter the ancestors with
\r
2935 * @cat DOM/Traversing
\r
2937 ancestors: jQuery.parents,
\r
2940 * Get a set of elements containing the unique ancestors of the matched
\r
2941 * set of elements (except for the root element).
\r
2943 * @example $("span").ancestors()
\r
2944 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2945 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
\r
2949 * @cat DOM/Traversing
\r
2953 * Get a set of elements containing the unique ancestors of the matched
\r
2954 * set of elements, and filtered by an expression.
\r
2956 * @example $("span").ancestors("p")
\r
2957 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2958 * @result [ <p><span>Hello</span></p> ]
\r
2962 * @param String expr An expression to filter the ancestors with
\r
2963 * @cat DOM/Traversing
\r
2965 parents: jQuery.parents,
\r
2968 * Get a set of elements containing the unique next siblings of each of the
\r
2969 * matched set of elements.
\r
2971 * It only returns the very next sibling, not all next siblings.
\r
2973 * @example $("p").next()
\r
2974 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
\r
2975 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
\r
2979 * @cat DOM/Traversing
\r
2983 * Get a set of elements containing the unique next siblings of each of the
\r
2984 * matched set of elements, and filtered by an expression.
\r
2986 * It only returns the very next sibling, not all next siblings.
\r
2988 * @example $("p").next(".selected")
\r
2989 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
\r
2990 * @result [ <p class="selected">Hello Again</p> ]
\r
2994 * @param String expr An expression to filter the next Elements with
\r
2995 * @cat DOM/Traversing
\r
2997 next: "jQuery.sibling(a).next",
\r
3000 * Get a set of elements containing the unique previous siblings of each of the
\r
3001 * matched set of elements.
\r
3003 * It only returns the immediately previous sibling, not all previous siblings.
\r
3005 * @example $("p").prev()
\r
3006 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
3007 * @result [ <div><span>Hello Again</span></div> ]
\r
3011 * @cat DOM/Traversing
\r
3015 * Get a set of elements containing the unique previous siblings of each of the
\r
3016 * matched set of elements, and filtered by an expression.
\r
3018 * It only returns the immediately previous sibling, not all previous siblings.
\r
3020 * @example $("p").previous(".selected")
\r
3021 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
\r
3022 * @result [ <div><span>Hello</span></div> ]
\r
3026 * @param String expr An expression to filter the previous Elements with
\r
3027 * @cat DOM/Traversing
\r
3029 prev: "jQuery.sibling(a).prev",
\r
3032 * Get a set of elements containing all of the unique siblings of each of the
\r
3033 * matched set of elements.
\r
3035 * @example $("div").siblings()
\r
3036 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
3037 * @result [ <p>Hello</p>, <p>And Again</p> ]
\r
3039 * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
\r
3043 * @cat DOM/Traversing
\r
3047 * Get a set of elements containing all of the unique siblings of each of the
\r
3048 * matched set of elements, and filtered by an expression.
\r
3050 * @example $("div").siblings(".selected")
\r
3051 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
\r
3052 * @result [ <p class="selected">Hello Again</p> ]
\r
3054 * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
\r
3055 * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
\r
3059 * @param String expr An expression to filter the sibling Elements with
\r
3060 * @cat DOM/Traversing
\r
3062 siblings: "jQuery.sibling(a, null, true)",
\r
3066 * Get a set of elements containing all of the unique children of each of the
\r
3067 * matched set of elements.
\r
3069 * @example $("div").children()
\r
3070 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
3071 * @result [ <span>Hello Again</span> ]
\r
3073 * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
\r
3077 * @cat DOM/Traversing
\r
3081 * Get a set of elements containing all of the unique children of each of the
\r
3082 * matched set of elements, and filtered by an expression.
\r
3084 * @example $("div").children(".selected")
\r
3085 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
\r
3086 * @result [ <p class="selected">Hello Again</p> ]
\r
3088 * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
\r
3092 * @param String expr An expression to filter the child Elements with
\r
3093 * @cat DOM/Traversing
\r
3095 children: "jQuery.sibling(a.firstChild)"
\r
3101 * Remove an attribute from each of the matched elements.
\r
3103 * @example $("input").removeAttr("disabled")
\r
3104 * @before <input disabled="disabled"/>
\r
3105 * @result <input/>
\r
3107 * @name removeAttr
\r
3109 * @param String name The name of the attribute to remove.
\r
3112 removeAttr: function( key ) {
\r
3113 this.removeAttribute( key );
\r
3117 * Displays each of the set of matched elements if they are hidden.
\r
3119 * @example $("p").show()
\r
3120 * @before <p style="display: none">Hello</p>
\r
3121 * @result [ <p style="display: block">Hello</p> ]
\r
3123 * @test var pass = true, div = $("div");
\r
3124 * div.show().each(function(){
\r
3125 * if ( this.style.display == "none" ) pass = false;
\r
3127 * ok( pass, "Show" );
\r
3134 this.style.display = this.oldblock ? this.oldblock : "";
\r
3135 if ( jQuery.css(this,"display") == "none" )
\r
3136 this.style.display = "block";
\r
3140 * Hides each of the set of matched elements if they are shown.
\r
3142 * @example $("p").hide()
\r
3143 * @before <p>Hello</p>
\r
3144 * @result [ <p style="display: none">Hello</p> ]
\r
3146 * var pass = true, div = $("div");
\r
3147 * div.hide().each(function(){
\r
3148 * if ( this.style.display != "none" ) pass = false;
\r
3150 * ok( pass, "Hide" );
\r
3157 this.oldblock = this.oldblock || jQuery.css(this,"display");
\r
3158 if ( this.oldblock == "none" )
\r
3159 this.oldblock = "block";
\r
3160 this.style.display = "none";
\r
3164 * Toggles each of the set of matched elements. If they are shown,
\r
3165 * toggle makes them hidden. If they are hidden, toggle
\r
3166 * makes them shown.
\r
3168 * @example $("p").toggle()
\r
3169 * @before <p>Hello</p><p style="display: none">Hello Again</p>
\r
3170 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
\r
3176 toggle: function(){
\r
3177 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
\r
3181 * Adds the specified class to each of the set of matched elements.
\r
3183 * @example $("p").addClass("selected")
\r
3184 * @before <p>Hello</p>
\r
3185 * @result [ <p class="selected">Hello</p> ]
\r
3187 * @test var div = $("div");
\r
3188 * div.addClass("test");
\r
3189 * var pass = true;
\r
3190 * for ( var i = 0; i < div.size(); i++ ) {
\r
3191 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
\r
3193 * ok( pass, "Add Class" );
\r
3197 * @param String class A CSS class to add to the elements
\r
3200 addClass: function(c){
\r
3201 jQuery.className.add(this,c);
\r
3205 * Removes the specified class from the set of matched elements.
\r
3207 * @example $("p").removeClass("selected")
\r
3208 * @before <p class="selected">Hello</p>
\r
3209 * @result [ <p>Hello</p> ]
\r
3211 * @test var div = $("div").addClass("test");
\r
3212 * div.removeClass("test");
\r
3213 * var pass = true;
\r
3214 * for ( var i = 0; i < div.size(); i++ ) {
\r
3215 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
\r
3217 * ok( pass, "Remove Class" );
\r
3221 * var div = $("div").addClass("test").addClass("foo").addClass("bar");
\r
3222 * div.removeClass("test").removeClass("bar").removeClass("foo");
\r
3223 * var pass = true;
\r
3224 * for ( var i = 0; i < div.size(); i++ ) {
\r
3225 * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
\r
3227 * ok( pass, "Remove multiple classes" );
\r
3229 * @name removeClass
\r
3231 * @param String class A CSS class to remove from the elements
\r
3234 removeClass: function(c){
\r
3235 jQuery.className.remove(this,c);
\r
3239 * Adds the specified class if it is present, removes it if it is
\r
3242 * @example $("p").toggleClass("selected")
\r
3243 * @before <p>Hello</p><p class="selected">Hello Again</p>
\r
3244 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
\r
3246 * @name toggleClass
\r
3248 * @param String class A CSS class with which to toggle the elements
\r
3251 toggleClass: function( c ){
\r
3252 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
\r
3256 * Removes all matched elements from the DOM. This does NOT remove them from the
\r
3257 * jQuery object, allowing you to use the matched elements further.
\r
3259 * @example $("p").remove();
\r
3260 * @before <p>Hello</p> how are <p>you?</p>
\r
3265 * @cat DOM/Manipulation
\r
3269 * Removes only elements (out of the list of matched elements) that match
\r
3270 * the specified jQuery expression. This does NOT remove them from the
\r
3271 * jQuery object, allowing you to use the matched elements further.
\r
3273 * @example $("p").remove(".hello");
\r
3274 * @before <p class="hello">Hello</p> how are <p>you?</p>
\r
3275 * @result how are <p>you?</p>
\r
3279 * @param String expr A jQuery expression to filter elements by.
\r
3280 * @cat DOM/Manipulation
\r
3282 remove: function(a){
\r
3283 if ( !a || jQuery.filter( a, [this] ).r )
\r
3284 this.parentNode.removeChild( this );
\r
3288 * Removes all child nodes from the set of matched elements.
\r
3290 * @example $("p").empty()
\r
3291 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
\r
3292 * @result [ <p></p> ]
\r
3296 * @cat DOM/Manipulation
\r
3298 empty: function(){
\r
3299 while ( this.firstChild )
\r
3300 this.removeChild( this.firstChild );
\r
3304 * Binds a handler to a particular event (like click) for each matched element.
\r
3305 * The event handler is passed an event object that you can use to prevent
\r
3306 * default behaviour. To stop both default action and event bubbling, your handler
\r
3307 * has to return false.
\r
3309 * @example $("p").bind( "click", function() {
\r
3310 * alert( $(this).text() );
\r
3312 * @before <p>Hello</p>
\r
3313 * @result alert("Hello")
\r
3315 * @example $("form").bind( "submit", function() { return false; } )
\r
3316 * @desc Cancel a default action and prevent it from bubbling by returning false
\r
3317 * from your function.
\r
3319 * @example $("form").bind( "submit", function(event) {
\r
3320 * event.preventDefault();
\r
3322 * @desc Cancel only the default action by using the preventDefault method.
\r
3325 * @example $("form").bind( "submit", function(event) {
\r
3326 * event.stopPropagation();
\r
3328 * @desc Stop only an event from bubbling by using the stopPropagation method.
\r
3332 * @param String type An event type
\r
3333 * @param Function fn A function to bind to the event on each of the set of matched elements
\r
3336 bind: function( type, fn ) {
\r
3337 if ( fn.constructor == String )
\r
3338 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
\r
3339 jQuery.event.add( this, type, fn );
\r
3343 * The opposite of bind, removes a bound event from each of the matched
\r
3344 * elements. You must pass the identical function that was used in the original
\r
3347 * @example $("p").unbind( "click", function() { alert("Hello"); } )
\r
3348 * @before <p onclick="alert('Hello');">Hello</p>
\r
3349 * @result [ <p>Hello</p> ]
\r
3353 * @param String type An event type
\r
3354 * @param Function fn A function to unbind from the event on each of the set of matched elements
\r
3359 * Removes all bound events of a particular type from each of the matched
\r
3362 * @example $("p").unbind( "click" )
\r
3363 * @before <p onclick="alert('Hello');">Hello</p>
\r
3364 * @result [ <p>Hello</p> ]
\r
3368 * @param String type An event type
\r
3373 * Removes all bound events from each of the matched elements.
\r
3375 * @example $("p").unbind()
\r
3376 * @before <p onclick="alert('Hello');">Hello</p>
\r
3377 * @result [ <p>Hello</p> ]
\r
3383 unbind: function( type, fn ) {
\r
3384 jQuery.event.remove( this, type, fn );
\r
3388 * Trigger a type of event on every matched element.
\r
3390 * @example $("p").trigger("click")
\r
3391 * @before <p click="alert('hello')">Hello</p>
\r
3392 * @result alert('hello')
\r
3396 * @param String type An event type to trigger.
\r
3399 trigger: function( type, data ) {
\r
3400 jQuery.event.trigger( type, data, this );
\r