2 * jQuery @VERSION - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
18 * @test ok( Array.prototype.push, "Array.push()" );
19 * ok( Function.prototype.apply, "Function.apply()" );
20 * ok( document.getElementById, "getElementById" );
21 * ok( document.getElementsByTagName, "getElementsByTagName" );
22 * ok( RegExp, "RegExp" );
23 * ok( jQuery, "jQuery" );
31 var jQuery = function(a,c) {
33 // Shortcut for document ready (because $(document).each() is silly)
34 if ( a && typeof a == "function" && jQuery.fn.ready && !a.nodeType && a[0] == undefined ) // Safari reports typeof on DOM NodeLists as a function
35 return jQuery(document).ready(a);
37 // Make sure that a selection was provided
38 a = a || jQuery.context || document;
40 // Watch for when a jQuery object is passed as the selector
42 return jQuery( jQuery.merge( a, [] ) );
44 // Watch for when a jQuery object is passed at the context
46 return jQuery( c ).find(a);
48 // If the context is global, return a new object
50 return new jQuery(a,c);
52 // Handle HTML strings
53 if ( a.constructor == String ) {
54 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
55 if ( m ) a = jQuery.clean( [ m[1] ] );
58 // Watch for when an array is passed in
59 this.get( a.constructor == Array || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType ?
60 // Assume that it is an array of DOM Elements
61 jQuery.merge( a, [] ) :
63 // Find the matching elements and save them for later
64 jQuery.find( a, c ) );
66 // See if an extra function was provided
67 var fn = arguments[ arguments.length - 1 ];
69 // If so, execute it in context
70 if ( fn && typeof fn == "function" )
76 // Map over the $ in case of overwrite
77 if ( typeof $ != "undefined" )
81 * This function accepts a string containing a CSS selector,
82 * basic XPath, or raw HTML, which is then used to match a set of elements.
83 * The HTML string is different from the traditional selectors in that
84 * it creates the DOM elements representing that HTML string, on the fly,
85 * to be (assumedly) inserted into the document later.
87 * The core functionality of jQuery centers around this function.
88 * Everything in jQuery is based upon this, or uses this in some way.
89 * The most basic use of this function is to pass in an expression
90 * (usually consisting of CSS or XPath), which then finds all matching
91 * elements and remembers them for later use.
93 * By default, $() looks for DOM elements within the context of the
94 * current HTML document.
96 * @example $("div > p")
97 * @desc This finds all p elements that are children of a div element.
98 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
99 * @result [ <p>two</p> ]
101 * @example $("<div><p>Hello</p></div>").appendTo("#body")
102 * @desc Creates a div element (and all of its contents) dynamically,
103 * and appends it to the element with the ID of body. Internally, an
104 * element is created and it's innerHTML property set to the given markup.
105 * It is therefore both quite flexible and limited.
108 * @param String expr An expression to search with, or a string of HTML to create on the fly.
114 * This function accepts a string containing a CSS selector, or
115 * basic XPath, which is then used to match a set of elements with the
116 * context of the specified DOM element, or document
118 * @example $("div", xml.responseXML)
119 * @desc This finds all div elements within the specified XML document.
122 * @param String expr An expression to search with.
123 * @param Element context A DOM Element, or Document, representing the base context.
129 * Wrap jQuery functionality around a specific DOM Element.
130 * This function also accepts XML Documents and Window objects
131 * as valid arguments (even though they are not DOM Elements).
133 * @example $(document).find("div > p")
134 * @before <p>one</p> <div><p>two</p></div> <p>three</p>
135 * @result [ <p>two</p> ]
137 * @example $(document.body).background( "black" );
138 * @desc Sets the background color of the page to black.
141 * @param Element elem A DOM element to be encapsulated by a jQuery object.
147 * Wrap jQuery functionality around a set of DOM Elements.
149 * @example $( myForm.elements ).hide()
150 * @desc Hides all the input elements within a form
153 * @param Array<Element> elems An array of DOM elements to be encapsulated by a jQuery object.
159 * A shorthand for $(document).ready(), allowing you to bind a function
160 * to be executed when the DOM document has finished loading. This function
161 * behaves just like $(document).ready(), in that it should be used to wrap
162 * all of the other $() operations on your page. While this function is,
163 * technically, chainable - there really isn't much use for chaining against it.
164 * You can have as many $(document).ready events on your page as you like.
166 * @example $(function(){
167 * // Document is ready
169 * @desc Executes the function when the DOM is ready to be used.
172 * @param Function fn The function to execute when the DOM is ready.
178 * A means of creating a cloned copy of a jQuery object. This function
179 * copies the set of matched elements from one jQuery object and creates
180 * another, new, jQuery object containing the same elements.
182 * @example var div = $("div");
183 * $( div ).find("p");
184 * @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).
187 * @param jQuery obj The jQuery object to be cloned.
192 // Map the jQuery namespace to the '$' one
195 jQuery.fn = jQuery.prototype = {
197 * The current version of jQuery.
208 * The number of elements currently matched.
210 * @example $("img").length;
211 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
214 * @test ok( $("div").length == 2, "Get Number of Elements Found" );
223 * The number of elements currently matched.
225 * @example $("img").size();
226 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
229 * @test ok( $("div").size() == 2, "Get Number of Elements Found" );
240 * Access all matched elements. This serves as a backwards-compatible
241 * way of accessing all matched elements (other than the jQuery object
242 * itself, which is, in fact, an array of elements).
244 * @example $("img").get();
245 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
246 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
248 * @test isSet( $("div").get(), q("main","foo"), "Get All Elements" );
251 * @type Array<Element>
256 * Access a single matched element. num is used to access the
257 * Nth element matched.
259 * @example $("img").get(1);
260 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
261 * @result [ <img src="test1.jpg"/> ]
263 * @test ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
267 * @param Number num Access the element in the Nth position.
272 * Set the jQuery object to an array of elements.
274 * @example $("img").get([ document.body ]);
275 * @result $("img").get() == [ document.body ]
280 * @param Elements elems An array of elements
283 get: function( num ) {
284 // Watch for when an array (of elements) is passed in
285 if ( num && num.constructor == Array ) {
287 // Use a tricky hack to make the jQuery object
288 // look and feel like an array
290 [].push.apply( this, num );
294 return num == undefined ?
296 // Return a 'clean' array
297 jQuery.merge( this, [] ) :
299 // Return just the object
304 * Execute a function within the context of every matched element.
305 * This means that every time the passed-in function is executed
306 * (which is once for every element matched) the 'this' keyword
307 * points to the specific element.
309 * Additionally, the function, when executed, is passed a single
310 * argument representing the position of the element in the matched
313 * @example $("img").each(function(){
314 * this.src = "test.jpg";
316 * @before <img/> <img/>
317 * @result <img src="test.jpg"/> <img src="test.jpg"/>
319 * @example $("img").each(function(i){
320 * alert( "Image #" + i + " is " + this );
322 * @before <img/> <img/>
323 * @result <img src="test.jpg"/> <img src="test.jpg"/>
325 * @test var div = $("div");
326 * div.each(function(){this.foo = 'zoo';});
328 * for ( var i = 0; i < div.size(); i++ ) {
329 * if ( div.get(i).foo != "zoo" ) pass = false;
331 * ok( pass, "Execute a function, Relative" );
335 * @param Function fn A function to execute
338 each: function( fn, args ) {
339 return jQuery.each( this, fn, args );
343 * Searches every matched element for the object and returns
344 * the index of the element, if found, starting with zero.
345 * Returns -1 if the object wasn't found.
347 * @example $("*").index(document.getElementById('foobar'))
348 * @before <div id="foobar"></div><b></b><span id="foo"></span>
351 * @example $("*").index(document.getElementById('foo'))
352 * @before <div id="foobar"></div><b></b><span id="foo"></span>
355 * @example $("*").index(document.getElementById('bar'))
356 * @before <div id="foobar"></div><b></b><span id="foo"></span>
359 * @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );
360 * ok( $([window, document]).index(document) == 1, "Check for index of elements" );
361 * var inputElements = $('#radio1,#radio2,#check1,#check2');
362 * ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
363 * ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
364 * ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
365 * ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
366 * ok( inputElements.index(window) == -1, "Check for not found index" );
367 * ok( inputElements.index(document) == -1, "Check for not found index" );
371 * @param Object obj Object to search for
374 index: function( obj ) {
376 this.each(function(i){
377 if ( this == obj ) pos = i;
383 * Access a property on the first matched element.
384 * This method makes it easy to retrieve a property value
385 * from the first matched element.
387 * @example $("img").attr("src");
388 * @before <img src="test.jpg"/>
391 * @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
392 * ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
393 * ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
394 * ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
395 * ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
396 * ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
397 * ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
398 * ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
399 * ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
400 * ok( $('#name').attr('name') == "name", 'Check for name attribute' );
401 * ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
402 * ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
406 * @param String name The name of the property to access.
411 * Set a hash of key/value object properties to all matched elements.
412 * This serves as the best way to set a large number of properties
413 * on all matched elements.
415 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
417 * @result <img src="test.jpg" alt="Test Image"/>
419 * @test var pass = true;
420 * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
421 * if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
423 * ok( pass, "Set Multiple Attributes" );
427 * @param Hash prop A set of key/value pairs to set as object properties.
432 * Set a single property to a value, on all matched elements.
434 * @example $("img").attr("src","test.jpg");
436 * @result <img src="test.jpg"/>
438 * @test var div = $("div");
439 * div.attr("foo", "bar");
441 * for ( var i = 0; i < div.size(); i++ ) {
442 * if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
444 * ok( pass, "Set Attribute" );
446 * $("#name").attr('name', 'something');
447 * ok( $("#name").name() == 'something', 'Set name attribute' );
448 * $("#check2").attr('checked', true);
449 * ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
450 * $("#check2").attr('checked', false);
451 * ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
452 * $("#text1").attr('readonly', true);
453 * ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
454 * $("#text1").attr('readonly', false);
455 * ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
458 * $.get('data/dashboard.xml', function(xml) {
460 * $('tab', xml).each(function() {
461 * titles.push($(this).attr('title'));
463 * ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
464 * ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
470 * @param String key The name of the property to set.
471 * @param Object value The value to set the property to.
474 attr: function( key, value, type ) {
475 // Check to see if we're setting style values
476 return key.constructor != String || value != undefined ?
477 this.each(function(){
478 // See if we're setting a hash of styles
479 if ( value == undefined )
480 // Set all the styles
481 for ( var prop in key )
483 type ? this.style : this,
487 // See if we're setting a single key/value style
490 type ? this.style : this,
495 // Look for the case where we're accessing a style value
496 jQuery[ type || "attr" ]( this[0], key );
500 * Access a style property on the first matched element.
501 * This method makes it easy to retrieve a style property value
502 * from the first matched element.
504 * @example $("p").css("color");
505 * @before <p style="color:red;">Test Paragraph.</p>
507 * @desc Retrieves the color style of the first paragraph
509 * @example $("p").css("fontWeight");
510 * @before <p style="font-weight: bold;">Test Paragraph.</p>
512 * @desc Retrieves the font-weight style of the first paragraph.
513 * Note that for all style properties with a dash (like 'font-weight'), you have to
514 * write it in camelCase. In other words: Every time you have a '-' in a
515 * property, remove it and replace the next character with an uppercase
516 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
517 * borderStyle, borderBottomWidth etc.
519 * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"');
523 * @param String name The name of the property to access.
528 * Set a hash of key/value style properties to all matched elements.
529 * This serves as the best way to set a large number of style properties
530 * on all matched elements.
532 * @example $("p").css({ color: "red", background: "blue" });
533 * @before <p>Test Paragraph.</p>
534 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
536 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
537 * $('#foo').css({display: 'none'});
538 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
539 * $('#foo').css({display: 'block'});
540 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
541 * $('#floatTest').css({styleFloat: 'right'});
542 * ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
543 * $('#floatTest').css({cssFloat: 'left'});
544 * ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
545 * $('#floatTest').css({'float': 'right'});
546 * ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
547 * $('#floatTest').css({'font-size': '30px'});
548 * ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
552 * @param Hash prop A set of key/value pairs to set as style properties.
557 * Set a single style property to a value, on all matched elements.
559 * @example $("p").css("color","red");
560 * @before <p>Test Paragraph.</p>
561 * @result <p style="color:red;">Test Paragraph.</p>
562 * @desc Changes the color of all paragraphs to red
565 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
566 * $('#foo').css('display', 'none');
567 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
568 * $('#foo').css('display', 'block');
569 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
570 * $('#floatTest').css('styleFloat', 'left');
571 * ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
572 * $('#floatTest').css('cssFloat', 'right');
573 * ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
574 * $('#floatTest').css('float', 'left');
575 * ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
576 * $('#floatTest').css('font-size', '20px');
577 * ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
581 * @param String key The name of the property to set.
582 * @param Object value The value to set the property to.
585 css: function( key, value ) {
586 return this.attr( key, value, "curCSS" );
590 * Retrieve the text contents of all matched elements. The result is
591 * a string that contains the combined text contents of all matched
592 * elements. This method works on both HTML and XML documents.
594 * @example $("p").text();
595 * @before <p>Test Paragraph.</p>
596 * @result Test Paragraph.
598 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
599 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
608 for ( var j = 0; j < e.length; j++ ) {
609 var r = e[j].childNodes;
610 for ( var i = 0; i < r.length; i++ )
611 if ( r[i].nodeType != 8 )
612 t += r[i].nodeType != 1 ?
613 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
619 * Wrap all matched elements with a structure of other elements.
620 * This wrapping process is most useful for injecting additional
621 * stucture into a document, without ruining the original semantic
622 * qualities of a document.
624 * This works by going through the first element
625 * provided (which is generated, on the fly, from the provided HTML)
626 * and finds the deepest ancestor element within its
627 * structure - it is that element that will en-wrap everything else.
629 * This does not work with elements that contain text. Any necessary text
630 * must be added after the wrapping is done.
632 * @example $("p").wrap("<div class='wrap'></div>");
633 * @before <p>Test Paragraph.</p>
634 * @result <div class='wrap'><p>Test Paragraph.</p></div>
636 * @test var defaultText = 'Try them out:'
637 * var result = $('#first').wrap('<div class="red"><span></span></div>').text();
638 * ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
639 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
643 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
644 * @cat DOM/Manipulation
648 * Wrap all matched elements with a structure of other elements.
649 * This wrapping process is most useful for injecting additional
650 * stucture into a document, without ruining the original semantic
651 * qualities of a document.
653 * This works by going through the first element
654 * provided and finding the deepest ancestor element within its
655 * structure - it is that element that will en-wrap everything else.
657 * This does not work with elements that contain text. Any necessary text
658 * must be added after the wrapping is done.
660 * @example $("p").wrap( document.getElementById('content') );
661 * @before <p>Test Paragraph.</p><div id="content"></div>
662 * @result <div id="content"><p>Test Paragraph.</p></div>
664 * @test var defaultText = 'Try them out:'
665 * var result = $('#first').wrap(document.getElementById('empty')).parent();
666 * ok( result.is('ol'), 'Check for element wrapping' );
667 * ok( result.text() == defaultText, 'Check for element wrapping' );
671 * @param Element elem A DOM element that will be wrapped.
672 * @cat DOM/Manipulation
675 // The elements to wrap the target around
676 var a = jQuery.clean(arguments);
678 // Wrap each of the matched elements individually
679 return this.each(function(){
680 // Clone the structure that we're using to wrap
681 var b = a[0].cloneNode(true);
683 // Insert it before the element to be wrapped
684 this.parentNode.insertBefore( b, this );
686 // Find the deepest point in the wrap structure
687 while ( b.firstChild )
690 // Move the matched element to within the wrap structure
691 b.appendChild( this );
696 * Append any number of elements to the inside of every matched elements,
697 * generated from the provided HTML.
698 * This operation is similar to doing an appendChild to all the
699 * specified elements, adding them into the document.
701 * @example $("p").append("<b>Hello</b>");
702 * @before <p>I would like to say: </p>
703 * @result <p>I would like to say: <b>Hello</b></p>
705 * @test var defaultText = 'Try them out:'
706 * var result = $('#first').append('<b>buga</b>');
707 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
708 * ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
712 * @param String html A string of HTML, that will be created on the fly and appended to the target.
713 * @cat DOM/Manipulation
717 * Append an element to the inside of all matched elements.
718 * This operation is similar to doing an appendChild to all the
719 * specified elements, adding them into the document.
721 * @example $("p").append( $("#foo")[0] );
722 * @before <p>I would like to say: </p><b id="foo">Hello</b>
723 * @result <p>I would like to say: <b id="foo">Hello</b></p>
725 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
726 * $('#sap').append(document.getElementById('first'));
727 * ok( expected == $('#sap').text(), "Check for appending of element" );
731 * @param Element elem A DOM element that will be appended.
732 * @cat DOM/Manipulation
736 * Append any number of elements to the inside of all matched elements.
737 * This operation is similar to doing an appendChild to all the
738 * specified elements, adding them into the document.
740 * @example $("p").append( $("b") );
741 * @before <p>I would like to say: </p><b>Hello</b>
742 * @result <p>I would like to say: <b>Hello</b></p>
744 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
745 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
746 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
750 * @param Array<Element> elems An array of elements, all of which will be appended.
751 * @cat DOM/Manipulation
754 return this.domManip(arguments, true, 1, function(a){
755 this.appendChild( a );
760 * Prepend any number of elements to the inside of every matched elements,
761 * generated from the provided HTML.
762 * This operation is the best way to insert dynamically created elements
763 * inside, at the beginning, of all the matched element.
765 * @example $("p").prepend("<b>Hello</b>");
766 * @before <p>I would like to say: </p>
767 * @result <p><b>Hello</b>I would like to say: </p>
769 * @test var defaultText = 'Try them out:'
770 * var result = $('#first').prepend('<b>buga</b>');
771 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
772 * ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
776 * @param String html A string of HTML, that will be created on the fly and appended to the target.
777 * @cat DOM/Manipulation
781 * Prepend an element to the inside of all matched elements.
782 * This operation is the best way to insert an element inside, at the
783 * beginning, of all the matched element.
785 * @example $("p").prepend( $("#foo")[0] );
786 * @before <p>I would like to say: </p><b id="foo">Hello</b>
787 * @result <p><b id="foo">Hello</b>I would like to say: </p>
789 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
790 * $('#sap').prepend(document.getElementById('first'));
791 * ok( expected == $('#sap').text(), "Check for prepending of element" );
795 * @param Element elem A DOM element that will be appended.
796 * @cat DOM/Manipulation
800 * Prepend any number of elements to the inside of all matched elements.
801 * This operation is the best way to insert a set of elements inside, at the
802 * beginning, of all the matched element.
804 * @example $("p").prepend( $("b") );
805 * @before <p>I would like to say: </p><b>Hello</b>
806 * @result <p><b>Hello</b>I would like to say: </p>
808 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
809 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
810 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
814 * @param Array<Element> elems An array of elements, all of which will be appended.
815 * @cat DOM/Manipulation
817 prepend: function() {
818 return this.domManip(arguments, true, -1, function(a){
819 this.insertBefore( a, this.firstChild );
824 * Insert any number of dynamically generated elements before each of the
827 * @example $("p").before("<b>Hello</b>");
828 * @before <p>I would like to say: </p>
829 * @result <b>Hello</b><p>I would like to say: </p>
831 * @test var expected = 'This is a normal link: bugaYahoo';
832 * $('#yahoo').before('<b>buga</b>');
833 * ok( expected == $('#en').text(), 'Insert String before' );
837 * @param String html A string of HTML, that will be created on the fly and appended to the target.
838 * @cat DOM/Manipulation
842 * Insert an element before each of the matched elements.
844 * @example $("p").before( $("#foo")[0] );
845 * @before <p>I would like to say: </p><b id="foo">Hello</b>
846 * @result <b id="foo">Hello</b><p>I would like to say: </p>
848 * @test var expected = "This is a normal link: Try them out:Yahoo";
849 * $('#yahoo').before(document.getElementById('first'));
850 * ok( expected == $('#en').text(), "Insert element before" );
854 * @param Element elem A DOM element that will be appended.
855 * @cat DOM/Manipulation
859 * Insert any number of elements before each of the matched elements.
861 * @example $("p").before( $("b") );
862 * @before <p>I would like to say: </p><b>Hello</b>
863 * @result <b>Hello</b><p>I would like to say: </p>
865 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
866 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
867 * ok( expected == $('#en').text(), "Insert array of elements before" );
871 * @param Array<Element> elems An array of elements, all of which will be appended.
872 * @cat DOM/Manipulation
875 return this.domManip(arguments, false, 1, function(a){
876 this.parentNode.insertBefore( a, this );
881 * Insert any number of dynamically generated elements after each of the
884 * @example $("p").after("<b>Hello</b>");
885 * @before <p>I would like to say: </p>
886 * @result <p>I would like to say: </p><b>Hello</b>
888 * @test var expected = 'This is a normal link: Yahoobuga';
889 * $('#yahoo').after('<b>buga</b>');
890 * ok( expected == $('#en').text(), 'Insert String after' );
894 * @param String html A string of HTML, that will be created on the fly and appended to the target.
895 * @cat DOM/Manipulation
899 * Insert an element after each of the matched elements.
901 * @example $("p").after( $("#foo")[0] );
902 * @before <b id="foo">Hello</b><p>I would like to say: </p>
903 * @result <p>I would like to say: </p><b id="foo">Hello</b>
905 * @test var expected = "This is a normal link: YahooTry them out:";
906 * $('#yahoo').after(document.getElementById('first'));
907 * ok( expected == $('#en').text(), "Insert element after" );
911 * @param Element elem A DOM element that will be appended.
912 * @cat DOM/Manipulation
916 * Insert any number of elements after each of the matched elements.
918 * @example $("p").after( $("b") );
919 * @before <b>Hello</b><p>I would like to say: </p>
920 * @result <p>I would like to say: </p><b>Hello</b>
922 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
923 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
924 * ok( expected == $('#en').text(), "Insert array of elements after" );
928 * @param Array<Element> elems An array of elements, all of which will be appended.
929 * @cat DOM/Manipulation
932 return this.domManip(arguments, false, -1, function(a){
933 this.parentNode.insertBefore( a, this.nextSibling );
938 * End the most recent 'destructive' operation, reverting the list of matched elements
939 * back to its previous state. After an end operation, the list of matched elements will
940 * revert to the last state of matched elements.
942 * @example $("p").find("span").end();
943 * @before <p><span>Hello</span>, how are you?</p>
944 * @result $("p").find("span").end() == [ <p>...</p> ]
946 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
947 * ok( $('#yahoo').end(), 'Check for end with nothing to end' );
951 * @cat DOM/Traversing
954 if( !(this.stack && this.stack.length) )
956 return this.get( this.stack.pop() );
960 * Searches for all elements that match the specified expression.
961 * This method is the optimal way of finding additional descendant
962 * elements with which to process.
964 * All searching is done using a jQuery expression. The expression can be
965 * written using CSS 1-3 Selector syntax, or basic XPath.
967 * @example $("p").find("span");
968 * @before <p><span>Hello</span>, how are you?</p>
969 * @result $("p").find("span") == [ <span>Hello</span> ]
971 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
975 * @param String expr An expression to search with.
976 * @cat DOM/Traversing
979 return this.pushStack( jQuery.map( this, function(a){
980 return jQuery.find(t,a);
985 * Create cloned copies of all matched DOM Elements. This does
986 * not create a cloned copy of this particular jQuery object,
987 * instead it creates duplicate copies of all DOM Elements.
988 * This is useful for moving copies of the elements to another
989 * location in the DOM.
991 * @example $("b").clone().prependTo("p");
992 * @before <b>Hello</b><p>, how are you?</p>
993 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
995 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
996 * var clone = $('#yahoo').clone();
997 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
998 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
1002 * @cat DOM/Manipulation
1004 clone: function(deep) {
1005 return this.pushStack( jQuery.map( this, function(a){
1006 return a.cloneNode( deep != undefined ? deep : true );
1011 * Removes all elements from the set of matched elements that do not
1012 * match the specified expression. This method is used to narrow down
1013 * the results of a search.
1015 * All searching is done using a jQuery expression. The expression
1016 * can be written using CSS 1-3 Selector syntax, or basic XPath.
1018 * @example $("p").filter(".selected")
1019 * @before <p class="selected">Hello</p><p>How are you?</p>
1020 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
1022 * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
1023 * @test $("input").filter(":checked",function(i){
1024 * ok( this == q("radio2", "check1")[i], "Filter elements, context" );
1026 * @test $("#main > p#ap > a").filter("#foobar",function(){},function(i){
1027 * ok( this == q("google","groups", "mark")[i], "Filter elements, else context" );
1032 * @param String expr An expression to search with.
1033 * @cat DOM/Traversing
1037 * Removes all elements from the set of matched elements that do not
1038 * match at least one of the expressions passed to the function. This
1039 * method is used when you want to filter the set of matched elements
1040 * through more than one expression.
1042 * Elements will be retained in the jQuery object if they match at
1043 * least one of the expressions passed.
1045 * @example $("p").filter([".selected", ":first"])
1046 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
1047 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
1051 * @param Array<String> exprs A set of expressions to evaluate against
1052 * @cat DOM/Traversing
1054 filter: function(t) {
1055 return this.pushStack(
1056 t.constructor == Array &&
1057 jQuery.map(this,function(a){
1058 for ( var i = 0; i < t.length; i++ )
1059 if ( jQuery.filter(t[i],[a]).r.length )
1064 t.constructor == Boolean &&
1065 ( t ? this.get() : [] ) ||
1067 typeof t == "function" &&
1068 jQuery.grep( this, t ) ||
1070 jQuery.filter(t,this).r, arguments );
1074 * Removes the specified Element from the set of matched elements. This
1075 * method is used to remove a single Element from a jQuery object.
1077 * @example $("p").not( document.getElementById("selected") )
1078 * @before <p>Hello</p><p id="selected">Hello Again</p>
1079 * @result [ <p>Hello</p> ]
1083 * @param Element el An element to remove from the set
1084 * @cat DOM/Traversing
1088 * Removes elements matching the specified expression from the set
1089 * of matched elements. This method is used to remove one or more
1090 * elements from a jQuery object.
1092 * @example $("p").not("#selected")
1093 * @before <p>Hello</p><p id="selected">Hello Again</p>
1094 * @result [ <p>Hello</p> ]
1096 * @test ok($("#main > p#ap > a").not("#google").length == 2, ".not")
1100 * @param String expr An expression with which to remove matching elements
1101 * @cat DOM/Traversing
1104 return this.pushStack( t.constructor == String ?
1105 jQuery.filter(t,this,false).r :
1106 jQuery.grep(this,function(a){ return a != t; }), arguments );
1110 * Adds the elements matched by the expression to the jQuery object. This
1111 * can be used to concatenate the result sets of two expressions.
1113 * @example $("p").add("span")
1114 * @before <p>Hello</p><p><span>Hello Again</span></p>
1115 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
1119 * @param String expr An expression whose matched elements are added
1120 * @cat DOM/Traversing
1124 * Adds each of the Elements in the array to the set of matched elements.
1125 * This is used to add a set of Elements to a jQuery object.
1127 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
1128 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
1129 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
1133 * @param Array<Element> els An array of Elements to add
1134 * @cat DOM/Traversing
1138 * Adds a single Element to the set of matched elements. This is used to
1139 * add a single Element to a jQuery object.
1141 * @example $("p").add( document.getElementById("a") )
1142 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1143 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1147 * @param Element el An Element to add
1148 * @cat DOM/Traversing
1151 return this.pushStack( jQuery.merge( this, t.constructor == String ?
1152 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
1156 * Checks the current selection against an expression and returns true,
1157 * if the selection fits the given expression. Does return false, if the
1158 * selection does not fit or the expression is not valid.
1160 * @example $("input[@type='checkbox']").parent().is("form")
1161 * @before <form><input type="checkbox" /></form>
1163 * @desc Returns true, because the parent of the input is a form element
1165 * @example $("input[@type='checkbox']").parent().is("form")
1166 * @before <form><p><input type="checkbox" /></p></form>
1168 * @desc Returns false, because the parent of the input is a p element
1170 * @example $("form").is(null)
1171 * @before <form></form>
1173 * @desc An invalid expression always returns false.
1175 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1176 * ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1177 * ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1178 * ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1179 * ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1180 * ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1181 * ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1182 * ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1183 * ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1184 * ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1185 * ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1186 * ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1187 * ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1188 * ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1189 * ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
1190 * ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
1191 * ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1192 * ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1193 * ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1194 * ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1195 * ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1196 * ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1200 * @param String expr The expression with which to filter
1201 * @cat DOM/Traversing
1203 is: function(expr) {
1204 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1213 * @param Boolean table
1215 * @param Function fn The function doing the DOM manipulation.
1219 domManip: function(args, table, dir, fn){
1220 var clone = this.size() > 1;
1221 var a = jQuery.clean(args);
1223 return this.each(function(){
1226 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
1227 var tbody = this.getElementsByTagName("tbody");
1229 if ( !tbody.length ) {
1230 obj = document.createElement("tbody");
1231 this.appendChild( obj );
1236 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
1237 i != ( dir < 0 ? dir : a.length ); i += dir ) {
1238 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1253 pushStack: function(a,args) {
1254 var fn = args && args[args.length-1];
1255 var fn2 = args && args[args.length-2];
1257 if ( fn && fn.constructor != Function ) fn = null;
1258 if ( fn2 && fn2.constructor != Function ) fn2 = null;
1261 if ( !this.stack ) this.stack = [];
1262 this.stack.push( this.get() );
1265 var old = this.get();
1268 if ( fn2 && a.length || !fn2 )
1269 this.each( fn2 || fn ).get( old );
1271 this.get( old ).each( fn );
1279 * Extends the jQuery object itself. Can be used to add both static
1280 * functions and plugin methods.
1282 * @example $.fn.extend({
1283 * check: function() {
1284 * this.each(function() { this.checked = true; });
1286 * uncheck: function() {
1287 * this.each(function() { this.checked = false; });
1290 * $("input[@type=checkbox]").check();
1291 * $("input[@type=radio]").uncheck();
1292 * @desc Adds two plugin methods.
1302 * Extend one object with another, returning the original,
1303 * modified, object. This is a great utility for simple inheritance.
1305 * @example var settings = { validate: false, limit: 5, name: "foo" };
1306 * var options = { validate: true, name: "bar" };
1307 * jQuery.extend(settings, options);
1308 * @result settings == { validate: true, limit: 5, name: "bar" }
1310 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1311 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1312 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1313 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
1314 * jQuery.extend(settings, options);
1315 * isSet( settings, merged, "Check if extended: settings must be extended" );
1316 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
1319 * @param Object obj The object to extend
1320 * @param Object prop The object that will be merged into the first.
1324 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1325 // Watch for the case where null or undefined gets passed in by accident
1326 if ( arguments.length > 1 && (prop === null || prop == undefined) )
1329 // If no property object was provided, then we're extending jQuery
1330 if ( !prop ) { prop = obj; obj = this; }
1332 // Extend the base object
1333 for ( var i in prop ) obj[i] = prop[i];
1335 // Return the modified object
1347 jQuery.initDone = true;
1349 jQuery.each( jQuery.macros.axis, function(i,n){
1350 jQuery.fn[ i ] = function(a) {
1351 var ret = jQuery.map(this,n);
1352 if ( a && a.constructor == String )
1353 ret = jQuery.filter(a,ret).r;
1354 return this.pushStack( ret, arguments );
1358 jQuery.each( jQuery.macros.to, function(i,n){
1359 jQuery.fn[ i ] = function(){
1361 return this.each(function(){
1362 for ( var j = 0; j < a.length; j++ )
1363 jQuery(a[j])[n]( this );
1368 jQuery.each( jQuery.macros.each, function(i,n){
1369 jQuery.fn[ i ] = function() {
1370 return this.each( n, arguments );
1374 jQuery.each( jQuery.macros.filter, function(i,n){
1375 jQuery.fn[ n ] = function(num,fn) {
1376 return this.filter( ":" + n + "(" + num + ")", fn );
1380 jQuery.each( jQuery.macros.attr, function(i,n){
1382 jQuery.fn[ i ] = function(h) {
1383 return h == undefined ?
1384 this.length ? this[0][n] : null :
1389 jQuery.each( jQuery.macros.css, function(i,n){
1390 jQuery.fn[ n ] = function(h) {
1391 return h == undefined ?
1392 ( this.length ? jQuery.css( this[0], n ) : null ) :
1400 * A generic iterator function, which can be used to seemlessly
1401 * iterate over both objects and arrays. This function is not the same
1402 * as $().each() - which is used to iterate, exclusively, over a jQuery
1403 * object. This function can be used to iterate over anything.
1405 * @example $.each( [0,1,2], function(i){
1406 * alert( "Item #" + i + ": " + this );
1408 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1410 * @example $.each( { name: "John", lang: "JS" }, function(i){
1411 * alert( "Name: " + i + ", Value: " + this );
1413 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1416 * @param Object obj The object, or array, to iterate over.
1417 * @param Function fn The function that will be executed on every object.
1421 each: function( obj, fn, args ) {
1422 if ( obj.length == undefined )
1423 for ( var i in obj )
1424 fn.apply( obj[i], args || [i, obj[i]] );
1426 for ( var i = 0; i < obj.length; i++ )
1427 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1433 if (jQuery.className.has(o,c)) return;
1434 o.className += ( o.className ? " " : "" ) + c;
1436 remove: function(o,c){
1440 var classes = o.className.split(" ");
1441 for(var i=0; i<classes.length; i++) {
1442 if(classes[i] == c) {
1443 classes.splice(i, 1);
1447 o.className = classes.join(' ');
1450 has: function(e,a) {
1451 if ( e.className != undefined )
1453 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1458 * Swap in/out style options.
1461 swap: function(e,o,f) {
1462 for ( var i in o ) {
1463 e.style["old"+i] = e.style[i];
1468 e.style[i] = e.style["old"+i];
1471 css: function(e,p) {
1472 if ( p == "height" || p == "width" ) {
1473 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1475 for ( var i=0; i<d.length; i++ ) {
1476 old["padding" + d[i]] = 0;
1477 old["border" + d[i] + "Width"] = 0;
1480 jQuery.swap( e, old, function() {
1481 if (jQuery.css(e,"display") != "none") {
1482 oHeight = e.offsetHeight;
1483 oWidth = e.offsetWidth;
1485 e = jQuery(e.cloneNode(true))
1486 .find(":radio").removeAttr("checked").end()
1488 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1489 }).appendTo(e.parentNode)[0];
1491 var parPos = jQuery.css(e.parentNode,"position");
1492 if ( parPos == "" || parPos == "static" )
1493 e.parentNode.style.position = "relative";
1495 oHeight = e.clientHeight;
1496 oWidth = e.clientWidth;
1498 if ( parPos == "" || parPos == "static" )
1499 e.parentNode.style.position = "static";
1501 e.parentNode.removeChild(e);
1505 return p == "height" ? oHeight : oWidth;
1508 return jQuery.curCSS( e, p );
1511 curCSS: function(elem, prop, force) {
1514 if (prop == 'opacity' && jQuery.browser.msie)
1515 return jQuery.attr(elem.style, 'opacity');
1517 if (prop == "float" || prop == "cssFloat")
1518 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1520 if (!force && elem.style[prop]) {
1522 ret = elem.style[prop];
1524 } else if (elem.currentStyle) {
1526 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1527 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1529 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1531 if (prop == "cssFloat" || prop == "styleFloat")
1534 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1535 var cur = document.defaultView.getComputedStyle(elem, null);
1538 ret = cur.getPropertyValue(prop);
1539 else if ( prop == 'display' )
1542 jQuery.swap(elem, { display: 'block' }, function() {
1543 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1551 clean: function(a) {
1553 for ( var i = 0; i < a.length; i++ ) {
1555 if ( arg.constructor == String ) { // Convert html string into DOM nodes
1556 // Trim whitespace, otherwise indexOf won't work as expected
1557 var s = jQuery.trim(arg), div = document.createElement("div"), wrap = [0,"",""];
1559 if ( !s.indexOf("<opt") ) // option or optgroup
1560 wrap = [1, "<select>", "</select>"];
1561 else if ( !s.indexOf("<thead") || !s.indexOf("<tbody") )
1562 wrap = [1, "<table>", "</table>"];
1563 else if ( !s.indexOf("<tr") )
1564 wrap = [2, "<table>", "</table>"]; // tbody auto-inserted
1565 else if ( !s.indexOf("<td") || !s.indexOf("<th") )
1566 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
1568 // Go to html and back, then peel off extra wrappers
1569 div.innerHTML = wrap[1] + s + wrap[2];
1570 while ( wrap[0]-- ) div = div.firstChild;
1571 arg = div.childNodes;
1575 if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
1576 for ( var n = 0; n < arg.length; n++ ) // Handles Array, jQuery, DOM NodeList collections
1579 r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
1586 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
1587 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
1595 last: "i==r.length-1",
1600 "nth-child": "jQuery.sibling(a,m[3]).cur",
1601 "first-child": "jQuery.sibling(a,0).cur",
1602 "last-child": "jQuery.sibling(a,0).last",
1603 "only-child": "jQuery.sibling(a).length==1",
1606 parent: "a.childNodes.length",
1607 empty: "!a.childNodes.length",
1610 contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
1613 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
1614 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
1617 enabled: "!a.disabled",
1618 disabled: "a.disabled",
1619 checked: "a.checked",
1620 selected: "a.selected || jQuery.attr(a, 'selected')",
1623 text: "a.type=='text'",
1624 radio: "a.type=='radio'",
1625 checkbox: "a.type=='checkbox'",
1626 file: "a.type=='file'",
1627 password: "a.type=='password'",
1628 submit: "a.type=='submit'",
1629 image: "a.type=='image'",
1630 reset: "a.type=='reset'",
1631 button: "a.type=='button'",
1632 input: "a.nodeName.toLowerCase().match(/input|select|textarea|button/)"
1634 ".": "jQuery.className.has(a,m[2])",
1638 "^=": "z && !z.indexOf(m[4])",
1639 "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
1640 "*=": "z && z.indexOf(m[4])>=0",
1643 "[": "jQuery.find(m[2],a).length"
1647 "\\.\\.|/\\.\\.", "a.parentNode",
1648 ">|/", "jQuery.sibling(a.firstChild)",
1649 "\\+", "jQuery.sibling(a).next",
1651 var s = jQuery.sibling(a);
1652 return s.n >= 0 ? s.slice(s.n+1) : [];
1658 * @test t( "Element Selector", "div", ["main","foo"] );
1659 * t( "Element Selector", "body", ["body"] );
1660 * t( "Element Selector", "html", ["html"] );
1661 * ok( $("*").size() >= 30, "Element Selector" );
1662 * t( "Parent Element", "div div", ["foo"] );
1664 * t( "ID Selector", "#body", ["body"] );
1665 * t( "ID Selector w/ Element", "body#body", ["body"] );
1666 * t( "ID Selector w/ Element", "ul#first", [] );
1668 * t( "Class Selector", ".blog", ["mark","simon"] );
1669 * t( "Class Selector", ".blog.link", ["simon"] );
1670 * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1671 * t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1673 * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1674 * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1675 * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1676 * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1678 * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1679 * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1680 * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1681 * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1682 * t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1683 * t( "All Children", "code > *", ["anchor1","anchor2"] );
1684 * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1685 * t( "Adjacent", "a + a", ["groups"] );
1686 * t( "Adjacent", "a +a", ["groups"] );
1687 * t( "Adjacent", "a+ a", ["groups"] );
1688 * t( "Adjacent", "a+a", ["groups"] );
1689 * t( "Adjacent", "p + p", ["ap","en","sap"] );
1690 * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1691 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1692 * t( "Attribute Exists", "a[@title]", ["google"] );
1693 * t( "Attribute Exists", "*[@title]", ["google"] );
1694 * t( "Attribute Exists", "[@title]", ["google"] );
1696 * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1697 * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1698 * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1699 * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1700 * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1701 * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1703 * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1704 * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1705 * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1706 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1707 * t( "Last Child", "p:last-child", ["sap"] );
1708 * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1709 * t( "Empty", "ul:empty", ["firstUL"] );
1710 * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
1711 * t( "Disabled UI Element", "input:disabled", ["text2"] );
1712 * t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1713 * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1714 * t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1715 * t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1716 * t( "Element Preceded By", "p ~ div", ["foo"] );
1717 * t( "Not", "a.blog:not(.link)", ["mark"] );
1719 * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
1720 * t( "All Div Elements", "//div", ["main","foo"] );
1721 * t( "Absolute Path", "/html/body", ["body"] );
1722 * t( "Absolute Path w/ *", "/* /body", ["body"] );
1723 * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1724 * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1725 * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1726 * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1727 * t( "Attribute Exists", "//a[@title]", ["google"] );
1728 * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1729 * t( "Parent Axis", "//p/..", ["main","foo"] );
1730 * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );
1731 * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );
1732 * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1734 * t( "nth Element", "p:nth(1)", ["ap"] );
1735 * t( "First Element", "p:first", ["firstp"] );
1736 * t( "Last Element", "p:last", ["first"] );
1737 * t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1738 * t( "Odd Elements", "p:odd", ["ap","en","first"] );
1739 * t( "Position Equals", "p:eq(1)", ["ap"] );
1740 * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1741 * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1742 * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1743 * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
1744 * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1746 * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
1748 * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
1749 * t( "All Children of ID with no children", "#firstUL/*", [] );
1751 * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
1752 * t( "Form element :radio", ":radio", ["radio1", "radio2"] );
1753 * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
1754 * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
1755 * t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
1756 * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
1757 * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
1759 * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
1760 * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
1761 * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
1764 * @type Array<Element>
1768 find: function( t, context ) {
1769 // Make sure that the context is a DOM Element
1770 if ( context && context.nodeType == undefined )
1773 // Set the correct context (if none is provided)
1774 context = context || jQuery.context || document;
1776 if ( t.constructor != String ) return [t];
1778 if ( !t.indexOf("//") ) {
1779 context = context.documentElement;
1780 t = t.substr(2,t.length);
1781 } else if ( !t.indexOf("/") ) {
1782 context = context.documentElement;
1783 t = t.substr(1,t.length);
1784 // FIX Assume the root element is right :(
1785 if ( t.indexOf("/") >= 1 )
1786 t = t.substr(t.indexOf("/"),t.length);
1789 var ret = [context];
1793 while ( t.length > 0 && last != t ) {
1797 t = jQuery.trim(t).replace( /^\/\//i, "" );
1799 var foundToken = false;
1801 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1802 if ( foundToken ) continue;
1804 var re = new RegExp("^(" + jQuery.token[i] + ")");
1808 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1809 t = jQuery.trim( t.replace( re, "" ) );
1814 if ( !foundToken ) {
1815 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1816 if ( ret[0] == context ) ret.shift();
1817 done = jQuery.merge( done, ret );
1818 r = ret = [context];
1819 t = " " + t.substr(1,t.length);
1821 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1822 var m = re2.exec(t);
1824 if ( m[1] == "#" ) {
1825 // Ummm, should make this work in all XML docs
1826 var oid = document.getElementById(m[2]);
1827 r = ret = oid ? [oid] : [];
1828 t = t.replace( re2, "" );
1830 if ( !m[2] || m[1] == "." ) m[2] = "*";
1832 for ( var i = 0; i < ret.length; i++ )
1833 r = jQuery.merge( r,
1835 jQuery.getAll(ret[i]) :
1836 ret[i].getElementsByTagName(m[2])
1844 var val = jQuery.filter(t,r);
1846 t = jQuery.trim(val.t);
1850 if ( ret && ret[0] == context ) ret.shift();
1851 done = jQuery.merge( done, ret );
1856 getAll: function(o,r) {
1858 var s = o.childNodes;
1859 for ( var i = 0; i < s.length; i++ )
1860 if ( s[i].nodeType == 1 ) {
1862 jQuery.getAll( s[i], r );
1867 attr: function(elem, name, value){
1870 "class": "className",
1871 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1872 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1873 innerHTML: "innerHTML",
1874 className: "className",
1876 disabled: "disabled",
1878 readonly: "readOnly"
1881 // IE actually uses filters for opacity ... elem is actually elem.style
1882 if (name == "opacity" && jQuery.browser.msie && value != undefined) {
1883 // IE has trouble with opacity if it does not have layout
1884 // Would prefer to check element.hasLayout first but don't have access to the element here
1886 if (value == 1) // Remove filter to avoid more IE weirdness
1887 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"");
1889 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"") + "alpha(opacity=" + value * 100 + ")";
1890 } else if (name == "opacity" && jQuery.browser.msie) {
1891 return elem["filter"] ? parseFloat( elem["filter"].match(/alpha\(opacity=(.*)\)/)[1] )/100 : 1;
1894 // Mozilla doesn't play well with opacity 1
1895 if (name == "opacity" && jQuery.browser.mozilla && value == 1) value = 0.9999;
1898 if ( value != undefined ) elem[fix[name]] = value;
1899 return elem[fix[name]];
1900 } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1901 return elem.getAttributeNode(name).nodeValue;
1902 } else if ( elem.tagName ) { // IE elem.getAttribute passes even for style
1903 if ( value != undefined ) elem.setAttribute( name, value );
1904 return elem.getAttribute( name );
1906 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1907 if ( value != undefined ) elem[name] = value;
1912 // The regular expressions that power the parsing engine
1914 // Match: [@value='test'], [@foo]
1915 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
1917 // Match: [div], [div p]
1918 "(\\[)\s*(.*?)\s*\\]",
1920 // Match: :contains('foo')
1921 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
1923 // Match: :even, :last-chlid
1927 filter: function(t,r,not) {
1928 // Figure out if we're doing regular, or inverse, filtering
1929 var g = not !== false ? jQuery.grep :
1930 function(a,f) {return jQuery.grep(a,f,true);};
1932 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1934 var p = jQuery.parse;
1936 for ( var i = 0; i < p.length; i++ ) {
1938 // Look for, and replace, string-like sequences
1939 // and finally build a regexp out of it
1940 var re = new RegExp(
1941 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
1943 var m = re.exec( t );
1946 // Re-organize the first match
1948 m = ["",m[1], m[3], m[2], m[5]];
1950 // Remove what we just matched
1951 t = t.replace( re, "" );
1957 // :not() is a special case that can be optimized by
1958 // keeping it out of the expression list
1959 if ( m[1] == ":" && m[2] == "not" )
1960 r = jQuery.filter(m[3],r,false).r;
1962 // Otherwise, find the expression to execute
1964 var f = jQuery.expr[m[1]];
1965 if ( f.constructor != String )
1966 f = jQuery.expr[m[1]][m[2]];
1968 // Build a custom macro to enclose it
1969 eval("f = function(a,i){" +
1970 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1971 "return " + f + "}");
1973 // Execute it against the current filter
1978 // Return an array of filtered elements (r)
1979 // and the modified expression string (t)
1980 return { r: r, t: t };
1984 * Remove the whitespace from the beginning and end of a string.
1986 * @example $.trim(" hello, how are you? ");
1987 * @result "hello, how are you?"
1991 * @param String str The string to trim.
1995 return t.replace(/^\s+|\s+$/g, "");
1999 * All ancestors of a given element.
2003 * @type Array<Element>
2004 * @param Element elem The element to find the ancestors of.
2005 * @cat DOM/Traversing
2007 parents: function( elem ){
2009 var cur = elem.parentNode;
2010 while ( cur && cur != document ) {
2011 matched.push( cur );
2012 cur = cur.parentNode;
2018 * All elements on a specified axis.
2023 * @param Element elem The element to find all the siblings of (including itself).
2024 * @cat DOM/Traversing
2026 sibling: function(elem, pos, not) {
2030 var siblings = elem.parentNode.childNodes;
2031 for ( var i = 0; i < siblings.length; i++ ) {
2032 if ( not === true && siblings[i] == elem ) continue;
2034 if ( siblings[i].nodeType == 1 )
2035 elems.push( siblings[i] );
2036 if ( siblings[i] == elem )
2037 elems.n = elems.length - 1;
2041 return jQuery.extend( elems, {
2042 last: elems.n == elems.length - 1,
2043 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
2044 prev: elems[elems.n - 1],
2045 next: elems[elems.n + 1]
2050 * Merge two arrays together, removing all duplicates. The final order
2051 * or the new array is: All the results from the first array, followed
2052 * by the unique results from the second array.
2054 * @example $.merge( [0,1,2], [2,3,4] )
2055 * @result [0,1,2,3,4]
2057 * @example $.merge( [3,2,1], [4,3,2] )
2062 * @param Array first The first array to merge.
2063 * @param Array second The second array to merge.
2066 merge: function(first, second) {
2069 // Move b over to the new array (this helps to avoid
2070 // StaticNodeList instances)
2071 for ( var k = 0; k < first.length; k++ )
2072 result[k] = first[k];
2074 // Now check for duplicates between a and b and only
2075 // add the unique items
2076 for ( var i = 0; i < second.length; i++ ) {
2077 var noCollision = true;
2079 // The collision-checking process
2080 for ( var j = 0; j < first.length; j++ )
2081 if ( second[i] == first[j] )
2082 noCollision = false;
2084 // If the item is unique, add it
2086 result.push( second[i] );
2093 * Filter items out of an array, by using a filter function.
2094 * The specified function will be passed two arguments: The
2095 * current array item and the index of the item in the array. The
2096 * function should return 'true' if you wish to keep the item in
2097 * the array, false if it should be removed.
2099 * @example $.grep( [0,1,2], function(i){
2106 * @param Array array The Array to find items in.
2107 * @param Function fn The function to process each item against.
2108 * @param Boolean inv Invert the selection - select the opposite of the function.
2111 grep: function(elems, fn, inv) {
2112 // If a string is passed in for the function, make a function
2113 // for it (a handy shortcut)
2114 if ( fn.constructor == String )
2115 fn = new Function("a","i","return " + fn);
2119 // Go through the array, only saving the items
2120 // that pass the validator function
2121 for ( var i = 0; i < elems.length; i++ )
2122 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
2123 result.push( elems[i] );
2129 * Translate all items in an array to another array of items.
2130 * The translation function that is provided to this method is
2131 * called for each item in the array and is passed one argument:
2132 * The item to be translated. The function can then return:
2133 * The translated value, 'null' (to remove the item), or
2134 * an array of values - which will be flattened into the full array.
2136 * @example $.map( [0,1,2], function(i){
2141 * @example $.map( [0,1,2], function(i){
2142 * return i > 0 ? i + 1 : null;
2146 * @example $.map( [0,1,2], function(i){
2147 * return [ i, i + 1 ];
2149 * @result [0, 1, 1, 2, 2, 3]
2153 * @param Array array The Array to translate.
2154 * @param Function fn The function to process each item against.
2157 map: function(elems, fn) {
2158 // If a string is passed in for the function, make a function
2159 // for it (a handy shortcut)
2160 if ( fn.constructor == String )
2161 fn = new Function("a","return " + fn);
2165 // Go through the array, translating each of the items to their
2166 // new value (or values).
2167 for ( var i = 0; i < elems.length; i++ ) {
2168 var val = fn(elems[i],i);
2170 if ( val !== null && val != undefined ) {
2171 if ( val.constructor != Array ) val = [val];
2172 result = jQuery.merge( result, val );
2180 * A number of helper functions used for managing events.
2181 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2185 // Bind an event to an element
2186 // Original by Dean Edwards
2187 add: function(element, type, handler) {
2188 // For whatever reason, IE has trouble passing the window object
2189 // around, causing it to be cloned in the process
2190 if ( jQuery.browser.msie && element.setInterval != undefined )
2193 // Make sure that the function being executed has a unique ID
2194 if ( !handler.guid )
2195 handler.guid = this.guid++;
2197 // Init the element's event structure
2198 if (!element.events)
2199 element.events = {};
2201 // Get the current list of functions bound to this event
2202 var handlers = element.events[type];
2204 // If it hasn't been initialized yet
2206 // Init the event handler queue
2207 handlers = element.events[type] = {};
2209 // Remember an existing handler, if it's already there
2210 if (element["on" + type])
2211 handlers[0] = element["on" + type];
2214 // Add the function to the element's handler list
2215 handlers[handler.guid] = handler;
2217 // And bind the global event handler to the element
2218 element["on" + type] = this.handle;
2220 // Remember the function in a global list (for triggering)
2221 if (!this.global[type])
2222 this.global[type] = [];
2223 this.global[type].push( element );
2229 // Detach an event or set of events from an element
2230 remove: function(element, type, handler) {
2232 if (type && element.events[type])
2234 delete element.events[type][handler.guid];
2236 for ( var i in element.events[type] )
2237 delete element.events[type][i];
2239 for ( var j in element.events )
2240 this.remove( element, j );
2243 trigger: function(type,data,element) {
2244 // Clone the incoming data, if any
2245 data = $.merge([], data || []);
2247 // Handle a global trigger
2249 var g = this.global[type];
2251 for ( var i = 0; i < g.length; i++ )
2252 this.trigger( type, data, g[i] );
2254 // Handle triggering a single element
2255 } else if ( element["on" + type] ) {
2256 // Pass along a fake event
2257 data.unshift( this.fix({ type: type, target: element }) );
2259 // Trigger the event
2260 element["on" + type].apply( element, data );
2264 handle: function(event) {
2265 if ( typeof jQuery == "undefined" ) return false;
2267 event = jQuery.event.fix( event || window.event || {} ); // Empty object is for triggered events with no data
2269 // If no correct event was found, fail
2270 if ( !event ) return false;
2272 var returnValue = true;
2274 var c = this.events[event.type];
2276 var args = [].slice.call( arguments, 1 );
2277 args.unshift( event );
2279 for ( var j in c ) {
2280 if ( c[j].apply( this, args ) === false ) {
2281 event.preventDefault();
2282 event.stopPropagation();
2283 returnValue = false;
2287 // Clean up added properties in IE to prevent memory leak
2288 if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = null;
2293 fix: function(event) {
2295 if(jQuery.browser.msie) {
2296 // fix target property
2297 event.target = event.srcElement;
2299 // check safari and if target is a textnode
2300 } else if(jQuery.browser.safari && event.target.nodeType == 3) {
2301 // target is readonly, clone the event object
2302 event = jQuery.extend({}, event);
2303 // get parentnode from textnode
2304 event.target = event.target.parentNode;
2307 // fix preventDefault and stopPropagation
2308 if (!event.preventDefault)
2309 event.preventDefault = function() {
2310 this.returnValue = false;
2313 if (!event.stopPropagation)
2314 event.stopPropagation = function() {
2315 this.cancelBubble = true;
2324 * Contains flags for the useragent, read from navigator.userAgent.
2325 * Available flags are: safari, opera, msie, mozilla
2326 * This property is available before the DOM is ready, therefore you can
2327 * use it to add ready events only for certain browsers.
2329 * See <a href="http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/">
2330 * jQBrowser plugin</a> for advanced browser detection:
2332 * @example $.browser.msie
2333 * @desc returns true if the current useragent is some version of microsoft's internet explorer
2335 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
2336 * @desc Alerts "this is safari!" only for safari browsers
2343 var b = navigator.userAgent.toLowerCase();
2345 // Figure out what browser is being used
2347 safari: /webkit/.test(b),
2348 opera: /opera/.test(b),
2349 msie: /msie/.test(b) && !/opera/.test(b),
2350 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2353 // Check to see if the W3C box model is being used
2354 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2360 * Append all of the matched elements to another, specified, set of elements.
2361 * This operation is, essentially, the reverse of doing a regular
2362 * $(A).append(B), in that instead of appending B to A, you're appending
2365 * @example $("p").appendTo("#foo");
2366 * @before <p>I would like to say: </p><div id="foo"></div>
2367 * @result <div id="foo"><p>I would like to say: </p></div>
2371 * @param String expr A jQuery expression of elements to match.
2372 * @cat DOM/Manipulation
2377 * Prepend all of the matched elements to another, specified, set of elements.
2378 * This operation is, essentially, the reverse of doing a regular
2379 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2382 * @example $("p").prependTo("#foo");
2383 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2384 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2388 * @param String expr A jQuery expression of elements to match.
2389 * @cat DOM/Manipulation
2391 prependTo: "prepend",
2394 * Insert all of the matched elements before another, specified, set of elements.
2395 * This operation is, essentially, the reverse of doing a regular
2396 * $(A).before(B), in that instead of inserting B before A, you're inserting
2399 * @example $("p").insertBefore("#foo");
2400 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2401 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2403 * @name insertBefore
2405 * @param String expr A jQuery expression of elements to match.
2406 * @cat DOM/Manipulation
2408 insertBefore: "before",
2411 * Insert all of the matched elements after another, specified, set of elements.
2412 * This operation is, essentially, the reverse of doing a regular
2413 * $(A).after(B), in that instead of inserting B after A, you're inserting
2416 * @example $("p").insertAfter("#foo");
2417 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2418 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2422 * @param String expr A jQuery expression of elements to match.
2423 * @cat DOM/Manipulation
2425 insertAfter: "after"
2429 * Get the current CSS width of the first matched element.
2431 * @example $("p").width();
2432 * @before <p>This is just a test.</p>
2441 * Set the CSS width of every matched element. Be sure to include
2442 * the "px" (or other unit of measurement) after the number that you
2443 * specify, otherwise you might get strange results.
2445 * @example $("p").width("20px");
2446 * @before <p>This is just a test.</p>
2447 * @result <p style="width:20px;">This is just a test.</p>
2451 * @param String val Set the CSS property to the specified value.
2456 * Get the current CSS height of the first matched element.
2458 * @example $("p").height();
2459 * @before <p>This is just a test.</p>
2468 * Set the CSS height of every matched element. Be sure to include
2469 * the "px" (or other unit of measurement) after the number that you
2470 * specify, otherwise you might get strange results.
2472 * @example $("p").height("20px");
2473 * @before <p>This is just a test.</p>
2474 * @result <p style="height:20px;">This is just a test.</p>
2478 * @param String val Set the CSS property to the specified value.
2483 * Get the current CSS top of the first matched element.
2485 * @example $("p").top();
2486 * @before <p>This is just a test.</p>
2495 * Set the CSS top of every matched element. Be sure to include
2496 * the "px" (or other unit of measurement) after the number that you
2497 * specify, otherwise you might get strange results.
2499 * @example $("p").top("20px");
2500 * @before <p>This is just a test.</p>
2501 * @result <p style="top:20px;">This is just a test.</p>
2505 * @param String val Set the CSS property to the specified value.
2510 * Get the current CSS left of the first matched element.
2512 * @example $("p").left();
2513 * @before <p>This is just a test.</p>
2522 * Set the CSS left of every matched element. Be sure to include
2523 * the "px" (or other unit of measurement) after the number that you
2524 * specify, otherwise you might get strange results.
2526 * @example $("p").left("20px");
2527 * @before <p>This is just a test.</p>
2528 * @result <p style="left:20px;">This is just a test.</p>
2532 * @param String val Set the CSS property to the specified value.
2537 * Get the current CSS position of the first matched element.
2539 * @example $("p").position();
2540 * @before <p>This is just a test.</p>
2549 * Set the CSS position of every matched element.
2551 * @example $("p").position("relative");
2552 * @before <p>This is just a test.</p>
2553 * @result <p style="position:relative;">This is just a test.</p>
2557 * @param String val Set the CSS property to the specified value.
2562 * Get the current CSS float of the first matched element.
2564 * @example $("p").float();
2565 * @before <p>This is just a test.</p>
2574 * Set the CSS float of every matched element.
2576 * @example $("p").float("left");
2577 * @before <p>This is just a test.</p>
2578 * @result <p style="float:left;">This is just a test.</p>
2582 * @param String val Set the CSS property to the specified value.
2587 * Get the current CSS overflow of the first matched element.
2589 * @example $("p").overflow();
2590 * @before <p>This is just a test.</p>
2599 * Set the CSS overflow of every matched element.
2601 * @example $("p").overflow("auto");
2602 * @before <p>This is just a test.</p>
2603 * @result <p style="overflow:auto;">This is just a test.</p>
2607 * @param String val Set the CSS property to the specified value.
2612 * Get the current CSS color of the first matched element.
2614 * @example $("p").color();
2615 * @before <p>This is just a test.</p>
2624 * Set the CSS color of every matched element.
2626 * @example $("p").color("blue");
2627 * @before <p>This is just a test.</p>
2628 * @result <p style="color:blue;">This is just a test.</p>
2632 * @param String val Set the CSS property to the specified value.
2637 * Get the current CSS background of the first matched element.
2639 * @example $("p").background();
2640 * @before <p style="background:blue;">This is just a test.</p>
2649 * Set the CSS background of every matched element.
2651 * @example $("p").background("blue");
2652 * @before <p>This is just a test.</p>
2653 * @result <p style="background:blue;">This is just a test.</p>
2657 * @param String val Set the CSS property to the specified value.
2661 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2664 * Reduce the set of matched elements to a single element.
2665 * The position of the element in the set of matched elements
2666 * starts at 0 and goes to length - 1.
2668 * @example $("p").eq(1)
2669 * @before <p>This is just a test.</p><p>So is this</p>
2670 * @result [ <p>So is this</p> ]
2674 * @param Number pos The index of the element that you wish to limit to.
2679 * Reduce the set of matched elements to all elements before a given position.
2680 * The position of the element in the set of matched elements
2681 * starts at 0 and goes to length - 1.
2683 * @example $("p").lt(1)
2684 * @before <p>This is just a test.</p><p>So is this</p>
2685 * @result [ <p>This is just a test.</p> ]
2689 * @param Number pos Reduce the set to all elements below this position.
2694 * Reduce the set of matched elements to all elements after a given position.
2695 * The position of the element in the set of matched elements
2696 * starts at 0 and goes to length - 1.
2698 * @example $("p").gt(0)
2699 * @before <p>This is just a test.</p><p>So is this</p>
2700 * @result [ <p>So is this</p> ]
2704 * @param Number pos Reduce the set to all elements after this position.
2709 * Filter the set of elements to those that contain the specified text.
2711 * @example $("p").contains("test")
2712 * @before <p>This is just a test.</p><p>So is this</p>
2713 * @result [ <p>This is just a test.</p> ]
2717 * @param String str The string that will be contained within the text of an element.
2718 * @cat DOM/Traversing
2721 filter: [ "eq", "lt", "gt", "contains" ],
2725 * Get the current value of the first matched element.
2727 * @example $("input").val();
2728 * @before <input type="text" value="some text"/>
2729 * @result "some text"
2731 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2732 * ok( !$("#text1").val() == "", "Check for value of input element" );
2736 * @cat DOM/Attributes
2740 * Set the value of every matched element.
2742 * @example $("input").val("test");
2743 * @before <input type="text" value="some text"/>
2744 * @result <input type="text" value="test"/>
2746 * @test document.getElementById('text1').value = "bla";
2747 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2748 * $("#text1").val('test');
2749 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2753 * @param String val Set the property to the specified value.
2754 * @cat DOM/Attributes
2759 * Get the html contents of the first matched element.
2761 * @example $("div").html();
2762 * @before <div><input/></div>
2767 * @cat DOM/Attributes
2771 * Set the html contents of every matched element.
2773 * @example $("div").html("<b>new stuff</b>");
2774 * @before <div><input/></div>
2775 * @result <div><b>new stuff</b></div>
2777 * @test var div = $("div");
2778 * div.html("<b>test</b>");
2780 * for ( var i = 0; i < div.size(); i++ ) {
2781 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2783 * ok( pass, "Set HTML" );
2787 * @param String val Set the html contents to the specified value.
2788 * @cat DOM/Attributes
2793 * Get the current id of the first matched element.
2795 * @example $("input").id();
2796 * @before <input type="text" id="test" value="some text"/>
2799 * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" );
2800 * ok( $("#foo").id() == "foo", "Check for id" );
2801 * ok( !$("head").id(), "Check for id" );
2805 * @cat DOM/Attributes
2809 * Set the id of every matched element.
2811 * @example $("input").id("newid");
2812 * @before <input type="text" id="test" value="some text"/>
2813 * @result <input type="text" id="newid" value="some text"/>
2817 * @param String val Set the property to the specified value.
2818 * @cat DOM/Attributes
2823 * Get the current title of the first matched element.
2825 * @example $("img").title();
2826 * @before <img src="test.jpg" title="my image"/>
2827 * @result "my image"
2829 * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
2830 * ok( !$("#yahoo").title(), "Check for title" );
2834 * @cat DOM/Attributes
2838 * Set the title of every matched element.
2840 * @example $("img").title("new title");
2841 * @before <img src="test.jpg" title="my image"/>
2842 * @result <img src="test.jpg" title="new image"/>
2846 * @param String val Set the property to the specified value.
2847 * @cat DOM/Attributes
2852 * Get the current name of the first matched element.
2854 * @example $("input").name();
2855 * @before <input type="text" name="username"/>
2856 * @result "username"
2858 * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
2859 * ok( $("#hidden1").name() == "hidden", "Check for name" );
2860 * ok( !$("#area1").name(), "Check for name" );
2864 * @cat DOM/Attributes
2868 * Set the name of every matched element.
2870 * @example $("input").name("user");
2871 * @before <input type="text" name="username"/>
2872 * @result <input type="text" name="user"/>
2876 * @param String val Set the property to the specified value.
2877 * @cat DOM/Attributes
2882 * Get the current href of the first matched element.
2884 * @example $("a").href();
2885 * @before <a href="test.html">my link</a>
2886 * @result "test.html"
2890 * @cat DOM/Attributes
2894 * Set the href of every matched element.
2896 * @example $("a").href("test2.html");
2897 * @before <a href="test.html">my link</a>
2898 * @result <a href="test2.html">my link</a>
2902 * @param String val Set the property to the specified value.
2903 * @cat DOM/Attributes
2908 * Get the current src of the first matched element.
2910 * @example $("img").src();
2911 * @before <img src="test.jpg" title="my image"/>
2912 * @result "test.jpg"
2916 * @cat DOM/Attributes
2920 * Set the src of every matched element.
2922 * @example $("img").src("test2.jpg");
2923 * @before <img src="test.jpg" title="my image"/>
2924 * @result <img src="test2.jpg" title="my image"/>
2928 * @param String val Set the property to the specified value.
2929 * @cat DOM/Attributes
2934 * Get the current rel of the first matched element.
2936 * @example $("a").rel();
2937 * @before <a href="test.html" rel="nofollow">my link</a>
2938 * @result "nofollow"
2942 * @cat DOM/Attributes
2946 * Set the rel of every matched element.
2948 * @example $("a").rel("nofollow");
2949 * @before <a href="test.html">my link</a>
2950 * @result <a href="test.html" rel="nofollow">my link</a>
2954 * @param String val Set the property to the specified value.
2955 * @cat DOM/Attributes
2962 * Get a set of elements containing the unique parents of the matched
2965 * @example $("p").parent()
2966 * @before <div><p>Hello</p><p>Hello</p></div>
2967 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2971 * @cat DOM/Traversing
2975 * Get a set of elements containing the unique parents of the matched
2976 * set of elements, and filtered by an expression.
2978 * @example $("p").parent(".selected")
2979 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2980 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2984 * @param String expr An expression to filter the parents with
2985 * @cat DOM/Traversing
2987 parent: "a.parentNode",
2990 * Get a set of elements containing the unique ancestors of the matched
2991 * set of elements (except for the root element).
2993 * @example $("span").ancestors()
2994 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2995 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2999 * @cat DOM/Traversing
3003 * Get a set of elements containing the unique ancestors of the matched
3004 * set of elements, and filtered by an expression.
3006 * @example $("span").ancestors("p")
3007 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
3008 * @result [ <p><span>Hello</span></p> ]
3012 * @param String expr An expression to filter the ancestors with
3013 * @cat DOM/Traversing
3015 ancestors: jQuery.parents,
3018 * Get a set of elements containing the unique ancestors of the matched
3019 * set of elements (except for the root element).
3021 * @example $("span").ancestors()
3022 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
3023 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
3027 * @cat DOM/Traversing
3031 * Get a set of elements containing the unique ancestors of the matched
3032 * set of elements, and filtered by an expression.
3034 * @example $("span").ancestors("p")
3035 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
3036 * @result [ <p><span>Hello</span></p> ]
3040 * @param String expr An expression to filter the ancestors with
3041 * @cat DOM/Traversing
3043 parents: jQuery.parents,
3046 * Get a set of elements containing the unique next siblings of each of the
3047 * matched set of elements.
3049 * It only returns the very next sibling, not all next siblings.
3051 * @example $("p").next()
3052 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
3053 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
3057 * @cat DOM/Traversing
3061 * Get a set of elements containing the unique next siblings of each of the
3062 * matched set of elements, and filtered by an expression.
3064 * It only returns the very next sibling, not all next siblings.
3066 * @example $("p").next(".selected")
3067 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
3068 * @result [ <p class="selected">Hello Again</p> ]
3072 * @param String expr An expression to filter the next Elements with
3073 * @cat DOM/Traversing
3075 next: "jQuery.sibling(a).next",
3078 * Get a set of elements containing the unique previous siblings of each of the
3079 * matched set of elements.
3081 * It only returns the immediately previous sibling, not all previous siblings.
3083 * @example $("p").prev()
3084 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3085 * @result [ <div><span>Hello Again</span></div> ]
3089 * @cat DOM/Traversing
3093 * Get a set of elements containing the unique previous siblings of each of the
3094 * matched set of elements, and filtered by an expression.
3096 * It only returns the immediately previous sibling, not all previous siblings.
3098 * @example $("p").prev(".selected")
3099 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3100 * @result [ <div><span>Hello</span></div> ]
3104 * @param String expr An expression to filter the previous Elements with
3105 * @cat DOM/Traversing
3107 prev: "jQuery.sibling(a).prev",
3110 * Get a set of elements containing all of the unique siblings of each of the
3111 * matched set of elements.
3113 * @example $("div").siblings()
3114 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3115 * @result [ <p>Hello</p>, <p>And Again</p> ]
3117 * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
3121 * @cat DOM/Traversing
3125 * Get a set of elements containing all of the unique siblings of each of the
3126 * matched set of elements, and filtered by an expression.
3128 * @example $("div").siblings(".selected")
3129 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3130 * @result [ <p class="selected">Hello Again</p> ]
3132 * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
3133 * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
3137 * @param String expr An expression to filter the sibling Elements with
3138 * @cat DOM/Traversing
3140 siblings: "jQuery.sibling(a, null, true)",
3144 * Get a set of elements containing all of the unique children of each of the
3145 * matched set of elements.
3147 * @example $("div").children()
3148 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3149 * @result [ <span>Hello Again</span> ]
3151 * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
3155 * @cat DOM/Traversing
3159 * Get a set of elements containing all of the unique children of each of the
3160 * matched set of elements, and filtered by an expression.
3162 * @example $("div").children(".selected")
3163 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
3164 * @result [ <p class="selected">Hello Again</p> ]
3166 * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
3170 * @param String expr An expression to filter the child Elements with
3171 * @cat DOM/Traversing
3173 children: "jQuery.sibling(a.firstChild)"
3179 * Remove an attribute from each of the matched elements.
3181 * @example $("input").removeAttr("disabled")
3182 * @before <input disabled="disabled"/>
3187 * @param String name The name of the attribute to remove.
3190 removeAttr: function( key ) {
3191 this.removeAttribute( key );
3195 * Displays each of the set of matched elements if they are hidden.
3197 * @example $("p").show()
3198 * @before <p style="display: none">Hello</p>
3199 * @result [ <p style="display: block">Hello</p> ]
3201 * @test var pass = true, div = $("div");
3202 * div.show().each(function(){
3203 * if ( this.style.display == "none" ) pass = false;
3205 * ok( pass, "Show" );
3212 this.style.display = this.oldblock ? this.oldblock : "";
3213 if ( jQuery.css(this,"display") == "none" )
3214 this.style.display = "block";
3218 * Hides each of the set of matched elements if they are shown.
3220 * @example $("p").hide()
3221 * @before <p>Hello</p>
3222 * @result [ <p style="display: none">Hello</p> ]
3224 * var pass = true, div = $("div");
3225 * div.hide().each(function(){
3226 * if ( this.style.display != "none" ) pass = false;
3228 * ok( pass, "Hide" );
3235 this.oldblock = this.oldblock || jQuery.css(this,"display");
3236 if ( this.oldblock == "none" )
3237 this.oldblock = "block";
3238 this.style.display = "none";
3242 * Toggles each of the set of matched elements. If they are shown,
3243 * toggle makes them hidden. If they are hidden, toggle
3246 * @example $("p").toggle()
3247 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3248 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3255 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3259 * Adds the specified class to each of the set of matched elements.
3261 * @example $("p").addClass("selected")
3262 * @before <p>Hello</p>
3263 * @result [ <p class="selected">Hello</p> ]
3265 * @test var div = $("div");
3266 * div.addClass("test");
3268 * for ( var i = 0; i < div.size(); i++ ) {
3269 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
3271 * ok( pass, "Add Class" );
3275 * @param String class A CSS class to add to the elements
3278 addClass: function(c){
3279 jQuery.className.add(this,c);
3283 * Removes the specified class from the set of matched elements.
3285 * @example $("p").removeClass("selected")
3286 * @before <p class="selected">Hello</p>
3287 * @result [ <p>Hello</p> ]
3289 * @test var div = $("div").addClass("test");
3290 * div.removeClass("test");
3292 * for ( var i = 0; i < div.size(); i++ ) {
3293 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3295 * ok( pass, "Remove Class" );
3299 * var div = $("div").addClass("test").addClass("foo").addClass("bar");
3300 * div.removeClass("test").removeClass("bar").removeClass("foo");
3302 * for ( var i = 0; i < div.size(); i++ ) {
3303 * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
3305 * ok( pass, "Remove multiple classes" );
3309 * @param String class A CSS class to remove from the elements
3312 removeClass: function(c){
3313 jQuery.className.remove(this,c);
3317 * Adds the specified class if it is not present, removes it if it is
3320 * @example $("p").toggleClass("selected")
3321 * @before <p>Hello</p><p class="selected">Hello Again</p>
3322 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3326 * @param String class A CSS class with which to toggle the elements
3329 toggleClass: function( c ){
3330 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3334 * Removes all matched elements from the DOM. This does NOT remove them from the
3335 * jQuery object, allowing you to use the matched elements further.
3337 * @example $("p").remove();
3338 * @before <p>Hello</p> how are <p>you?</p>
3343 * @cat DOM/Manipulation
3347 * Removes only elements (out of the list of matched elements) that match
3348 * the specified jQuery expression. This does NOT remove them from the
3349 * jQuery object, allowing you to use the matched elements further.
3351 * @example $("p").remove(".hello");
3352 * @before <p class="hello">Hello</p> how are <p>you?</p>
3353 * @result how are <p>you?</p>
3357 * @param String expr A jQuery expression to filter elements by.
3358 * @cat DOM/Manipulation
3360 remove: function(a){
3361 if ( !a || jQuery.filter( a, [this] ).r )
3362 this.parentNode.removeChild( this );
3366 * Removes all child nodes from the set of matched elements.
3368 * @example $("p").empty()
3369 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3370 * @result [ <p></p> ]
3374 * @cat DOM/Manipulation
3377 while ( this.firstChild )
3378 this.removeChild( this.firstChild );
3382 * Binds a handler to a particular event (like click) for each matched element.
3383 * The event handler is passed an event object that you can use to prevent
3384 * default behaviour. To stop both default action and event bubbling, your handler
3385 * has to return false.
3387 * @example $("p").bind( "click", function() {
3388 * alert( $(this).text() );
3390 * @before <p>Hello</p>
3391 * @result alert("Hello")
3393 * @example $("form").bind( "submit", function() { return false; } )
3394 * @desc Cancel a default action and prevent it from bubbling by returning false
3395 * from your function.
3397 * @example $("form").bind( "submit", function(event) {
3398 * event.preventDefault();
3400 * @desc Cancel only the default action by using the preventDefault method.
3403 * @example $("form").bind( "submit", function(event) {
3404 * event.stopPropagation();
3406 * @desc Stop only an event from bubbling by using the stopPropagation method.
3410 * @param String type An event type
3411 * @param Function fn A function to bind to the event on each of the set of matched elements
3414 bind: function( type, fn ) {
3415 if ( fn.constructor == String )
3416 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3417 jQuery.event.add( this, type, fn );
3421 * The opposite of bind, removes a bound event from each of the matched
3422 * elements. You must pass the identical function that was used in the original
3425 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3426 * @before <p onclick="alert('Hello');">Hello</p>
3427 * @result [ <p>Hello</p> ]
3431 * @param String type An event type
3432 * @param Function fn A function to unbind from the event on each of the set of matched elements
3437 * Removes all bound events of a particular type from each of the matched
3440 * @example $("p").unbind( "click" )
3441 * @before <p onclick="alert('Hello');">Hello</p>
3442 * @result [ <p>Hello</p> ]
3446 * @param String type An event type
3451 * Removes all bound events from each of the matched elements.
3453 * @example $("p").unbind()
3454 * @before <p onclick="alert('Hello');">Hello</p>
3455 * @result [ <p>Hello</p> ]
3461 unbind: function( type, fn ) {
3462 jQuery.event.remove( this, type, fn );
3466 * Trigger a type of event on every matched element.
3468 * @example $("p").trigger("click")
3469 * @before <p click="alert('hello')">Hello</p>
3470 * @result alert('hello')
3474 * @param String type An event type to trigger.
3477 trigger: function( type, data ) {
3478 jQuery.event.trigger( type, data, this );