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, and appends it to the element with the ID of body.
\r
101 * @param String expr An expression to search with, or a string of HTML to create on the fly.
\r
107 * This function accepts a string containing a CSS selector, or
\r
108 * basic XPath, which is then used to match a set of elements with the
\r
109 * context of the specified DOM element, or document
\r
111 * @example $("div", xml.responseXML)
\r
112 * @desc This finds all div elements within the specified XML document.
\r
115 * @param String expr An expression to search with.
\r
116 * @param Element context A DOM Element, or Document, representing the base context.
\r
122 * Wrap jQuery functionality around a specific DOM Element.
\r
123 * This function also accepts XML Documents and Window objects
\r
124 * as valid arguments (even though they are not DOM Elements).
\r
126 * @example $(document).find("div > p")
\r
127 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
\r
128 * @result [ <p>two</p> ]
\r
130 * @example $(document.body).background( "black" );
\r
131 * @desc Sets the background color of the page to black.
\r
134 * @param Element elem A DOM element to be encapsulated by a jQuery object.
\r
140 * Wrap jQuery functionality around a set of DOM Elements.
\r
142 * @example $( myForm.elements ).hide()
\r
143 * @desc Hides all the input elements within a form
\r
146 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
\r
152 * A shorthand for $(document).ready(), allowing you to bind a function
\r
153 * to be executed when the DOM document has finished loading. This function
\r
154 * behaves just like $(document).ready(), in that it should be used to wrap
\r
155 * all of the other $() operations on your page. While this function is,
\r
156 * technically, chainable - there really isn't much use for chaining against it.
\r
157 * You can have as many $(document).ready events on your page as you like.
\r
159 * @example $(function(){
\r
160 * // Document is ready
\r
162 * @desc Executes the function when the DOM is ready to be used.
\r
165 * @param Function fn The function to execute when the DOM is ready.
\r
171 * A means of creating a cloned copy of a jQuery object. This function
\r
172 * copies the set of matched elements from one jQuery object and creates
\r
173 * another, new, jQuery object containing the same elements.
\r
175 * @example var div = $("div");
\r
176 * $( div ).find("p");
\r
177 * @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
180 * @param jQuery obj The jQuery object to be cloned.
\r
185 // Map the jQuery namespace to the '$' one
\r
188 jQuery.fn = jQuery.prototype = {
\r
190 * The current SVN version of jQuery.
\r
201 * The number of elements currently matched.
\r
203 * @example $("img").length;
\r
204 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
207 * @test ok( $("div").length == 2, "Get Number of Elements Found" );
\r
216 * The number of elements currently matched.
\r
218 * @example $("img").size();
\r
219 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
222 * @test ok( $("div").size() == 2, "Get Number of Elements Found" );
\r
229 return this.length;
\r
233 * Access all matched elements. This serves as a backwards-compatible
\r
234 * way of accessing all matched elements (other than the jQuery object
\r
235 * itself, which is, in fact, an array of elements).
\r
237 * @example $("img").get();
\r
238 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
239 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
\r
241 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
\r
244 * @type Array<Element>
\r
249 * Access a single matched element. num is used to access the
\r
250 * Nth element matched.
\r
252 * @example $("img").get(1);
\r
253 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
\r
254 * @result [ <img src="test1.jpg"/> ]
\r
256 * @test ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
\r
260 * @param Number num Access the element in the Nth position.
\r
265 * Set the jQuery object to an array of elements.
\r
267 * @example $("img").get([ document.body ]);
\r
268 * @result $("img").get() == [ document.body ]
\r
273 * @param Elements elems An array of elements
\r
276 get: function( num ) {
\r
277 // Watch for when an array (of elements) is passed in
\r
278 if ( num && num.constructor == Array ) {
\r
280 // Use a tricky hack to make the jQuery object
\r
281 // look and feel like an array
\r
283 [].push.apply( this, num );
\r
287 return num == undefined ?
\r
289 // Return a 'clean' array
\r
290 jQuery.merge( this, [] ) :
\r
292 // Return just the object
\r
297 * Execute a function within the context of every matched element.
\r
298 * This means that every time the passed-in function is executed
\r
299 * (which is once for every element matched) the 'this' keyword
\r
300 * points to the specific element.
\r
302 * Additionally, the function, when executed, is passed a single
\r
303 * argument representing the position of the element in the matched
\r
306 * @example $("img").each(function(){
\r
307 * this.src = "test.jpg";
\r
309 * @before <img/> <img/>
\r
310 * @result <img src="test.jpg"/> <img src="test.jpg"/>
\r
312 * @example $("img").each(function(i){
\r
313 * alert( "Image #" + i + " is " + this );
\r
315 * @before <img/> <img/>
\r
316 * @result <img src="test.jpg"/> <img src="test.jpg"/>
\r
318 * @test var div = $("div");
\r
319 * div.each(function(){this.foo = 'zoo';});
\r
321 * for ( var i = 0; i < div.size(); i++ ) {
\r
322 * if ( div.get(i).foo != "zoo" ) pass = false;
\r
324 * ok( pass, "Execute a function, Relative" );
\r
328 * @param Function fn A function to execute
\r
331 each: function( fn, args ) {
\r
332 return jQuery.each( this, fn, args );
\r
336 * Searches every matched element for the object and returns
\r
337 * the index of the element, if found, starting with zero.
\r
338 * Returns -1 if the object wasn't found.
\r
340 * @example $("*").index(document.getElementById('foobar'))
\r
341 * @before <div id="foobar"></div><b></b><span id="foo"></span>
\r
344 * @example $("*").index(document.getElementById('foo'))
\r
345 * @before <div id="foobar"></div><b></b><span id="foo"></span>
\r
348 * @example $("*").index(document.getElementById('bar'))
\r
349 * @before <div id="foobar"></div><b></b><span id="foo"></span>
\r
352 * @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );
\r
353 * ok( $([window, document]).index(document) == 1, "Check for index of elements" );
\r
354 * var inputElements = $('#radio1,#radio2,#check1,#check2');
\r
355 * ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
\r
356 * ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
\r
357 * ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
\r
358 * ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
\r
359 * ok( inputElements.index(window) == -1, "Check for not found index" );
\r
360 * ok( inputElements.index(document) == -1, "Check for not found index" );
\r
364 * @param Object obj Object to search for
\r
367 index: function( obj ) {
\r
369 this.each(function(i){
\r
370 if ( this == obj ) pos = i;
\r
376 * Access a property on the first matched element.
\r
377 * This method makes it easy to retrieve a property value
\r
378 * from the first matched element.
\r
380 * @example $("img").attr("src");
\r
381 * @before <img src="test.jpg"/>
\r
384 * @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
\r
385 * ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
\r
386 * ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
\r
387 * ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
\r
388 * ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
\r
389 * ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
\r
390 * ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
\r
391 * ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
\r
392 * ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
\r
393 * ok( $('#name').attr('name') == "name", 'Check for name attribute' );
\r
394 * ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
\r
395 * ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
\r
399 * @param String name The name of the property to access.
\r
404 * Set a hash of key/value object properties to all matched elements.
\r
405 * This serves as the best way to set a large number of properties
\r
406 * on all matched elements.
\r
408 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
\r
410 * @result <img src="test.jpg" alt="Test Image"/>
\r
412 * @test var pass = true;
\r
413 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
\r
414 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
\r
416 * ok( pass, "Set Multiple Attributes" );
\r
420 * @param Hash prop A set of key/value pairs to set as object properties.
\r
425 * Set a single property to a value, on all matched elements.
\r
427 * @example $("img").attr("src","test.jpg");
\r
429 * @result <img src="test.jpg"/>
\r
431 * @test var div = $("div");
\r
432 * div.attr("foo", "bar");
\r
434 * for ( var i = 0; i < div.size(); i++ ) {
\r
435 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
\r
437 * ok( pass, "Set Attribute" );
\r
439 * $("#name").attr('name', 'something');
\r
440 * ok( $("#name").name() == 'something', 'Set name attribute' );
\r
441 * $("#check2").attr('checked', true);
\r
442 * ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
\r
443 * $("#check2").attr('checked', false);
\r
444 * ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
\r
448 * @param String key The name of the property to set.
\r
449 * @param Object value The value to set the property to.
\r
452 attr: function( key, value, type ) {
\r
453 // Check to see if we're setting style values
\r
454 return key.constructor != String || value != undefined ?
\r
455 this.each(function(){
\r
456 // See if we're setting a hash of styles
\r
457 if ( value == undefined )
\r
458 // Set all the styles
\r
459 for ( var prop in key )
\r
461 type ? this.style : this,
\r
465 // See if we're setting a single key/value style
\r
468 type ? this.style : this,
\r
473 // Look for the case where we're accessing a style value
\r
474 jQuery[ type || "attr" ]( this[0], key );
\r
478 * Access a style property on the first matched element.
\r
479 * This method makes it easy to retrieve a style property value
\r
480 * from the first matched element.
\r
482 * @example $("p").css("color");
\r
483 * @before <p style="color:red;">Test Paragraph.</p>
\r
485 * @desc Retrieves the color style of the first paragraph
\r
487 * @example $("p").css("fontWeight");
\r
488 * @before <p style="font-weight: bold;">Test Paragraph.</p>
\r
490 * @desc Retrieves the font-weight style of the first paragraph.
\r
491 * Note that for all style properties with a dash (like 'font-weight'), you have to
\r
492 * write it in camelCase. In other words: Every time you have a '-' in a
\r
493 * property, remove it and replace the next character with an uppercase
\r
494 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
\r
495 * borderStyle, borderBottomWidth etc.
\r
497 * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"');
\r
501 * @param String name The name of the property to access.
\r
506 * Set a hash of key/value style properties to all matched elements.
\r
507 * This serves as the best way to set a large number of style properties
\r
508 * on all matched elements.
\r
510 * @example $("p").css({ color: "red", background: "blue" });
\r
511 * @before <p>Test Paragraph.</p>
\r
512 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
\r
514 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
515 * $('#foo').css({display: 'none'});
\r
516 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
517 * $('#foo').css({display: 'block'});
\r
518 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
522 * @param Hash prop A set of key/value pairs to set as style properties.
\r
527 * Set a single style property to a value, on all matched elements.
\r
529 * @example $("p").css("color","red");
\r
530 * @before <p>Test Paragraph.</p>
\r
531 * @result <p style="color:red;">Test Paragraph.</p>
\r
532 * @desc Changes the color of all paragraphs to red
\r
535 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
536 * $('#foo').css('display', 'none');
\r
537 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
538 * $('#foo').css('display', 'block');
\r
539 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
543 * @param String key The name of the property to set.
\r
544 * @param Object value The value to set the property to.
\r
547 css: function( key, value ) {
\r
548 return this.attr( key, value, "curCSS" );
\r
552 * Retrieve the text contents of all matched elements. The result is
\r
553 * a string that contains the combined text contents of all matched
\r
554 * elements. This method works on both HTML and XML documents.
\r
556 * @example $("p").text();
\r
557 * @before <p>Test Paragraph.</p>
\r
558 * @result Test Paragraph.
\r
560 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
\r
561 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
\r
567 text: function(e) {
\r
570 for ( var j = 0; j < e.length; j++ ) {
\r
571 var r = e[j].childNodes;
\r
572 for ( var i = 0; i < r.length; i++ )
\r
573 if ( r[i].nodeType != 8 )
\r
574 t += r[i].nodeType != 1 ?
\r
575 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
\r
581 * Wrap all matched elements with a structure of other elements.
\r
582 * This wrapping process is most useful for injecting additional
\r
583 * stucture into a document, without ruining the original semantic
\r
584 * qualities of a document.
\r
586 * This works by going through the first element
\r
587 * provided (which is generated, on the fly, from the provided HTML)
\r
588 * and finds the deepest ancestor element within its
\r
589 * structure - it is that element that will en-wrap everything else.
\r
591 * This does not work with elements that contain text. Any necessary text
\r
592 * must be added after the wrapping is done.
\r
594 * @example $("p").wrap("<div class='wrap'></div>");
\r
595 * @before <p>Test Paragraph.</p>
\r
596 * @result <div class='wrap'><p>Test Paragraph.</p></div>
\r
598 * @test var defaultText = 'Try them out:'
\r
599 * var result = $('#first').wrap('<div class="red"><span></span></div>').text();
\r
600 * ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
\r
601 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
605 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
\r
606 * @cat DOM/Manipulation
\r
610 * Wrap all matched elements with a structure of other elements.
\r
611 * This wrapping process is most useful for injecting additional
\r
612 * stucture into a document, without ruining the original semantic
\r
613 * qualities of a document.
\r
615 * This works by going through the first element
\r
616 * provided and finding the deepest ancestor element within its
\r
617 * structure - it is that element that will en-wrap everything else.
\r
619 * This does not work with elements that contain text. Any necessary text
\r
620 * must be added after the wrapping is done.
\r
622 * @example $("p").wrap( document.getElementById('content') );
\r
623 * @before <p>Test Paragraph.</p><div id="content"></div>
\r
624 * @result <div id="content"><p>Test Paragraph.</p></div>
\r
626 * @test var defaultText = 'Try them out:'
\r
627 * var result = $('#first').wrap(document.getElementById('empty')).parent();
\r
628 * ok( result.is('ol'), 'Check for element wrapping' );
\r
629 * ok( result.text() == defaultText, 'Check for element wrapping' );
\r
633 * @param Element elem A DOM element that will be wrapped.
\r
634 * @cat DOM/Manipulation
\r
637 // The elements to wrap the target around
\r
638 var a = jQuery.clean(arguments);
\r
640 // Wrap each of the matched elements individually
\r
641 return this.each(function(){
\r
642 // Clone the structure that we're using to wrap
\r
643 var b = a[0].cloneNode(true);
\r
645 // Insert it before the element to be wrapped
\r
646 this.parentNode.insertBefore( b, this );
\r
648 // Find he deepest point in the wrap structure
\r
649 while ( b.firstChild )
\r
652 // Move the matched element to within the wrap structure
\r
653 b.appendChild( this );
\r
658 * Append any number of elements to the inside of every matched elements,
\r
659 * generated from the provided HTML.
\r
660 * This operation is similar to doing an appendChild to all the
\r
661 * specified elements, adding them into the document.
\r
663 * @example $("p").append("<b>Hello</b>");
\r
664 * @before <p>I would like to say: </p>
\r
665 * @result <p>I would like to say: <b>Hello</b></p>
\r
667 * @test var defaultText = 'Try them out:'
\r
668 * var result = $('#first').append('<b>buga</b>');
\r
669 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
\r
673 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
674 * @cat DOM/Manipulation
\r
678 * Append an element to the inside of all matched elements.
\r
679 * This operation is similar to doing an appendChild to all the
\r
680 * specified elements, adding them into the document.
\r
682 * @example $("p").append( $("#foo")[0] );
\r
683 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
684 * @result <p>I would like to say: <b id="foo">Hello</b></p>
\r
686 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
687 * $('#sap').append(document.getElementById('first'));
\r
688 * ok( expected == $('#sap').text(), "Check for appending of element" );
\r
692 * @param Element elem A DOM element that will be appended.
\r
693 * @cat DOM/Manipulation
\r
697 * Append any number of elements to the inside of all matched elements.
\r
698 * This operation is similar to doing an appendChild to all the
\r
699 * specified elements, adding them into the document.
\r
701 * @example $("p").append( $("b") );
\r
702 * @before <p>I would like to say: </p><b>Hello</b>
\r
703 * @result <p>I would like to say: <b>Hello</b></p>
\r
705 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
706 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
\r
707 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
711 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
712 * @cat DOM/Manipulation
\r
714 append: function() {
\r
715 return this.domManip(arguments, true, 1, function(a){
\r
716 this.appendChild( a );
\r
721 * Prepend any number of elements to the inside of every matched elements,
\r
722 * generated from the provided HTML.
\r
723 * This operation is the best way to insert dynamically created elements
\r
724 * inside, at the beginning, of all the matched element.
\r
726 * @example $("p").prepend("<b>Hello</b>");
\r
727 * @before <p>I would like to say: </p>
\r
728 * @result <p><b>Hello</b>I would like to say: </p>
\r
730 * @test var defaultText = 'Try them out:'
\r
731 * var result = $('#first').prepend('<b>buga</b>');
\r
732 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
736 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
737 * @cat DOM/Manipulation
\r
741 * Prepend an element to the inside of all matched elements.
\r
742 * This operation is the best way to insert an element inside, at the
\r
743 * beginning, of all the matched element.
\r
745 * @example $("p").prepend( $("#foo")[0] );
\r
746 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
747 * @result <p><b id="foo">Hello</b>I would like to say: </p>
\r
749 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
750 * $('#sap').prepend(document.getElementById('first'));
\r
751 * ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
755 * @param Element elem A DOM element that will be appended.
\r
756 * @cat DOM/Manipulation
\r
760 * Prepend any number of elements to the inside of all matched elements.
\r
761 * This operation is the best way to insert a set of elements inside, at the
\r
762 * beginning, of all the matched element.
\r
764 * @example $("p").prepend( $("b") );
\r
765 * @before <p>I would like to say: </p><b>Hello</b>
\r
766 * @result <p><b>Hello</b>I would like to say: </p>
\r
768 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
769 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
\r
770 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
774 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
775 * @cat DOM/Manipulation
\r
777 prepend: function() {
\r
778 return this.domManip(arguments, true, -1, function(a){
\r
779 this.insertBefore( a, this.firstChild );
\r
784 * Insert any number of dynamically generated elements before each of the
\r
785 * matched elements.
\r
787 * @example $("p").before("<b>Hello</b>");
\r
788 * @before <p>I would like to say: </p>
\r
789 * @result <b>Hello</b><p>I would like to say: </p>
\r
791 * @test var expected = 'This is a normal link: bugaYahoo';
\r
792 * $('#yahoo').before('<b>buga</b>');
\r
793 * ok( expected == $('#en').text(), 'Insert String before' );
\r
797 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
798 * @cat DOM/Manipulation
\r
802 * Insert an element before each of the matched elements.
\r
804 * @example $("p").before( $("#foo")[0] );
\r
805 * @before <p>I would like to say: </p><b id="foo">Hello</b>
\r
806 * @result <b id="foo">Hello</b><p>I would like to say: </p>
\r
808 * @test var expected = "This is a normal link: Try them out:Yahoo";
\r
809 * $('#yahoo').before(document.getElementById('first'));
\r
810 * ok( expected == $('#en').text(), "Insert element before" );
\r
814 * @param Element elem A DOM element that will be appended.
\r
815 * @cat DOM/Manipulation
\r
819 * Insert any number of elements before each of the matched elements.
\r
821 * @example $("p").before( $("b") );
\r
822 * @before <p>I would like to say: </p><b>Hello</b>
\r
823 * @result <b>Hello</b><p>I would like to say: </p>
\r
825 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
826 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
\r
827 * ok( expected == $('#en').text(), "Insert array of elements before" );
\r
831 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
832 * @cat DOM/Manipulation
\r
834 before: function() {
\r
835 return this.domManip(arguments, false, 1, function(a){
\r
836 this.parentNode.insertBefore( a, this );
\r
841 * Insert any number of dynamically generated elements after each of the
\r
842 * matched elements.
\r
844 * @example $("p").after("<b>Hello</b>");
\r
845 * @before <p>I would like to say: </p>
\r
846 * @result <p>I would like to say: </p><b>Hello</b>
\r
848 * @test var expected = 'This is a normal link: Yahoobuga';
\r
849 * $('#yahoo').after('<b>buga</b>');
\r
850 * ok( expected == $('#en').text(), 'Insert String after' );
\r
854 * @param String html A string of HTML, that will be created on the fly and appended to the target.
\r
855 * @cat DOM/Manipulation
\r
859 * Insert an element after each of the matched elements.
\r
861 * @example $("p").after( $("#foo")[0] );
\r
862 * @before <b id="foo">Hello</b><p>I would like to say: </p>
\r
863 * @result <p>I would like to say: </p><b id="foo">Hello</b>
\r
865 * @test var expected = "This is a normal link: YahooTry them out:";
\r
866 * $('#yahoo').after(document.getElementById('first'));
\r
867 * ok( expected == $('#en').text(), "Insert element after" );
\r
871 * @param Element elem A DOM element that will be appended.
\r
872 * @cat DOM/Manipulation
\r
876 * Insert any number of elements after each of the matched elements.
\r
878 * @example $("p").after( $("b") );
\r
879 * @before <b>Hello</b><p>I would like to say: </p>
\r
880 * @result <p>I would like to say: </p><b>Hello</b>
\r
882 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
\r
883 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
\r
884 * ok( expected == $('#en').text(), "Insert array of elements after" );
\r
888 * @param Array<Element> elems An array of elements, all of which will be appended.
\r
889 * @cat DOM/Manipulation
\r
891 after: function() {
\r
892 return this.domManip(arguments, false, -1, function(a){
\r
893 this.parentNode.insertBefore( a, this.nextSibling );
\r
898 * End the most recent 'destructive' operation, reverting the list of matched elements
\r
899 * back to its previous state. After an end operation, the list of matched elements will
\r
900 * revert to the last state of matched elements.
\r
902 * @example $("p").find("span").end();
\r
903 * @before <p><span>Hello</span>, how are you?</p>
\r
904 * @result $("p").find("span").end() == [ <p>...</p> ]
\r
906 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
\r
910 * @cat DOM/Traversing
\r
913 return this.get( this.stack.pop() );
\r
917 * Searches for all elements that match the specified expression.
\r
918 * This method is the optimal way of finding additional descendant
\r
919 * elements with which to process.
\r
921 * All searching is done using a jQuery expression. The expression can be
\r
922 * written using CSS 1-3 Selector syntax, or basic XPath.
\r
924 * @example $("p").find("span");
\r
925 * @before <p><span>Hello</span>, how are you?</p>
\r
926 * @result $("p").find("span") == [ <span>Hello</span> ]
\r
928 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
\r
932 * @param String expr An expression to search with.
\r
933 * @cat DOM/Traversing
\r
935 find: function(t) {
\r
936 return this.pushStack( jQuery.map( this, function(a){
\r
937 return jQuery.find(t,a);
\r
942 * Create cloned copies of all matched DOM Elements. This does
\r
943 * not create a cloned copy of this particular jQuery object,
\r
944 * instead it creates duplicate copies of all DOM Elements.
\r
945 * This is useful for moving copies of the elements to another
\r
946 * location in the DOM.
\r
948 * @example $("b").clone().prependTo("p");
\r
949 * @before <b>Hello</b><p>, how are you?</p>
\r
950 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
\r
952 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
\r
953 * var clone = $('#yahoo').clone();
\r
954 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
\r
955 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
\r
959 * @cat DOM/Manipulation
\r
961 clone: function(deep) {
\r
962 return this.pushStack( jQuery.map( this, function(a){
\r
963 return a.cloneNode( deep != undefined ? deep : true );
\r
968 * Removes all elements from the set of matched elements that do not
\r
969 * match the specified expression. This method is used to narrow down
\r
970 * the results of a search.
\r
972 * All searching is done using a jQuery expression. The expression
\r
973 * can be written using CSS 1-3 Selector syntax, or basic XPath.
\r
975 * @example $("p").filter(".selected")
\r
976 * @before <p class="selected">Hello</p><p>How are you?</p>
\r
977 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
\r
979 * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
\r
980 * @test $("input").filter(":checked",function(i){
\r
981 * ok( this == q("radio2", "check1")[i], "Filter elements, context" );
\r
983 * @test $("#main > p#ap > a").filter("#foobar",function(){},function(i){
\r
984 * ok( this == q("google","groups", "mark")[i], "Filter elements, else context" );
\r
989 * @param String expr An expression to search with.
\r
990 * @cat DOM/Traversing
\r
994 * Removes all elements from the set of matched elements that do not
\r
995 * match at least one of the expressions passed to the function. This
\r
996 * method is used when you want to filter the set of matched elements
\r
997 * through more than one expression.
\r
999 * Elements will be retained in the jQuery object if they match at
\r
1000 * least one of the expressions passed.
\r
1002 * @example $("p").filter([".selected", ":first"])
\r
1003 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
\r
1004 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
\r
1008 * @param Array<String> exprs A set of expressions to evaluate against
\r
1009 * @cat DOM/Traversing
\r
1011 filter: function(t) {
\r
1012 return this.pushStack(
\r
1013 t.constructor == Array &&
\r
1014 jQuery.map(this,function(a){
\r
1015 for ( var i = 0; i < t.length; i++ )
\r
1016 if ( jQuery.filter(t[i],[a]).r.length )
\r
1020 t.constructor == Boolean &&
\r
1021 ( t ? this.get() : [] ) ||
\r
1023 typeof t == "function" &&
\r
1024 jQuery.grep( this, t ) ||
\r
1026 jQuery.filter(t,this).r, arguments );
\r
1030 * Removes the specified Element from the set of matched elements. This
\r
1031 * method is used to remove a single Element from a jQuery object.
\r
1033 * @example $("p").not( document.getElementById("selected") )
\r
1034 * @before <p>Hello</p><p id="selected">Hello Again</p>
\r
1035 * @result [ <p>Hello</p> ]
\r
1039 * @param Element el An element to remove from the set
\r
1040 * @cat DOM/Traversing
\r
1044 * Removes elements matching the specified expression from the set
\r
1045 * of matched elements. This method is used to remove one or more
\r
1046 * elements from a jQuery object.
\r
1048 * @example $("p").not("#selected")
\r
1049 * @before <p>Hello</p><p id="selected">Hello Again</p>
\r
1050 * @result [ <p>Hello</p> ]
\r
1052 * @test ok($("#main > p#ap > a").not("#google").length == 2, ".not")
\r
1056 * @param String expr An expression with which to remove matching elements
\r
1057 * @cat DOM/Traversing
\r
1059 not: function(t) {
\r
1060 return this.pushStack( t.constructor == String ?
\r
1061 jQuery.filter(t,this,false).r :
\r
1062 jQuery.grep(this,function(a){ return a != t; }), arguments );
\r
1066 * Adds the elements matched by the expression to the jQuery object. This
\r
1067 * can be used to concatenate the result sets of two expressions.
\r
1069 * @example $("p").add("span")
\r
1070 * @before <p>Hello</p><p><span>Hello Again</span></p>
\r
1071 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
\r
1075 * @param String expr An expression whose matched elements are added
\r
1076 * @cat DOM/Traversing
\r
1080 * Adds each of the Elements in the array to the set of matched elements.
\r
1081 * This is used to add a set of Elements to a jQuery object.
\r
1083 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
\r
1084 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
\r
1085 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
\r
1089 * @param Array<Element> els An array of Elements to add
\r
1090 * @cat DOM/Traversing
\r
1094 * Adds a single Element to the set of matched elements. This is used to
\r
1095 * add a single Element to a jQuery object.
\r
1097 * @example $("p").add( document.getElementById("a") )
\r
1098 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
\r
1099 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
\r
1103 * @param Element el An Element to add
\r
1104 * @cat DOM/Traversing
\r
1106 add: function(t) {
\r
1107 return this.pushStack( jQuery.merge( this, t.constructor == String ?
\r
1108 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
\r
1112 * Checks the current selection against an expression and returns true,
\r
1113 * if the selection fits the given expression. Does return false, if the
\r
1114 * selection does not fit or the expression is not valid.
\r
1116 * @example $("input[@type='checkbox']").parent().is("form")
\r
1117 * @before <form><input type="checkbox" /></form>
\r
1119 * @desc Returns true, because the parent of the input is a form element
\r
1121 * @example $("input[@type='checkbox']").parent().is("form")
\r
1122 * @before <form><p><input type="checkbox" /></p></form>
\r
1124 * @desc Returns false, because the parent of the input is a p element
\r
1126 * @example $("form").is(null)
\r
1127 * @before <form></form>
\r
1129 * @desc An invalid expression always returns false.
\r
1131 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
\r
1132 * ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
\r
1133 * ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
\r
1134 * ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
\r
1135 * ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
\r
1136 * ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
\r
1137 * ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
\r
1138 * ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
\r
1139 * ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
\r
1140 * ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
\r
1141 * ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
\r
1142 * ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
\r
1143 * ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
\r
1144 * ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
\r
1145 * ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
\r
1146 * ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
\r
1147 * ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
\r
1148 * ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
\r
1149 * ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
\r
1150 * ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
\r
1151 * ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
\r
1152 * ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
\r
1156 * @param String expr The expression with which to filter
\r
1157 * @cat DOM/Traversing
\r
1159 is: function(expr) {
\r
1160 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
\r
1168 * @param Array args
\r
1169 * @param Boolean table
\r
1170 * @param Number int
\r
1171 * @param Function fn The function doing the DOM manipulation.
\r
1175 domManip: function(args, table, dir, fn){
\r
1176 var clone = this.size() > 1;
\r
1177 var a = jQuery.clean(args);
\r
1179 return this.each(function(){
\r
1182 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
\r
1183 var tbody = this.getElementsByTagName("tbody");
\r
1185 if ( !tbody.length ) {
\r
1186 obj = document.createElement("tbody");
\r
1187 this.appendChild( obj );
\r
1192 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
\r
1193 i != ( dir < 0 ? dir : a.length ); i += dir ) {
\r
1194 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
\r
1205 * @param Array args
\r
1209 pushStack: function(a,args) {
\r
1210 var fn = args && args[args.length-1];
\r
1211 var fn2 = args && args[args.length-2];
\r
1213 if ( fn && fn.constructor != Function ) fn = null;
\r
1214 if ( fn2 && fn2.constructor != Function ) fn2 = null;
\r
1217 if ( !this.stack ) this.stack = [];
\r
1218 this.stack.push( this.get() );
\r
1221 var old = this.get();
\r
1224 if ( fn2 && a.length || !fn2 )
\r
1225 this.each( fn2 || fn ).get( old );
\r
1227 this.get( old ).each( fn );
\r
1235 * Extends the jQuery object itself. Can be used to add both static
\r
1236 * functions and plugin methods.
\r
1238 * @example $.fn.extend({
\r
1239 * check: function() {
\r
1240 * this.each(function() { this.checked = true; });
\r
1242 * uncheck: function() {
\r
1243 * this.each(function() { this.checked = false; });
\r
1246 * $("input[@type=checkbox]").check();
\r
1247 * $("input[@type=radio]").uncheck();
\r
1248 * @desc Adds two plugin methods.
\r
1252 * @param Object obj
\r
1258 * Extend one object with another, returning the original,
\r
1259 * modified, object. This is a great utility for simple inheritance.
\r
1261 * @example var settings = { validate: false, limit: 5, name: "foo" };
\r
1262 * var options = { validate: true, name: "bar" };
\r
1263 * jQuery.extend(settings, options);
\r
1264 * @result settings == { validate: true, limit: 5, name: "bar" }
\r
1266 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
\r
1267 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
\r
1268 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
\r
1269 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
\r
1270 * jQuery.extend(settings, options);
\r
1271 * isSet( settings, merged, "Check if extended: settings must be extended" );
\r
1272 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
1275 * @param Object obj The object to extend
\r
1276 * @param Object prop The object that will be merged into the first.
\r
1280 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
\r
1281 if ( !prop ) { prop = obj; obj = this; }
\r
1282 for ( var i in prop ) obj[i] = prop[i];
\r
1294 jQuery.initDone = true;
\r
1296 jQuery.each( jQuery.macros.axis, function(i,n){
\r
1297 jQuery.fn[ i ] = function(a) {
\r
1298 var ret = jQuery.map(this,n);
\r
1299 if ( a && a.constructor == String )
\r
1300 ret = jQuery.filter(a,ret).r;
\r
1301 return this.pushStack( ret, arguments );
\r
1305 jQuery.each( jQuery.macros.to, function(i,n){
\r
1306 jQuery.fn[ i ] = function(){
\r
1307 var a = arguments;
\r
1308 return this.each(function(){
\r
1309 for ( var j = 0; j < a.length; j++ )
\r
1310 jQuery(a[j])[n]( this );
\r
1315 jQuery.each( jQuery.macros.each, function(i,n){
\r
1316 jQuery.fn[ i ] = function() {
\r
1317 return this.each( n, arguments );
\r
1321 jQuery.each( jQuery.macros.filter, function(i,n){
\r
1322 jQuery.fn[ n ] = function(num,fn) {
\r
1323 return this.filter( ":" + n + "(" + num + ")", fn );
\r
1327 jQuery.each( jQuery.macros.attr, function(i,n){
\r
1329 jQuery.fn[ i ] = function(h) {
\r
1330 return h == undefined ?
\r
1331 this.length ? this[0][n] : null :
\r
1332 this.attr( n, h );
\r
1336 jQuery.each( jQuery.macros.css, function(i,n){
\r
1337 jQuery.fn[ n ] = function(h) {
\r
1338 return h == undefined ?
\r
1339 ( this.length ? jQuery.css( this[0], n ) : null ) :
\r
1347 * A generic iterator function, which can be used to seemlessly
\r
1348 * iterate over both objects and arrays. This function is not the same
\r
1349 * as $().each() - which is used to iterate, exclusively, over a jQuery
\r
1350 * object. This function can be used to iterate over anything.
\r
1352 * @example $.each( [0,1,2], function(i){
\r
1353 * alert( "Item #" + i + ": " + this );
\r
1355 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
\r
1357 * @example $.each( { name: "John", lang: "JS" }, function(i){
\r
1358 * alert( "Name: " + i + ", Value: " + this );
\r
1360 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
\r
1363 * @param Object obj The object, or array, to iterate over.
\r
1364 * @param Function fn The function that will be executed on every object.
\r
1368 each: function( obj, fn, args ) {
\r
1369 if ( obj.length == undefined )
\r
1370 for ( var i in obj )
\r
1371 fn.apply( obj[i], args || [i, obj[i]] );
\r
1373 for ( var i = 0; i < obj.length; i++ )
\r
1374 fn.apply( obj[i], args || [i, obj[i]] );
\r
1379 add: function(o,c){
\r
1380 if (jQuery.className.has(o,c)) return;
\r
1381 o.className += ( o.className ? " " : "" ) + c;
\r
1383 remove: function(o,c){
\r
1385 o.className = !c ? "" :
\r
1386 o.className.replace(
\r
1387 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");*/
\r
1391 var classes = o.className.split(" ");
\r
1392 for(var i=0; i<classes.length; i++) {
\r
1393 if(classes[i] == c) {
\r
1394 classes.splice(i, 1);
\r
1398 o.className = classes.join(' ');
\r
1401 has: function(e,a) {
\r
1402 if ( e.className != undefined )
\r
1404 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
\r
1409 * Swap in/out style options.
\r
1412 swap: function(e,o,f) {
\r
1413 for ( var i in o ) {
\r
1414 e.style["old"+i] = e.style[i];
\r
1415 e.style[i] = o[i];
\r
1418 for ( var i in o )
\r
1419 e.style[i] = e.style["old"+i];
\r
1422 css: function(e,p) {
\r
1423 if ( p == "height" || p == "width" ) {
\r
1424 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
\r
1426 for ( var i in d ) {
\r
1427 old["padding" + d[i]] = 0;
\r
1428 old["border" + d[i] + "Width"] = 0;
\r
1431 jQuery.swap( e, old, function() {
\r
1432 if (jQuery.css(e,"display") != "none") {
\r
1433 oHeight = e.offsetHeight;
\r
1434 oWidth = e.offsetWidth;
\r
1436 e = jQuery(e.cloneNode(true)).css({
\r
1437 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
\r
1438 }).appendTo(e.parentNode)[0];
\r
1440 var parPos = jQuery.css(e.parentNode,"position");
\r
1441 if ( parPos == "" || parPos == "static" )
\r
1442 e.parentNode.style.position = "relative";
\r
1444 oHeight = e.clientHeight;
\r
1445 oWidth = e.clientWidth;
\r
1447 if ( parPos == "" || parPos == "static" )
\r
1448 e.parentNode.style.position = "static";
\r
1450 e.parentNode.removeChild(e);
\r
1454 return p == "height" ? oHeight : oWidth;
\r
1455 } else if ( p == "opacity" && jQuery.browser.msie )
\r
1456 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
\r
1458 return jQuery.curCSS( e, p );
\r
1461 curCSS: function(elem, prop, force) {
\r
1464 if (!force && elem.style[prop]) {
\r
1466 ret = elem.style[prop];
\r
1468 } else if (elem.currentStyle) {
\r
1470 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
\r
1471 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
\r
1473 } else if (document.defaultView && document.defaultView.getComputedStyle) {
\r
1475 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
\r
1476 var cur = document.defaultView.getComputedStyle(elem, null);
\r
1479 ret = cur.getPropertyValue(prop);
\r
1480 else if ( prop == 'display' )
\r
1483 jQuery.swap(elem, { display: 'block' }, function() {
\r
1484 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
\r
1492 clean: function(a) {
\r
1494 for ( var i = 0; i < a.length; i++ ) {
\r
1495 if ( a[i].constructor == String ) {
\r
1499 if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
\r
1501 a[i] = "<table>" + a[i] + "</table>";
\r
1502 } else if ( !a[i].indexOf("<tr") ) {
\r
1504 a[i] = "<table>" + a[i] + "</table>";
\r
1505 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
\r
1507 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
\r
1510 var div = document.createElement("div");
\r
1511 div.innerHTML = a[i];
\r
1514 div = div.firstChild;
\r
1515 if ( table != "thead" ) div = div.firstChild;
\r
1516 if ( table == "td" ) div = div.firstChild;
\r
1519 for ( var j = 0; j < div.childNodes.length; j++ )
\r
1520 r.push( div.childNodes[j] );
\r
1521 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
\r
1522 for ( var k = 0; k < a[i].length; k++ )
\r
1523 r.push( a[i][k] );
\r
1524 else if ( a[i] !== null )
\r
1525 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
\r
1531 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
\r
1532 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
\r
1534 // Position Checks
\r
1540 last: "i==r.length-1",
\r
1545 "nth-child": "jQuery.sibling(a,m[3]).cur",
\r
1546 "first-child": "jQuery.sibling(a,0).cur",
\r
1547 "last-child": "jQuery.sibling(a,0).last",
\r
1548 "only-child": "jQuery.sibling(a).length==1",
\r
1551 parent: "a.childNodes.length",
\r
1552 empty: "!a.childNodes.length",
\r
1555 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
\r
1558 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
\r
1559 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
\r
1561 // Form attributes
\r
1562 enabled: "!a.disabled",
\r
1563 disabled: "a.disabled",
\r
1564 checked: "a.checked",
\r
1565 selected: "a.selected",
\r
1568 text: "a.type=='text'",
\r
1569 radio: "a.type=='radio'",
\r
1570 checkbox: "a.type=='checkbox'",
\r
1571 file: "a.type=='file'",
\r
1572 password: "a.type=='password'",
\r
1573 submit: "a.type=='submit'",
\r
1574 image: "a.type=='image'",
\r
1575 reset: "a.type=='reset'",
\r
1576 button: "a.type=='button'",
\r
1577 input: "a.nodeName.toLowerCase().match(/input|select|textarea|button/)"
\r
1579 ".": "jQuery.className.has(a,m[2])",
\r
1583 "^=": "z && !z.indexOf(m[4])",
\r
1584 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
\r
1585 "*=": "z && z.indexOf(m[4])>=0",
\r
1588 "[": "jQuery.find(m[2],a).length"
\r
1592 "\\.\\.|/\\.\\.", "a.parentNode",
\r
1593 ">|/", "jQuery.sibling(a.firstChild)",
\r
1594 "\\+", "jQuery.sibling(a).next",
\r
1597 var s = jQuery.sibling(a);
\r
1599 for ( var i = s.n; i < s.length; i++ )
\r
1607 * @test t( "Element Selector", "div", ["main","foo"] );
\r
1608 * t( "Element Selector", "body", ["body"] );
\r
1609 * t( "Element Selector", "html", ["html"] );
\r
1610 * ok( $("*").size() >= 30, "Element Selector" );
\r
1611 * t( "Parent Element", "div div", ["foo"] );
\r
1613 * t( "ID Selector", "#body", ["body"] );
\r
1614 * t( "ID Selector w/ Element", "body#body", ["body"] );
\r
1615 * t( "ID Selector w/ Element", "ul#first", [] );
\r
1617 * t( "Class Selector", ".blog", ["mark","simon"] );
\r
1618 * t( "Class Selector", ".blog.link", ["simon"] );
\r
1619 * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
\r
1620 * t( "Parent Class Selector", "p .blog", ["mark","simon"] );
\r
1622 * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
\r
1623 * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
\r
1624 * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
\r
1625 * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
\r
1627 * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
1628 * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
1629 * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
1630 * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
1631 * t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
\r
1632 * t( "All Children", "code > *", ["anchor1","anchor2"] );
\r
1633 * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
\r
1634 * t( "Adjacent", "a + a", ["groups"] );
\r
1635 * t( "Adjacent", "a +a", ["groups"] );
\r
1636 * t( "Adjacent", "a+ a", ["groups"] );
\r
1637 * t( "Adjacent", "a+a", ["groups"] );
\r
1638 * t( "Adjacent", "p + p", ["ap","en","sap"] );
\r
1639 * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
\r
1640 * t( "First Child", "p:first-child", ["firstp","sndp"] );
\r
1641 * t( "Attribute Exists", "a[@title]", ["google"] );
\r
1642 * t( "Attribute Exists", "*[@title]", ["google"] );
\r
1643 * t( "Attribute Exists", "[@title]", ["google"] );
\r
1645 * t( "Non-existing part of attribute [@name*=bla]", "[@name*=bla]", [] );
\r
1646 * t( "Non-existing start of attribute [@name^=bla]", "[@name^=bla]", [] );
\r
1647 * t( "Non-existing end of attribute [@name$=bla]", "[@name$=bla]", [] );
\r
1649 * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
\r
1650 * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
\r
1651 * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
\r
1652 * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
\r
1653 * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
\r
1654 * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
\r
1656 * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
\r
1657 * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
\r
1658 * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
\r
1659 * t( "First Child", "p:first-child", ["firstp","sndp"] );
\r
1660 * t( "Last Child", "p:last-child", ["sap"] );
\r
1661 * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
\r
1662 * t( "Empty", "ul:empty", ["firstUL"] );
\r
1663 * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
\r
1664 * t( "Disabled UI Element", "input:disabled", ["text2"] );
\r
1665 * t( "Checked UI Element", "input:checked", ["radio2","check1"] );
\r
1666 * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
\r
1667 * t( "Text Contains", "a:contains('Google')", ["google","groups"] );
\r
1668 * t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
\r
1669 * t( "Element Preceded By", "p ~ div", ["foo"] );
\r
1670 * t( "Not", "a.blog:not(.link)", ["mark"] );
\r
1672 * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
\r
1673 * t( "All Div Elements", "//div", ["main","foo"] );
\r
1674 * t( "Absolute Path", "/html/body", ["body"] );
\r
1675 * t( "Absolute Path w/ *", "/* /body", ["body"] );
\r
1676 * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
\r
1677 * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
\r
1678 * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
\r
1679 * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
\r
1680 * t( "Attribute Exists", "//a[@title]", ["google"] );
\r
1681 * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
\r
1682 * t( "Parent Axis", "//p/..", ["main","foo"] );
\r
1683 * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
\r
1684 * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
\r
1685 * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
\r
1687 * t( "nth Element", "p:nth(1)", ["ap"] );
\r
1688 * t( "First Element", "p:first", ["firstp"] );
\r
1689 * t( "Last Element", "p:last", ["first"] );
\r
1690 * t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
\r
1691 * t( "Odd Elements", "p:odd", ["ap","en","first"] );
\r
1692 * t( "Position Equals", "p:eq(1)", ["ap"] );
\r
1693 * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
\r
1694 * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
\r
1695 * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
\r
1696 * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
\r
1697 * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
\r
1699 * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
\r
1701 * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
\r
1702 * t( "All Children of ID with no children", "#firstUL/*", [] );
\r
1704 * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
\r
1705 * t( "Form element :radio", ":radio", ["radio1", "radio2"] );
\r
1706 * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
\r
1707 * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
\r
1708 * t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
\r
1709 * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
\r
1710 * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
\r
1712 * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
\r
1713 * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
\r
1714 * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
\r
1717 * @type Array<Element>
\r
1721 find: function( t, context ) {
\r
1722 // Make sure that the context is a DOM Element
\r
1723 if ( context && context.nodeType == undefined )
\r
1726 // Set the correct context (if none is provided)
\r
1727 context = context || jQuery.context || document;
\r
1729 if ( t.constructor != String ) return [t];
\r
1731 if ( !t.indexOf("//") ) {
\r
1732 context = context.documentElement;
\r
1733 t = t.substr(2,t.length);
\r
1734 } else if ( !t.indexOf("/") ) {
\r
1735 context = context.documentElement;
\r
1736 t = t.substr(1,t.length);
\r
1737 // FIX Assume the root element is right :(
\r
1738 if ( t.indexOf("/") >= 1 )
\r
1739 t = t.substr(t.indexOf("/"),t.length);
\r
1742 var ret = [context];
\r
1746 while ( t.length > 0 && last != t ) {
\r
1750 t = jQuery.trim(t).replace( /^\/\//i, "" );
\r
1752 var foundToken = false;
\r
1754 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
\r
1755 if ( foundToken ) continue;
\r
1757 var re = new RegExp("^(" + jQuery.token[i] + ")");
\r
1758 var m = re.exec(t);
\r
1761 r = ret = jQuery.map( ret, jQuery.token[i+1] );
\r
1762 t = jQuery.trim( t.replace( re, "" ) );
\r
1763 foundToken = true;
\r
1767 if ( !foundToken ) {
\r
1768 if ( !t.indexOf(",") || !t.indexOf("|") ) {
\r
1769 if ( ret[0] == context ) ret.shift();
\r
1770 done = jQuery.merge( done, ret );
\r
1771 r = ret = [context];
\r
1772 t = " " + t.substr(1,t.length);
\r
1774 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
\r
1775 var m = re2.exec(t);
\r
1777 if ( m[1] == "#" ) {
\r
1778 // Ummm, should make this work in all XML docs
\r
1779 var oid = document.getElementById(m[2]);
\r
1780 r = ret = oid ? [oid] : [];
\r
1781 t = t.replace( re2, "" );
\r
1783 if ( !m[2] || m[1] == "." ) m[2] = "*";
\r
1785 for ( var i = 0; i < ret.length; i++ )
\r
1786 r = jQuery.merge( r,
\r
1788 jQuery.getAll(ret[i]) :
\r
1789 ret[i].getElementsByTagName(m[2])
\r
1797 var val = jQuery.filter(t,r);
\r
1799 t = jQuery.trim(val.t);
\r
1803 if ( ret && ret[0] == context ) ret.shift();
\r
1804 done = jQuery.merge( done, ret );
\r
1809 getAll: function(o,r) {
\r
1811 var s = o.childNodes;
\r
1812 for ( var i = 0; i < s.length; i++ )
\r
1813 if ( s[i].nodeType == 1 ) {
\r
1815 jQuery.getAll( s[i], r );
\r
1820 attr: function(elem, name, value){
\r
1823 "class": "className",
\r
1824 "float": "cssFloat",
\r
1825 innerHTML: "innerHTML",
\r
1826 className: "className",
\r
1828 disabled: "disabled",
\r
1829 checked: "checked"
\r
1832 if ( fix[name] ) {
\r
1833 if ( value != undefined ) elem[fix[name]] = value;
\r
1834 return elem[fix[name]];
\r
1835 } else if( value == undefined && $.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
\r
1836 return elem.getAttributeNode(name).nodeValue;
\r
1837 } else if ( elem.getAttribute != undefined ) {
\r
1838 if ( value != undefined ) elem.setAttribute( name, value );
\r
1839 return elem.getAttribute( name, 2 );
\r
1841 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
\r
1842 if ( value != undefined ) elem[name] = value;
\r
1843 return elem[name];
\r
1847 // The regular expressions that power the parsing engine
\r
1849 // Match: [@value='test'], [@foo]
\r
1850 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
\r
1852 // Match: [div], [div p]
\r
1853 "(\\[)\s*(.*?)\s*\\]",
\r
1855 // Match: :contains('foo')
\r
1856 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
\r
1858 // Match: :even, :last-chlid
\r
1862 filter: function(t,r,not) {
\r
1863 // Figure out if we're doing regular, or inverse, filtering
\r
1864 var g = not !== false ? jQuery.grep :
\r
1865 function(a,f) {return jQuery.grep(a,f,true);};
\r
1867 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
\r
1869 var p = jQuery.parse;
\r
1871 for ( var i = 0; i < p.length; i++ ) {
\r
1873 // Look for, and replace, string-like sequences
\r
1874 // and finally build a regexp out of it
\r
1875 var re = new RegExp(
\r
1876 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
\r
1878 var m = re.exec( t );
\r
1881 // Re-organize the first match
\r
1883 m = ["",m[1], m[3], m[2], m[5]];
\r
1885 // Remove what we just matched
\r
1886 t = t.replace( re, "" );
\r
1892 // :not() is a special case that can be optimized by
\r
1893 // keeping it out of the expression list
\r
1894 if ( m[1] == ":" && m[2] == "not" )
\r
1895 r = jQuery.filter(m[3],r,false).r;
\r
1897 // Otherwise, find the expression to execute
\r
1899 var f = jQuery.expr[m[1]];
\r
1900 if ( f.constructor != String )
\r
1901 f = jQuery.expr[m[1]][m[2]];
\r
1903 // Build a custom macro to enclose it
\r
1904 eval("f = function(a,i){" +
\r
1905 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
\r
1906 "return " + f + "}");
\r
1908 // Execute it against the current filter
\r
1913 // Return an array of filtered elements (r)
\r
1914 // and the modified expression string (t)
\r
1915 return { r: r, t: t };
\r
1919 * Remove the whitespace from the beginning and end of a string.
\r
1921 * @example $.trim(" hello, how are you? ");
\r
1922 * @result "hello, how are you?"
\r
1926 * @param String str The string to trim.
\r
1929 trim: function(t){
\r
1930 return t.replace(/^\s+|\s+$/g, "");
\r
1934 * All ancestors of a given element.
\r
1938 * @type Array<Element>
\r
1939 * @param Element elem The element to find the ancestors of.
\r
1940 * @cat DOM/Traversing
\r
1942 parents: function( elem ){
\r
1944 var cur = elem.parentNode;
\r
1945 while ( cur && cur != document ) {
\r
1946 matched.push( cur );
\r
1947 cur = cur.parentNode;
\r
1953 * All elements on a specified axis.
\r
1958 * @param Element elem The element to find all the siblings of (including itself).
\r
1959 * @cat DOM/Traversing
\r
1961 sibling: function(elem, pos, not) {
\r
1965 var siblings = elem.parentNode.childNodes;
\r
1966 for ( var i = 0; i < siblings.length; i++ ) {
\r
1967 if ( not === true && siblings[i] == elem ) continue;
\r
1969 if ( siblings[i].nodeType == 1 )
\r
1970 elems.push( siblings[i] );
\r
1971 if ( siblings[i] == elem )
\r
1972 elems.n = elems.length - 1;
\r
1976 return jQuery.extend( elems, {
\r
1977 last: elems.n == elems.length - 1,
\r
1978 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
\r
1979 prev: elems[elems.n - 1],
\r
1980 next: elems[elems.n + 1]
\r
1985 * Merge two arrays together, removing all duplicates. The final order
\r
1986 * or the new array is: All the results from the first array, followed
\r
1987 * by the unique results from the second array.
\r
1989 * @example $.merge( [0,1,2], [2,3,4] )
\r
1990 * @result [0,1,2,3,4]
\r
1992 * @example $.merge( [3,2,1], [4,3,2] )
\r
1993 * @result [3,2,1,4]
\r
1997 * @param Array first The first array to merge.
\r
1998 * @param Array second The second array to merge.
\r
2001 merge: function(first, second) {
\r
2004 // Move b over to the new array (this helps to avoid
\r
2005 // StaticNodeList instances)
\r
2006 for ( var k = 0; k < first.length; k++ )
\r
2007 result[k] = first[k];
\r
2009 // Now check for duplicates between a and b and only
\r
2010 // add the unique items
\r
2011 for ( var i = 0; i < second.length; i++ ) {
\r
2012 var noCollision = true;
\r
2014 // The collision-checking process
\r
2015 for ( var j = 0; j < first.length; j++ )
\r
2016 if ( second[i] == first[j] )
\r
2017 noCollision = false;
\r
2019 // If the item is unique, add it
\r
2020 if ( noCollision )
\r
2021 result.push( second[i] );
\r
2028 * Filter items out of an array, by using a filter function.
\r
2029 * The specified function will be passed two arguments: The
\r
2030 * current array item and the index of the item in the array. The
\r
2031 * function should return 'true' if you wish to keep the item in
\r
2032 * the array, false if it should be removed.
\r
2034 * @example $.grep( [0,1,2], function(i){
\r
2041 * @param Array array The Array to find items in.
\r
2042 * @param Function fn The function to process each item against.
\r
2043 * @param Boolean inv Invert the selection - select the opposite of the function.
\r
2046 grep: function(elems, fn, inv) {
\r
2047 // If a string is passed in for the function, make a function
\r
2048 // for it (a handy shortcut)
\r
2049 if ( fn.constructor == String )
\r
2050 fn = new Function("a","i","return " + fn);
\r
2054 // Go through the array, only saving the items
\r
2055 // that pass the validator function
\r
2056 for ( var i = 0; i < elems.length; i++ )
\r
2057 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
\r
2058 result.push( elems[i] );
\r
2064 * Translate all items in an array to another array of items.
\r
2065 * The translation function that is provided to this method is
\r
2066 * called for each item in the array and is passed one argument:
\r
2067 * The item to be translated. The function can then return:
\r
2068 * The translated value, 'null' (to remove the item), or
\r
2069 * an array of values - which will be flattened into the full array.
\r
2071 * @example $.map( [0,1,2], function(i){
\r
2074 * @result [4, 5, 6]
\r
2076 * @example $.map( [0,1,2], function(i){
\r
2077 * return i > 0 ? i + 1 : null;
\r
2081 * @example $.map( [0,1,2], function(i){
\r
2082 * return [ i, i + 1 ];
\r
2084 * @result [0, 1, 1, 2, 2, 3]
\r
2088 * @param Array array The Array to translate.
\r
2089 * @param Function fn The function to process each item against.
\r
2092 map: function(elems, fn) {
\r
2093 // If a string is passed in for the function, make a function
\r
2094 // for it (a handy shortcut)
\r
2095 if ( fn.constructor == String )
\r
2096 fn = new Function("a","return " + fn);
\r
2100 // Go through the array, translating each of the items to their
\r
2101 // new value (or values).
\r
2102 for ( var i = 0; i < elems.length; i++ ) {
\r
2103 var val = fn(elems[i],i);
\r
2105 if ( val !== null && val != undefined ) {
\r
2106 if ( val.constructor != Array ) val = [val];
\r
2107 result = jQuery.merge( result, val );
\r
2115 * A number of helper functions used for managing events.
\r
2116 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
\r
2120 // Bind an event to an element
\r
2121 // Original by Dean Edwards
\r
2122 add: function(element, type, handler) {
\r
2123 // For whatever reason, IE has trouble passing the window object
\r
2124 // around, causing it to be cloned in the process
\r
2125 if ( jQuery.browser.msie && element.setInterval != undefined )
\r
2128 // Make sure that the function being executed has a unique ID
\r
2129 if ( !handler.guid )
\r
2130 handler.guid = this.guid++;
\r
2132 // Init the element's event structure
\r
2133 if (!element.events)
\r
2134 element.events = {};
\r
2136 // Get the current list of functions bound to this event
\r
2137 var handlers = element.events[type];
\r
2139 // If it hasn't been initialized yet
\r
2141 // Init the event handler queue
\r
2142 handlers = element.events[type] = {};
\r
2144 // Remember an existing handler, if it's already there
\r
2145 if (element["on" + type])
\r
2146 handlers[0] = element["on" + type];
\r
2149 // Add the function to the element's handler list
\r
2150 handlers[handler.guid] = handler;
\r
2152 // And bind the global event handler to the element
\r
2153 element["on" + type] = this.handle;
\r
2155 // Remember the function in a global list (for triggering)
\r
2156 if (!this.global[type])
\r
2157 this.global[type] = [];
\r
2158 this.global[type].push( element );
\r
2164 // Detach an event or set of events from an element
\r
2165 remove: function(element, type, handler) {
\r
2166 if (element.events)
\r
2167 if (type && element.events[type])
\r
2169 delete element.events[type][handler.guid];
\r
2171 for ( var i in element.events[type] )
\r
2172 delete element.events[type][i];
\r
2174 for ( var j in element.events )
\r
2175 this.remove( element, j );
\r
2178 trigger: function(type,data,element) {
\r
2179 // Touch up the incoming data
\r
2180 data = data || [];
\r
2182 // Handle a global trigger
\r
2184 var g = this.global[type];
\r
2186 for ( var i = 0; i < g.length; i++ )
\r
2187 this.trigger( type, data, g[i] );
\r
2189 // Handle triggering a single element
\r
2190 } else if ( element["on" + type] ) {
\r
2191 // Pass along a fake event
\r
2192 data.unshift( this.fix({ type: type, target: element }) );
\r
2194 // Trigger the event
\r
2195 element["on" + type].apply( element, data );
\r
2199 handle: function(event) {
\r
2200 if ( typeof jQuery == "undefined" ) return;
\r
2202 event = event || jQuery.event.fix( window.event );
\r
2204 // If no correct event was found, fail
\r
2205 if ( !event ) return;
\r
2207 var returnValue = true;
\r
2209 var c = this.events[event.type];
\r
2211 var args = [].slice.call( arguments, 1 );
\r
2212 args.unshift( event );
\r
2214 for ( var j in c ) {
\r
2215 if ( c[j].apply( this, args ) === false ) {
\r
2216 event.preventDefault();
\r
2217 event.stopPropagation();
\r
2218 returnValue = false;
\r
2222 return returnValue;
\r
2225 fix: function(event) {
\r
2227 event.preventDefault = function() {
\r
2228 this.returnValue = false;
\r
2231 event.stopPropagation = function() {
\r
2232 this.cancelBubble = true;
\r
2243 * Contains flags for the useragent, read from navigator.userAgent.
\r
2244 * Available flags are: safari, opera, msie, mozilla
\r
2245 * This property is available before the DOM is ready, therefore you can
\r
2246 * use it to add ready events only for certain browsers.
\r
2248 * See <a href="http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/">
\r
2249 * jQBrowser plugin</a> for advanced browser detection:
\r
2251 * @example $.browser.msie
\r
2252 * @desc returns true if the current useragent is some version of microsoft's internet explorer
\r
2254 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
\r
2255 * @desc Alerts "this is safari!" only for safari browsers
\r
2262 var b = navigator.userAgent.toLowerCase();
\r
2264 // Figure out what browser is being used
\r
2265 jQuery.browser = {
\r
2266 safari: /webkit/.test(b),
\r
2267 opera: /opera/.test(b),
\r
2268 msie: /msie/.test(b) && !/opera/.test(b),
\r
2269 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
\r
2272 // Check to see if the W3C box model is being used
\r
2273 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
\r
2279 * Append all of the matched elements to another, specified, set of elements.
\r
2280 * This operation is, essentially, the reverse of doing a regular
\r
2281 * $(A).append(B), in that instead of appending B to A, you're appending
\r
2284 * @example $("p").appendTo("#foo");
\r
2285 * @before <p>I would like to say: </p><div id="foo"></div>
\r
2286 * @result <div id="foo"><p>I would like to say: </p></div>
\r
2290 * @param String expr A jQuery expression of elements to match.
\r
2291 * @cat DOM/Manipulation
\r
2293 appendTo: "append",
\r
2296 * Prepend all of the matched elements to another, specified, set of elements.
\r
2297 * This operation is, essentially, the reverse of doing a regular
\r
2298 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
\r
2301 * @example $("p").prependTo("#foo");
\r
2302 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
\r
2303 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
\r
2307 * @param String expr A jQuery expression of elements to match.
\r
2308 * @cat DOM/Manipulation
\r
2310 prependTo: "prepend",
\r
2313 * Insert all of the matched elements before another, specified, set of elements.
\r
2314 * This operation is, essentially, the reverse of doing a regular
\r
2315 * $(A).before(B), in that instead of inserting B before A, you're inserting
\r
2318 * @example $("p").insertBefore("#foo");
\r
2319 * @before <div id="foo">Hello</div><p>I would like to say: </p>
\r
2320 * @result <p>I would like to say: </p><div id="foo">Hello</div>
\r
2322 * @name insertBefore
\r
2324 * @param String expr A jQuery expression of elements to match.
\r
2325 * @cat DOM/Manipulation
\r
2327 insertBefore: "before",
\r
2330 * Insert all of the matched elements after another, specified, set of elements.
\r
2331 * This operation is, essentially, the reverse of doing a regular
\r
2332 * $(A).after(B), in that instead of inserting B after A, you're inserting
\r
2335 * @example $("p").insertAfter("#foo");
\r
2336 * @before <p>I would like to say: </p><div id="foo">Hello</div>
\r
2337 * @result <div id="foo">Hello</div><p>I would like to say: </p>
\r
2339 * @name insertAfter
\r
2341 * @param String expr A jQuery expression of elements to match.
\r
2342 * @cat DOM/Manipulation
\r
2344 insertAfter: "after"
\r
2348 * Get the current CSS width of the first matched element.
\r
2350 * @example $("p").width();
\r
2351 * @before <p>This is just a test.</p>
\r
2360 * Set the CSS width of every matched element. Be sure to include
\r
2361 * the "px" (or other unit of measurement) after the number that you
\r
2362 * specify, otherwise you might get strange results.
\r
2364 * @example $("p").width("20px");
\r
2365 * @before <p>This is just a test.</p>
\r
2366 * @result <p style="width:20px;">This is just a test.</p>
\r
2370 * @param String val Set the CSS property to the specified value.
\r
2375 * Get the current CSS height of the first matched element.
\r
2377 * @example $("p").height();
\r
2378 * @before <p>This is just a test.</p>
\r
2387 * Set the CSS height of every matched element. Be sure to include
\r
2388 * the "px" (or other unit of measurement) after the number that you
\r
2389 * specify, otherwise you might get strange results.
\r
2391 * @example $("p").height("20px");
\r
2392 * @before <p>This is just a test.</p>
\r
2393 * @result <p style="height:20px;">This is just a test.</p>
\r
2397 * @param String val Set the CSS property to the specified value.
\r
2402 * Get the current CSS top of the first matched element.
\r
2404 * @example $("p").top();
\r
2405 * @before <p>This is just a test.</p>
\r
2414 * Set the CSS top of every matched element. Be sure to include
\r
2415 * the "px" (or other unit of measurement) after the number that you
\r
2416 * specify, otherwise you might get strange results.
\r
2418 * @example $("p").top("20px");
\r
2419 * @before <p>This is just a test.</p>
\r
2420 * @result <p style="top:20px;">This is just a test.</p>
\r
2424 * @param String val Set the CSS property to the specified value.
\r
2429 * Get the current CSS left of the first matched element.
\r
2431 * @example $("p").left();
\r
2432 * @before <p>This is just a test.</p>
\r
2441 * Set the CSS left of every matched element. Be sure to include
\r
2442 * the "px" (or other unit of measurement) after the number that you
\r
2443 * specify, otherwise you might get strange results.
\r
2445 * @example $("p").left("20px");
\r
2446 * @before <p>This is just a test.</p>
\r
2447 * @result <p style="left:20px;">This is just a test.</p>
\r
2451 * @param String val Set the CSS property to the specified value.
\r
2456 * Get the current CSS position of the first matched element.
\r
2458 * @example $("p").position();
\r
2459 * @before <p>This is just a test.</p>
\r
2460 * @result "static"
\r
2468 * Set the CSS position of every matched element.
\r
2470 * @example $("p").position("relative");
\r
2471 * @before <p>This is just a test.</p>
\r
2472 * @result <p style="position:relative;">This is just a test.</p>
\r
2476 * @param String val Set the CSS property to the specified value.
\r
2481 * Get the current CSS float of the first matched element.
\r
2483 * @example $("p").float();
\r
2484 * @before <p>This is just a test.</p>
\r
2493 * Set the CSS float of every matched element.
\r
2495 * @example $("p").float("left");
\r
2496 * @before <p>This is just a test.</p>
\r
2497 * @result <p style="float:left;">This is just a test.</p>
\r
2501 * @param String val Set the CSS property to the specified value.
\r
2506 * Get the current CSS overflow of the first matched element.
\r
2508 * @example $("p").overflow();
\r
2509 * @before <p>This is just a test.</p>
\r
2518 * Set the CSS overflow of every matched element.
\r
2520 * @example $("p").overflow("auto");
\r
2521 * @before <p>This is just a test.</p>
\r
2522 * @result <p style="overflow:auto;">This is just a test.</p>
\r
2526 * @param String val Set the CSS property to the specified value.
\r
2531 * Get the current CSS color of the first matched element.
\r
2533 * @example $("p").color();
\r
2534 * @before <p>This is just a test.</p>
\r
2543 * Set the CSS color of every matched element.
\r
2545 * @example $("p").color("blue");
\r
2546 * @before <p>This is just a test.</p>
\r
2547 * @result <p style="color:blue;">This is just a test.</p>
\r
2551 * @param String val Set the CSS property to the specified value.
\r
2556 * Get the current CSS background of the first matched element.
\r
2558 * @example $("p").background();
\r
2559 * @before <p style="background:blue;">This is just a test.</p>
\r
2562 * @name background
\r
2568 * Set the CSS background of every matched element.
\r
2570 * @example $("p").background("blue");
\r
2571 * @before <p>This is just a test.</p>
\r
2572 * @result <p style="background:blue;">This is just a test.</p>
\r
2574 * @name background
\r
2576 * @param String val Set the CSS property to the specified value.
\r
2580 css: "width,height,top,left,position,float,overflow,color,background".split(","),
\r
2583 * Reduce the set of matched elements to a single element.
\r
2584 * The position of the element in the set of matched elements
\r
2585 * starts at 0 and goes to length - 1.
\r
2587 * @example $("p").eq(1)
\r
2588 * @before <p>This is just a test.</p><p>So is this</p>
\r
2589 * @result [ <p>So is this</p> ]
\r
2593 * @param Number pos The index of the element that you wish to limit to.
\r
2598 * Reduce the set of matched elements to all elements before a given position.
\r
2599 * The position of the element in the set of matched elements
\r
2600 * starts at 0 and goes to length - 1.
\r
2602 * @example $("p").lt(1)
\r
2603 * @before <p>This is just a test.</p><p>So is this</p>
\r
2604 * @result [ <p>This is just a test.</p> ]
\r
2608 * @param Number pos Reduce the set to all elements below this position.
\r
2613 * Reduce the set of matched elements to all elements after a given position.
\r
2614 * The position of the element in the set of matched elements
\r
2615 * starts at 0 and goes to length - 1.
\r
2617 * @example $("p").gt(0)
\r
2618 * @before <p>This is just a test.</p><p>So is this</p>
\r
2619 * @result [ <p>So is this</p> ]
\r
2623 * @param Number pos Reduce the set to all elements after this position.
\r
2628 * Filter the set of elements to those that contain the specified text.
\r
2630 * @example $("p").contains("test")
\r
2631 * @before <p>This is just a test.</p><p>So is this</p>
\r
2632 * @result [ <p>This is just a test.</p> ]
\r
2636 * @param String str The string that will be contained within the text of an element.
\r
2637 * @cat DOM/Traversing
\r
2640 filter: [ "eq", "lt", "gt", "contains" ],
\r
2644 * Get the current value of the first matched element.
\r
2646 * @example $("input").val();
\r
2647 * @before <input type="text" value="some text"/>
\r
2648 * @result "some text"
\r
2650 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
\r
2651 * ok( !$("#text1").val() == "", "Check for value of input element" );
\r
2655 * @cat DOM/Attributes
\r
2659 * Set the value of every matched element.
\r
2661 * @example $("input").value("test");
\r
2662 * @before <input type="text" value="some text"/>
\r
2663 * @result <input type="text" value="test"/>
\r
2665 * @test document.getElementById('text1').value = "bla";
\r
2666 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
\r
2667 * $("#text1").val('test');
\r
2668 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
\r
2672 * @param String val Set the property to the specified value.
\r
2673 * @cat DOM/Attributes
\r
2678 * Get the html contents of the first matched element.
\r
2680 * @example $("div").html();
\r
2681 * @before <div><input/></div>
\r
2682 * @result <input/>
\r
2686 * @cat DOM/Attributes
\r
2690 * Set the html contents of every matched element.
\r
2692 * @example $("div").html("<b>new stuff</b>");
\r
2693 * @before <div><input/></div>
\r
2694 * @result <div><b>new stuff</b></div>
\r
2696 * @test var div = $("div");
\r
2697 * div.html("<b>test</b>");
\r
2698 * var pass = true;
\r
2699 * for ( var i = 0; i < div.size(); i++ ) {
\r
2700 * if ( div.get(i).childNodes.length == 0 ) pass = false;
\r
2702 * ok( pass, "Set HTML" );
\r
2706 * @param String val Set the html contents to the specified value.
\r
2707 * @cat DOM/Attributes
\r
2709 html: "innerHTML",
\r
2712 * Get the current id of the first matched element.
\r
2714 * @example $("input").id();
\r
2715 * @before <input type="text" id="test" value="some text"/>
\r
2718 * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" );
\r
2719 * ok( $("#foo").id() == "foo", "Check for id" );
\r
2720 * ok( !$("head").id(), "Check for id" );
\r
2724 * @cat DOM/Attributes
\r
2728 * Set the id of every matched element.
\r
2730 * @example $("input").id("newid");
\r
2731 * @before <input type="text" id="test" value="some text"/>
\r
2732 * @result <input type="text" id="newid" value="some text"/>
\r
2736 * @param String val Set the property to the specified value.
\r
2737 * @cat DOM/Attributes
\r
2742 * Get the current title of the first matched element.
\r
2744 * @example $("img").title();
\r
2745 * @before <img src="test.jpg" title="my image"/>
\r
2746 * @result "my image"
\r
2748 * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
\r
2749 * ok( !$("#yahoo").title(), "Check for title" );
\r
2753 * @cat DOM/Attributes
\r
2757 * Set the title of every matched element.
\r
2759 * @example $("img").title("new title");
\r
2760 * @before <img src="test.jpg" title="my image"/>
\r
2761 * @result <img src="test.jpg" title="new image"/>
\r
2765 * @param String val Set the property to the specified value.
\r
2766 * @cat DOM/Attributes
\r
2771 * Get the current name of the first matched element.
\r
2773 * @example $("input").name();
\r
2774 * @before <input type="text" name="username"/>
\r
2775 * @result "username"
\r
2777 * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
\r
2778 * ok( $("#hidden1").name() == "hidden", "Check for name" );
\r
2779 * ok( !$("#area1").name(), "Check for name" );
\r
2783 * @cat DOM/Attributes
\r
2787 * Set the name of every matched element.
\r
2789 * @example $("input").name("user");
\r
2790 * @before <input type="text" name="username"/>
\r
2791 * @result <input type="text" name="user"/>
\r
2795 * @param String val Set the property to the specified value.
\r
2796 * @cat DOM/Attributes
\r
2801 * Get the current href of the first matched element.
\r
2803 * @example $("a").href();
\r
2804 * @before <a href="test.html">my link</a>
\r
2805 * @result "test.html"
\r
2809 * @cat DOM/Attributes
\r
2813 * Set the href of every matched element.
\r
2815 * @example $("a").href("test2.html");
\r
2816 * @before <a href="test.html">my link</a>
\r
2817 * @result <a href="test2.html">my link</a>
\r
2821 * @param String val Set the property to the specified value.
\r
2822 * @cat DOM/Attributes
\r
2827 * Get the current src of the first matched element.
\r
2829 * @example $("img").src();
\r
2830 * @before <img src="test.jpg" title="my image"/>
\r
2831 * @result "test.jpg"
\r
2835 * @cat DOM/Attributes
\r
2839 * Set the src of every matched element.
\r
2841 * @example $("img").src("test2.jpg");
\r
2842 * @before <img src="test.jpg" title="my image"/>
\r
2843 * @result <img src="test2.jpg" title="my image"/>
\r
2847 * @param String val Set the property to the specified value.
\r
2848 * @cat DOM/Attributes
\r
2853 * Get the current rel of the first matched element.
\r
2855 * @example $("a").rel();
\r
2856 * @before <a href="test.html" rel="nofollow">my link</a>
\r
2857 * @result "nofollow"
\r
2861 * @cat DOM/Attributes
\r
2865 * Set the rel of every matched element.
\r
2867 * @example $("a").rel("nofollow");
\r
2868 * @before <a href="test.html">my link</a>
\r
2869 * @result <a href="test.html" rel="nofollow">my link</a>
\r
2873 * @param String val Set the property to the specified value.
\r
2874 * @cat DOM/Attributes
\r
2881 * Get a set of elements containing the unique parents of the matched
\r
2882 * set of elements.
\r
2884 * @example $("p").parent()
\r
2885 * @before <div><p>Hello</p><p>Hello</p></div>
\r
2886 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
\r
2890 * @cat DOM/Traversing
\r
2894 * Get a set of elements containing the unique parents of the matched
\r
2895 * set of elements, and filtered by an expression.
\r
2897 * @example $("p").parent(".selected")
\r
2898 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
\r
2899 * @result [ <div class="selected"><p>Hello Again</p></div> ]
\r
2903 * @param String expr An expression to filter the parents with
\r
2904 * @cat DOM/Traversing
\r
2906 parent: "a.parentNode",
\r
2909 * Get a set of elements containing the unique ancestors of the matched
\r
2910 * set of elements (except for the root element).
\r
2912 * @example $("span").ancestors()
\r
2913 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2914 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
\r
2918 * @cat DOM/Traversing
\r
2922 * Get a set of elements containing the unique ancestors of the matched
\r
2923 * set of elements, and filtered by an expression.
\r
2925 * @example $("span").ancestors("p")
\r
2926 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2927 * @result [ <p><span>Hello</span></p> ]
\r
2931 * @param String expr An expression to filter the ancestors with
\r
2932 * @cat DOM/Traversing
\r
2934 ancestors: jQuery.parents,
\r
2937 * Get a set of elements containing the unique ancestors of the matched
\r
2938 * set of elements (except for the root element).
\r
2940 * @example $("span").ancestors()
\r
2941 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2942 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
\r
2946 * @cat DOM/Traversing
\r
2950 * Get a set of elements containing the unique ancestors of the matched
\r
2951 * set of elements, and filtered by an expression.
\r
2953 * @example $("span").ancestors("p")
\r
2954 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
\r
2955 * @result [ <p><span>Hello</span></p> ]
\r
2959 * @param String expr An expression to filter the ancestors with
\r
2960 * @cat DOM/Traversing
\r
2962 parents: jQuery.parents,
\r
2965 * Get a set of elements containing the unique next siblings of each of the
\r
2966 * matched set of elements.
\r
2968 * It only returns the very next sibling, not all next siblings.
\r
2970 * @example $("p").next()
\r
2971 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
\r
2972 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
\r
2976 * @cat DOM/Traversing
\r
2980 * Get a set of elements containing the unique next siblings of each of the
\r
2981 * matched set of elements, and filtered by an expression.
\r
2983 * It only returns the very next sibling, not all next siblings.
\r
2985 * @example $("p").next(".selected")
\r
2986 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
\r
2987 * @result [ <p class="selected">Hello Again</p> ]
\r
2991 * @param String expr An expression to filter the next Elements with
\r
2992 * @cat DOM/Traversing
\r
2994 next: "jQuery.sibling(a).next",
\r
2997 * Get a set of elements containing the unique previous siblings of each of the
\r
2998 * matched set of elements.
\r
3000 * It only returns the immediately previous sibling, not all previous siblings.
\r
3002 * @example $("p").prev()
\r
3003 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
3004 * @result [ <div><span>Hello Again</span></div> ]
\r
3008 * @cat DOM/Traversing
\r
3012 * Get a set of elements containing the unique previous siblings of each of the
\r
3013 * matched set of elements, and filtered by an expression.
\r
3015 * It only returns the immediately previous sibling, not all previous siblings.
\r
3017 * @example $("p").previous(".selected")
\r
3018 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
\r
3019 * @result [ <div><span>Hello</span></div> ]
\r
3023 * @param String expr An expression to filter the previous Elements with
\r
3024 * @cat DOM/Traversing
\r
3026 prev: "jQuery.sibling(a).prev",
\r
3029 * Get a set of elements containing all of the unique siblings of each of the
\r
3030 * matched set of elements.
\r
3032 * @example $("div").siblings()
\r
3033 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
3034 * @result [ <p>Hello</p>, <p>And Again</p> ]
\r
3036 * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
\r
3040 * @cat DOM/Traversing
\r
3044 * Get a set of elements containing all of the unique siblings of each of the
\r
3045 * matched set of elements, and filtered by an expression.
\r
3047 * @example $("div").siblings(".selected")
\r
3048 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
\r
3049 * @result [ <p class="selected">Hello Again</p> ]
\r
3051 * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
\r
3052 * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
\r
3056 * @param String expr An expression to filter the sibling Elements with
\r
3057 * @cat DOM/Traversing
\r
3059 siblings: "jQuery.sibling(a, null, true)",
\r
3063 * Get a set of elements containing all of the unique children of each of the
\r
3064 * matched set of elements.
\r
3066 * @example $("div").children()
\r
3067 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
\r
3068 * @result [ <span>Hello Again</span> ]
\r
3070 * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
\r
3074 * @cat DOM/Traversing
\r
3078 * Get a set of elements containing all of the unique children of each of the
\r
3079 * matched set of elements, and filtered by an expression.
\r
3081 * @example $("div").children(".selected")
\r
3082 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
\r
3083 * @result [ <p class="selected">Hello Again</p> ]
\r
3085 * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
\r
3089 * @param String expr An expression to filter the child Elements with
\r
3090 * @cat DOM/Traversing
\r
3092 children: "jQuery.sibling(a.firstChild)"
\r
3098 * Remove an attribute from each of the matched elements.
\r
3100 * @example $("input").removeAttr("disabled")
\r
3101 * @before <input disabled="disabled"/>
\r
3102 * @result <input/>
\r
3104 * @name removeAttr
\r
3106 * @param String name The name of the attribute to remove.
\r
3109 removeAttr: function( key ) {
\r
3110 this.removeAttribute( key );
\r
3114 * Displays each of the set of matched elements if they are hidden.
\r
3116 * @example $("p").show()
\r
3117 * @before <p style="display: none">Hello</p>
\r
3118 * @result [ <p style="display: block">Hello</p> ]
\r
3120 * @test var pass = true, div = $("div");
\r
3121 * div.show().each(function(){
\r
3122 * if ( this.style.display == "none" ) pass = false;
\r
3124 * ok( pass, "Show" );
\r
3131 this.style.display = this.oldblock ? this.oldblock : "";
\r
3132 if ( jQuery.css(this,"display") == "none" )
\r
3133 this.style.display = "block";
\r
3137 * Hides each of the set of matched elements if they are shown.
\r
3139 * @example $("p").hide()
\r
3140 * @before <p>Hello</p>
\r
3141 * @result [ <p style="display: none">Hello</p> ]
\r
3143 * var pass = true, div = $("div");
\r
3144 * div.hide().each(function(){
\r
3145 * if ( this.style.display != "none" ) pass = false;
\r
3147 * ok( pass, "Hide" );
\r
3154 this.oldblock = this.oldblock || jQuery.css(this,"display");
\r
3155 if ( this.oldblock == "none" )
\r
3156 this.oldblock = "block";
\r
3157 this.style.display = "none";
\r
3161 * Toggles each of the set of matched elements. If they are shown,
\r
3162 * toggle makes them hidden. If they are hidden, toggle
\r
3163 * makes them shown.
\r
3165 * @example $("p").toggle()
\r
3166 * @before <p>Hello</p><p style="display: none">Hello Again</p>
\r
3167 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
\r
3173 toggle: function(){
\r
3174 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
\r
3178 * Adds the specified class to each of the set of matched elements.
\r
3180 * @example $("p").addClass("selected")
\r
3181 * @before <p>Hello</p>
\r
3182 * @result [ <p class="selected">Hello</p> ]
\r
3184 * @test var div = $("div");
\r
3185 * div.addClass("test");
\r
3186 * var pass = true;
\r
3187 * for ( var i = 0; i < div.size(); i++ ) {
\r
3188 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
\r
3190 * ok( pass, "Add Class" );
\r
3194 * @param String class A CSS class to add to the elements
\r
3197 addClass: function(c){
\r
3198 jQuery.className.add(this,c);
\r
3202 * Removes the specified class from the set of matched elements.
\r
3204 * @example $("p").removeClass("selected")
\r
3205 * @before <p class="selected">Hello</p>
\r
3206 * @result [ <p>Hello</p> ]
\r
3208 * @test var div = $("div").addClass("test");
\r
3209 * div.removeClass("test");
\r
3210 * var pass = true;
\r
3211 * for ( var i = 0; i < div.size(); i++ ) {
\r
3212 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
\r
3214 * ok( pass, "Remove Class" );
\r
3218 * var div = $("div").addClass("test").addClass("foo").addClass("bar");
\r
3219 * div.removeClass("test").removeClass("bar").removeClass("foo");
\r
3220 * var pass = true;
\r
3221 * for ( var i = 0; i < div.size(); i++ ) {
\r
3222 * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
\r
3224 * ok( pass, "Remove multiple classes" );
\r
3226 * @name removeClass
\r
3228 * @param String class A CSS class to remove from the elements
\r
3231 removeClass: function(c){
\r
3232 jQuery.className.remove(this,c);
\r
3236 * Adds the specified class if it is present, removes it if it is
\r
3239 * @example $("p").toggleClass("selected")
\r
3240 * @before <p>Hello</p><p class="selected">Hello Again</p>
\r
3241 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
\r
3243 * @name toggleClass
\r
3245 * @param String class A CSS class with which to toggle the elements
\r
3248 toggleClass: function( c ){
\r
3249 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
\r
3253 * Removes all matched elements from the DOM. This does NOT remove them from the
\r
3254 * jQuery object, allowing you to use the matched elements further.
\r
3256 * @example $("p").remove();
\r
3257 * @before <p>Hello</p> how are <p>you?</p>
\r
3262 * @cat DOM/Manipulation
\r
3266 * Removes only elements (out of the list of matched elements) that match
\r
3267 * the specified jQuery expression. This does NOT remove them from the
\r
3268 * jQuery object, allowing you to use the matched elements further.
\r
3270 * @example $("p").remove(".hello");
\r
3271 * @before <p class="hello">Hello</p> how are <p>you?</p>
\r
3272 * @result how are <p>you?</p>
\r
3276 * @param String expr A jQuery expression to filter elements by.
\r
3277 * @cat DOM/Manipulation
\r
3279 remove: function(a){
\r
3280 if ( !a || jQuery.filter( a, [this] ).r )
\r
3281 this.parentNode.removeChild( this );
\r
3285 * Removes all child nodes from the set of matched elements.
\r
3287 * @example $("p").empty()
\r
3288 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
\r
3289 * @result [ <p></p> ]
\r
3293 * @cat DOM/Manipulation
\r
3295 empty: function(){
\r
3296 while ( this.firstChild )
\r
3297 this.removeChild( this.firstChild );
\r
3301 * Binds a handler to a particular event (like click) for each matched element.
\r
3302 * The event handler is passed an event object that you can use to prevent
\r
3303 * default behaviour. To stop both default action and event bubbling, your handler
\r
3304 * has to return false.
\r
3306 * @example $("p").bind( "click", function() {
\r
3307 * alert( $(this).text() );
\r
3309 * @before <p>Hello</p>
\r
3310 * @result alert("Hello")
\r
3312 * @example $("form").bind( "submit", function() { return false; } )
\r
3313 * @desc Cancel a default action and prevent it from bubbling by returning false
\r
3314 * from your function.
\r
3316 * @example $("form").bind( "submit", function(event) {
\r
3317 * event.preventDefault();
\r
3319 * @desc Cancel only the default action by using the preventDefault method.
\r
3322 * @example $("form").bind( "submit", function(event) {
\r
3323 * event.stopPropagation();
\r
3325 * @desc Stop only an event from bubbling by using the stopPropagation method.
\r
3329 * @param String type An event type
\r
3330 * @param Function fn A function to bind to the event on each of the set of matched elements
\r
3333 bind: function( type, fn ) {
\r
3334 if ( fn.constructor == String )
\r
3335 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
\r
3336 jQuery.event.add( this, type, fn );
\r
3340 * The opposite of bind, removes a bound event from each of the matched
\r
3341 * elements. You must pass the identical function that was used in the original
\r
3344 * @example $("p").unbind( "click", function() { alert("Hello"); } )
\r
3345 * @before <p onclick="alert('Hello');">Hello</p>
\r
3346 * @result [ <p>Hello</p> ]
\r
3350 * @param String type An event type
\r
3351 * @param Function fn A function to unbind from the event on each of the set of matched elements
\r
3356 * Removes all bound events of a particular type from each of the matched
\r
3359 * @example $("p").unbind( "click" )
\r
3360 * @before <p onclick="alert('Hello');">Hello</p>
\r
3361 * @result [ <p>Hello</p> ]
\r
3365 * @param String type An event type
\r
3370 * Removes all bound events from each of the matched elements.
\r
3372 * @example $("p").unbind()
\r
3373 * @before <p onclick="alert('Hello');">Hello</p>
\r
3374 * @result [ <p>Hello</p> ]
\r
3380 unbind: function( type, fn ) {
\r
3381 jQuery.event.remove( this, type, fn );
\r
3385 * Trigger a type of event on every matched element.
\r
3387 * @example $("p").trigger("click")
\r
3388 * @before <p click="alert('hello')">Hello</p>
\r
3389 * @result alert('hello')
\r
3393 * @param String type An event type to trigger.
\r
3396 trigger: function( type, data ) {
\r
3397 jQuery.event.trigger( type, data, this );
\r