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 )
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.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' );
454 * $.get('data/dashboard.xml', function(xml) {
456 * $('tab', xml).each(function() {
457 * titles.push($(this).attr('title'));
459 * ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
460 * ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
466 * @param String key The name of the property to set.
467 * @param Object value The value to set the property to.
470 attr: function( key, value, type ) {
471 // Check to see if we're setting style values
472 return key.constructor != String || value != undefined ?
473 this.each(function(){
474 // See if we're setting a hash of styles
475 if ( value == undefined )
476 // Set all the styles
477 for ( var prop in key )
479 type ? this.style : this,
483 // See if we're setting a single key/value style
486 type ? this.style : this,
491 // Look for the case where we're accessing a style value
492 jQuery[ type || "attr" ]( this[0], key );
496 * Access a style property on the first matched element.
497 * This method makes it easy to retrieve a style property value
498 * from the first matched element.
500 * @example $("p").css("color");
501 * @before <p style="color:red;">Test Paragraph.</p>
503 * @desc Retrieves the color style of the first paragraph
505 * @example $("p").css("fontWeight");
506 * @before <p style="font-weight: bold;">Test Paragraph.</p>
508 * @desc Retrieves the font-weight style of the first paragraph.
509 * Note that for all style properties with a dash (like 'font-weight'), you have to
510 * write it in camelCase. In other words: Every time you have a '-' in a
511 * property, remove it and replace the next character with an uppercase
512 * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
513 * borderStyle, borderBottomWidth etc.
515 * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"');
519 * @param String name The name of the property to access.
524 * Set a hash of key/value style properties to all matched elements.
525 * This serves as the best way to set a large number of style properties
526 * on all matched elements.
528 * @example $("p").css({ color: "red", background: "blue" });
529 * @before <p>Test Paragraph.</p>
530 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
532 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
533 * $('#foo').css({display: 'none'});
534 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
535 * $('#foo').css({display: 'block'});
536 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
537 * $('#floatTest').css({styleFloat: 'right'});
538 * ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
539 * $('#floatTest').css({cssFloat: 'left'});
540 * ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
541 * $('#floatTest').css({'float': 'right'});
542 * ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
543 * $('#floatTest').css({'font-size': '30px'});
544 * ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
548 * @param Hash prop A set of key/value pairs to set as style properties.
553 * Set a single style property to a value, on all matched elements.
555 * @example $("p").css("color","red");
556 * @before <p>Test Paragraph.</p>
557 * @result <p style="color:red;">Test Paragraph.</p>
558 * @desc Changes the color of all paragraphs to red
561 * @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
562 * $('#foo').css('display', 'none');
563 * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
564 * $('#foo').css('display', 'block');
565 * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
566 * $('#floatTest').css('styleFloat', 'left');
567 * ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
568 * $('#floatTest').css('cssFloat', 'right');
569 * ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
570 * $('#floatTest').css('float', 'left');
571 * ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
572 * $('#floatTest').css('font-size', '20px');
573 * ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
577 * @param String key The name of the property to set.
578 * @param Object value The value to set the property to.
581 css: function( key, value ) {
582 return this.attr( key, value, "curCSS" );
586 * Retrieve the text contents of all matched elements. The result is
587 * a string that contains the combined text contents of all matched
588 * elements. This method works on both HTML and XML documents.
590 * @example $("p").text();
591 * @before <p>Test Paragraph.</p>
592 * @result Test Paragraph.
594 * @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
595 * ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
604 for ( var j = 0; j < e.length; j++ ) {
605 var r = e[j].childNodes;
606 for ( var i = 0; i < r.length; i++ )
607 if ( r[i].nodeType != 8 )
608 t += r[i].nodeType != 1 ?
609 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
615 * Wrap all matched elements with a structure of other elements.
616 * This wrapping process is most useful for injecting additional
617 * stucture into a document, without ruining the original semantic
618 * qualities of a document.
620 * This works by going through the first element
621 * provided (which is generated, on the fly, from the provided HTML)
622 * and finds the deepest ancestor element within its
623 * structure - it is that element that will en-wrap everything else.
625 * This does not work with elements that contain text. Any necessary text
626 * must be added after the wrapping is done.
628 * @example $("p").wrap("<div class='wrap'></div>");
629 * @before <p>Test Paragraph.</p>
630 * @result <div class='wrap'><p>Test Paragraph.</p></div>
632 * @test var defaultText = 'Try them out:'
633 * var result = $('#first').wrap('<div class="red"><span></span></div>').text();
634 * ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
635 * ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
639 * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
640 * @cat DOM/Manipulation
644 * Wrap all matched elements with a structure of other elements.
645 * This wrapping process is most useful for injecting additional
646 * stucture into a document, without ruining the original semantic
647 * qualities of a document.
649 * This works by going through the first element
650 * provided and finding the deepest ancestor element within its
651 * structure - it is that element that will en-wrap everything else.
653 * This does not work with elements that contain text. Any necessary text
654 * must be added after the wrapping is done.
656 * @example $("p").wrap( document.getElementById('content') );
657 * @before <p>Test Paragraph.</p><div id="content"></div>
658 * @result <div id="content"><p>Test Paragraph.</p></div>
660 * @test var defaultText = 'Try them out:'
661 * var result = $('#first').wrap(document.getElementById('empty')).parent();
662 * ok( result.is('ol'), 'Check for element wrapping' );
663 * ok( result.text() == defaultText, 'Check for element wrapping' );
667 * @param Element elem A DOM element that will be wrapped.
668 * @cat DOM/Manipulation
671 // The elements to wrap the target around
672 var a = jQuery.clean(arguments);
674 // Wrap each of the matched elements individually
675 return this.each(function(){
676 // Clone the structure that we're using to wrap
677 var b = a[0].cloneNode(true);
679 // Insert it before the element to be wrapped
680 this.parentNode.insertBefore( b, this );
682 // Find the deepest point in the wrap structure
683 while ( b.firstChild )
686 // Move the matched element to within the wrap structure
687 b.appendChild( this );
692 * Append any number of elements to the inside of every matched elements,
693 * generated from the provided HTML.
694 * This operation is similar to doing an appendChild to all the
695 * specified elements, adding them into the document.
697 * @example $("p").append("<b>Hello</b>");
698 * @before <p>I would like to say: </p>
699 * @result <p>I would like to say: <b>Hello</b></p>
701 * @test var defaultText = 'Try them out:'
702 * var result = $('#first').append('<b>buga</b>');
703 * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
704 * ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
708 * @param String html A string of HTML, that will be created on the fly and appended to the target.
709 * @cat DOM/Manipulation
713 * Append an element to the inside of all matched elements.
714 * This operation is similar to doing an appendChild to all the
715 * specified elements, adding them into the document.
717 * @example $("p").append( $("#foo")[0] );
718 * @before <p>I would like to say: </p><b id="foo">Hello</b>
719 * @result <p>I would like to say: <b id="foo">Hello</b></p>
721 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
722 * $('#sap').append(document.getElementById('first'));
723 * ok( expected == $('#sap').text(), "Check for appending of element" );
727 * @param Element elem A DOM element that will be appended.
728 * @cat DOM/Manipulation
732 * Append any number of elements to the inside of all matched elements.
733 * This operation is similar to doing an appendChild to all the
734 * specified elements, adding them into the document.
736 * @example $("p").append( $("b") );
737 * @before <p>I would like to say: </p><b>Hello</b>
738 * @result <p>I would like to say: <b>Hello</b></p>
740 * @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
741 * $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
742 * ok( expected == $('#sap').text(), "Check for appending of array of elements" );
746 * @param Array<Element> elems An array of elements, all of which will be appended.
747 * @cat DOM/Manipulation
750 return this.domManip(arguments, true, 1, function(a){
751 this.appendChild( a );
756 * Prepend any number of elements to the inside of every matched elements,
757 * generated from the provided HTML.
758 * This operation is the best way to insert dynamically created elements
759 * inside, at the beginning, of all the matched element.
761 * @example $("p").prepend("<b>Hello</b>");
762 * @before <p>I would like to say: </p>
763 * @result <p><b>Hello</b>I would like to say: </p>
765 * @test var defaultText = 'Try them out:'
766 * var result = $('#first').prepend('<b>buga</b>');
767 * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
768 * ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
772 * @param String html A string of HTML, that will be created on the fly and appended to the target.
773 * @cat DOM/Manipulation
777 * Prepend an element to the inside of all matched elements.
778 * This operation is the best way to insert an element inside, at the
779 * beginning, of all the matched element.
781 * @example $("p").prepend( $("#foo")[0] );
782 * @before <p>I would like to say: </p><b id="foo">Hello</b>
783 * @result <p><b id="foo">Hello</b>I would like to say: </p>
785 * @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
786 * $('#sap').prepend(document.getElementById('first'));
787 * ok( expected == $('#sap').text(), "Check for prepending of element" );
791 * @param Element elem A DOM element that will be appended.
792 * @cat DOM/Manipulation
796 * Prepend any number of elements to the inside of all matched elements.
797 * This operation is the best way to insert a set of elements inside, at the
798 * beginning, of all the matched element.
800 * @example $("p").prepend( $("b") );
801 * @before <p>I would like to say: </p><b>Hello</b>
802 * @result <p><b>Hello</b>I would like to say: </p>
804 * @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
805 * $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
806 * ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
810 * @param Array<Element> elems An array of elements, all of which will be appended.
811 * @cat DOM/Manipulation
813 prepend: function() {
814 return this.domManip(arguments, true, -1, function(a){
815 this.insertBefore( a, this.firstChild );
820 * Insert any number of dynamically generated elements before each of the
823 * @example $("p").before("<b>Hello</b>");
824 * @before <p>I would like to say: </p>
825 * @result <b>Hello</b><p>I would like to say: </p>
827 * @test var expected = 'This is a normal link: bugaYahoo';
828 * $('#yahoo').before('<b>buga</b>');
829 * ok( expected == $('#en').text(), 'Insert String before' );
833 * @param String html A string of HTML, that will be created on the fly and appended to the target.
834 * @cat DOM/Manipulation
838 * Insert an element before each of the matched elements.
840 * @example $("p").before( $("#foo")[0] );
841 * @before <p>I would like to say: </p><b id="foo">Hello</b>
842 * @result <b id="foo">Hello</b><p>I would like to say: </p>
844 * @test var expected = "This is a normal link: Try them out:Yahoo";
845 * $('#yahoo').before(document.getElementById('first'));
846 * ok( expected == $('#en').text(), "Insert element before" );
850 * @param Element elem A DOM element that will be appended.
851 * @cat DOM/Manipulation
855 * Insert any number of elements before each of the matched elements.
857 * @example $("p").before( $("b") );
858 * @before <p>I would like to say: </p><b>Hello</b>
859 * @result <b>Hello</b><p>I would like to say: </p>
861 * @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
862 * $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
863 * ok( expected == $('#en').text(), "Insert array of elements before" );
867 * @param Array<Element> elems An array of elements, all of which will be appended.
868 * @cat DOM/Manipulation
871 return this.domManip(arguments, false, 1, function(a){
872 this.parentNode.insertBefore( a, this );
877 * Insert any number of dynamically generated elements after each of the
880 * @example $("p").after("<b>Hello</b>");
881 * @before <p>I would like to say: </p>
882 * @result <p>I would like to say: </p><b>Hello</b>
884 * @test var expected = 'This is a normal link: Yahoobuga';
885 * $('#yahoo').after('<b>buga</b>');
886 * ok( expected == $('#en').text(), 'Insert String after' );
890 * @param String html A string of HTML, that will be created on the fly and appended to the target.
891 * @cat DOM/Manipulation
895 * Insert an element after each of the matched elements.
897 * @example $("p").after( $("#foo")[0] );
898 * @before <b id="foo">Hello</b><p>I would like to say: </p>
899 * @result <p>I would like to say: </p><b id="foo">Hello</b>
901 * @test var expected = "This is a normal link: YahooTry them out:";
902 * $('#yahoo').after(document.getElementById('first'));
903 * ok( expected == $('#en').text(), "Insert element after" );
907 * @param Element elem A DOM element that will be appended.
908 * @cat DOM/Manipulation
912 * Insert any number of elements after each of the matched elements.
914 * @example $("p").after( $("b") );
915 * @before <b>Hello</b><p>I would like to say: </p>
916 * @result <p>I would like to say: </p><b>Hello</b>
918 * @test var expected = "This is a normal link: YahooTry them out:diveintomark";
919 * $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
920 * ok( expected == $('#en').text(), "Insert array of elements after" );
924 * @param Array<Element> elems An array of elements, all of which will be appended.
925 * @cat DOM/Manipulation
928 return this.domManip(arguments, false, -1, function(a){
929 this.parentNode.insertBefore( a, this.nextSibling );
934 * End the most recent 'destructive' operation, reverting the list of matched elements
935 * back to its previous state. After an end operation, the list of matched elements will
936 * revert to the last state of matched elements.
938 * @example $("p").find("span").end();
939 * @before <p><span>Hello</span>, how are you?</p>
940 * @result $("p").find("span").end() == [ <p>...</p> ]
942 * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
946 * @cat DOM/Traversing
949 return this.get( this.stack.pop() );
953 * Searches for all elements that match the specified expression.
954 * This method is the optimal way of finding additional descendant
955 * elements with which to process.
957 * All searching is done using a jQuery expression. The expression can be
958 * written using CSS 1-3 Selector syntax, or basic XPath.
960 * @example $("p").find("span");
961 * @before <p><span>Hello</span>, how are you?</p>
962 * @result $("p").find("span") == [ <span>Hello</span> ]
964 * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
968 * @param String expr An expression to search with.
969 * @cat DOM/Traversing
972 return this.pushStack( jQuery.map( this, function(a){
973 return jQuery.find(t,a);
978 * Create cloned copies of all matched DOM Elements. This does
979 * not create a cloned copy of this particular jQuery object,
980 * instead it creates duplicate copies of all DOM Elements.
981 * This is useful for moving copies of the elements to another
982 * location in the DOM.
984 * @example $("b").clone().prependTo("p");
985 * @before <b>Hello</b><p>, how are you?</p>
986 * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
988 * @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
989 * var clone = $('#yahoo').clone();
990 * ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
991 * ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
995 * @cat DOM/Manipulation
997 clone: function(deep) {
998 return this.pushStack( jQuery.map( this, function(a){
999 return a.cloneNode( deep != undefined ? deep : true );
1004 * Removes all elements from the set of matched elements that do not
1005 * match the specified expression. This method is used to narrow down
1006 * the results of a search.
1008 * All searching is done using a jQuery expression. The expression
1009 * can be written using CSS 1-3 Selector syntax, or basic XPath.
1011 * @example $("p").filter(".selected")
1012 * @before <p class="selected">Hello</p><p>How are you?</p>
1013 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
1015 * @test isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "Filter elements" );
1016 * @test $("input").filter(":checked",function(i){
1017 * ok( this == q("radio2", "check1")[i], "Filter elements, context" );
1019 * @test $("#main > p#ap > a").filter("#foobar",function(){},function(i){
1020 * ok( this == q("google","groups", "mark")[i], "Filter elements, else context" );
1025 * @param String expr An expression to search with.
1026 * @cat DOM/Traversing
1030 * Removes all elements from the set of matched elements that do not
1031 * match at least one of the expressions passed to the function. This
1032 * method is used when you want to filter the set of matched elements
1033 * through more than one expression.
1035 * Elements will be retained in the jQuery object if they match at
1036 * least one of the expressions passed.
1038 * @example $("p").filter([".selected", ":first"])
1039 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
1040 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
1044 * @param Array<String> exprs A set of expressions to evaluate against
1045 * @cat DOM/Traversing
1047 filter: function(t) {
1048 return this.pushStack(
1049 t.constructor == Array &&
1050 jQuery.map(this,function(a){
1051 for ( var i = 0; i < t.length; i++ )
1052 if ( jQuery.filter(t[i],[a]).r.length )
1057 t.constructor == Boolean &&
1058 ( t ? this.get() : [] ) ||
1060 typeof t == "function" &&
1061 jQuery.grep( this, t ) ||
1063 jQuery.filter(t,this).r, arguments );
1067 * Removes the specified Element from the set of matched elements. This
1068 * method is used to remove a single Element from a jQuery object.
1070 * @example $("p").not( document.getElementById("selected") )
1071 * @before <p>Hello</p><p id="selected">Hello Again</p>
1072 * @result [ <p>Hello</p> ]
1076 * @param Element el An element to remove from the set
1077 * @cat DOM/Traversing
1081 * Removes elements matching the specified expression from the set
1082 * of matched elements. This method is used to remove one or more
1083 * elements from a jQuery object.
1085 * @example $("p").not("#selected")
1086 * @before <p>Hello</p><p id="selected">Hello Again</p>
1087 * @result [ <p>Hello</p> ]
1089 * @test ok($("#main > p#ap > a").not("#google").length == 2, ".not")
1093 * @param String expr An expression with which to remove matching elements
1094 * @cat DOM/Traversing
1097 return this.pushStack( t.constructor == String ?
1098 jQuery.filter(t,this,false).r :
1099 jQuery.grep(this,function(a){ return a != t; }), arguments );
1103 * Adds the elements matched by the expression to the jQuery object. This
1104 * can be used to concatenate the result sets of two expressions.
1106 * @example $("p").add("span")
1107 * @before <p>Hello</p><p><span>Hello Again</span></p>
1108 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
1112 * @param String expr An expression whose matched elements are added
1113 * @cat DOM/Traversing
1117 * Adds each of the Elements in the array to the set of matched elements.
1118 * This is used to add a set of Elements to a jQuery object.
1120 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
1121 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
1122 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
1126 * @param Array<Element> els An array of Elements to add
1127 * @cat DOM/Traversing
1131 * Adds a single Element to the set of matched elements. This is used to
1132 * add a single Element to a jQuery object.
1134 * @example $("p").add( document.getElementById("a") )
1135 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
1136 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
1140 * @param Element el An Element to add
1141 * @cat DOM/Traversing
1144 return this.pushStack( jQuery.merge( this, t.constructor == String ?
1145 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
1149 * Checks the current selection against an expression and returns true,
1150 * if the selection fits the given expression. Does return false, if the
1151 * selection does not fit or the expression is not valid.
1153 * @example $("input[@type='checkbox']").parent().is("form")
1154 * @before <form><input type="checkbox" /></form>
1156 * @desc Returns true, because the parent of the input is a form element
1158 * @example $("input[@type='checkbox']").parent().is("form")
1159 * @before <form><p><input type="checkbox" /></p></form>
1161 * @desc Returns false, because the parent of the input is a p element
1163 * @example $("form").is(null)
1164 * @before <form></form>
1166 * @desc An invalid expression always returns false.
1168 * @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1169 * ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1170 * ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1171 * ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1172 * ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1173 * ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1174 * ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1175 * ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1176 * ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1177 * ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1178 * ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1179 * ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1180 * ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1181 * ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1182 * ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
1183 * ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
1184 * ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1185 * ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1186 * ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1187 * ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1188 * ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1189 * ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1193 * @param String expr The expression with which to filter
1194 * @cat DOM/Traversing
1196 is: function(expr) {
1197 return expr ? jQuery.filter(expr,this).r.length > 0 : false;
1206 * @param Boolean table
1208 * @param Function fn The function doing the DOM manipulation.
1212 domManip: function(args, table, dir, fn){
1213 var clone = this.size() > 1;
1214 var a = jQuery.clean(args);
1216 return this.each(function(){
1219 if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() != "THEAD" ) {
1220 var tbody = this.getElementsByTagName("tbody");
1222 if ( !tbody.length ) {
1223 obj = document.createElement("tbody");
1224 this.appendChild( obj );
1229 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
1230 i != ( dir < 0 ? dir : a.length ); i += dir ) {
1231 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
1246 pushStack: function(a,args) {
1247 var fn = args && args[args.length-1];
1248 var fn2 = args && args[args.length-2];
1250 if ( fn && fn.constructor != Function ) fn = null;
1251 if ( fn2 && fn2.constructor != Function ) fn2 = null;
1254 if ( !this.stack ) this.stack = [];
1255 this.stack.push( this.get() );
1258 var old = this.get();
1261 if ( fn2 && a.length || !fn2 )
1262 this.each( fn2 || fn ).get( old );
1264 this.get( old ).each( fn );
1272 * Extends the jQuery object itself. Can be used to add both static
1273 * functions and plugin methods.
1275 * @example $.fn.extend({
1276 * check: function() {
1277 * this.each(function() { this.checked = true; });
1279 * uncheck: function() {
1280 * this.each(function() { this.checked = false; });
1283 * $("input[@type=checkbox]").check();
1284 * $("input[@type=radio]").uncheck();
1285 * @desc Adds two plugin methods.
1295 * Extend one object with another, returning the original,
1296 * modified, object. This is a great utility for simple inheritance.
1298 * @example var settings = { validate: false, limit: 5, name: "foo" };
1299 * var options = { validate: true, name: "bar" };
1300 * jQuery.extend(settings, options);
1301 * @result settings == { validate: true, limit: 5, name: "bar" }
1303 * @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
1304 * var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1305 * var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
1306 * var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
1307 * jQuery.extend(settings, options);
1308 * isSet( settings, merged, "Check if extended: settings must be extended" );
1309 * isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
1312 * @param Object obj The object to extend
1313 * @param Object prop The object that will be merged into the first.
1317 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
1318 // Watch for the case where null or undefined gets passed in by accident
1319 if ( arguments.length > 1 && (prop === null || prop == undefined) )
1322 // If no property object was provided, then we're extending jQuery
1323 if ( !prop ) { prop = obj; obj = this; }
1325 // Extend the base object
1326 for ( var i in prop ) obj[i] = prop[i];
1328 // Return the modified object
1340 jQuery.initDone = true;
1342 jQuery.each( jQuery.macros.axis, function(i,n){
1343 jQuery.fn[ i ] = function(a) {
1344 var ret = jQuery.map(this,n);
1345 if ( a && a.constructor == String )
1346 ret = jQuery.filter(a,ret).r;
1347 return this.pushStack( ret, arguments );
1351 jQuery.each( jQuery.macros.to, function(i,n){
1352 jQuery.fn[ i ] = function(){
1354 return this.each(function(){
1355 for ( var j = 0; j < a.length; j++ )
1356 jQuery(a[j])[n]( this );
1361 jQuery.each( jQuery.macros.each, function(i,n){
1362 jQuery.fn[ i ] = function() {
1363 return this.each( n, arguments );
1367 jQuery.each( jQuery.macros.filter, function(i,n){
1368 jQuery.fn[ n ] = function(num,fn) {
1369 return this.filter( ":" + n + "(" + num + ")", fn );
1373 jQuery.each( jQuery.macros.attr, function(i,n){
1375 jQuery.fn[ i ] = function(h) {
1376 return h == undefined ?
1377 this.length ? this[0][n] : null :
1382 jQuery.each( jQuery.macros.css, function(i,n){
1383 jQuery.fn[ n ] = function(h) {
1384 return h == undefined ?
1385 ( this.length ? jQuery.css( this[0], n ) : null ) :
1393 * A generic iterator function, which can be used to seemlessly
1394 * iterate over both objects and arrays. This function is not the same
1395 * as $().each() - which is used to iterate, exclusively, over a jQuery
1396 * object. This function can be used to iterate over anything.
1398 * @example $.each( [0,1,2], function(i){
1399 * alert( "Item #" + i + ": " + this );
1401 * @desc This is an example of iterating over the items in an array, accessing both the current item and its index.
1403 * @example $.each( { name: "John", lang: "JS" }, function(i){
1404 * alert( "Name: " + i + ", Value: " + this );
1406 * @desc This is an example of iterating over the properties in an Object, accessing both the current item and its key.
1409 * @param Object obj The object, or array, to iterate over.
1410 * @param Function fn The function that will be executed on every object.
1414 each: function( obj, fn, args ) {
1415 if ( obj.length == undefined )
1416 for ( var i in obj )
1417 fn.apply( obj[i], args || [i, obj[i]] );
1419 for ( var i = 0; i < obj.length; i++ )
1420 if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
1426 if (jQuery.className.has(o,c)) return;
1427 o.className += ( o.className ? " " : "" ) + c;
1429 remove: function(o,c){
1433 var classes = o.className.split(" ");
1434 for(var i=0; i<classes.length; i++) {
1435 if(classes[i] == c) {
1436 classes.splice(i, 1);
1440 o.className = classes.join(' ');
1443 has: function(e,a) {
1444 if ( e.className != undefined )
1446 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
1451 * Swap in/out style options.
1454 swap: function(e,o,f) {
1455 for ( var i in o ) {
1456 e.style["old"+i] = e.style[i];
1461 e.style[i] = e.style["old"+i];
1464 css: function(e,p) {
1465 if ( p == "height" || p == "width" ) {
1466 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
1468 for ( var i in d ) {
1469 old["padding" + d[i]] = 0;
1470 old["border" + d[i] + "Width"] = 0;
1473 jQuery.swap( e, old, function() {
1474 if (jQuery.css(e,"display") != "none") {
1475 oHeight = e.offsetHeight;
1476 oWidth = e.offsetWidth;
1478 e = jQuery(e.cloneNode(true)).css({
1479 visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
1480 }).appendTo(e.parentNode)[0];
1482 var parPos = jQuery.css(e.parentNode,"position");
1483 if ( parPos == "" || parPos == "static" )
1484 e.parentNode.style.position = "relative";
1486 oHeight = e.clientHeight;
1487 oWidth = e.clientWidth;
1489 if ( parPos == "" || parPos == "static" )
1490 e.parentNode.style.position = "static";
1492 e.parentNode.removeChild(e);
1496 return p == "height" ? oHeight : oWidth;
1499 return jQuery.curCSS( e, p );
1502 curCSS: function(elem, prop, force) {
1505 if (prop == 'opacity' && jQuery.browser.msie)
1506 return jQuery.attr(elem.style, 'opacity');
1508 if (prop == "float" || prop == "cssFloat")
1509 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
1511 if (!force && elem.style[prop]) {
1513 ret = elem.style[prop];
1515 } else if (elem.currentStyle) {
1517 var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
1518 ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
1520 } else if (document.defaultView && document.defaultView.getComputedStyle) {
1522 if (prop == "cssFloat" || prop == "styleFloat")
1525 prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
1526 var cur = document.defaultView.getComputedStyle(elem, null);
1529 ret = cur.getPropertyValue(prop);
1530 else if ( prop == 'display' )
1533 jQuery.swap(elem, { display: 'block' }, function() {
1534 ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
1542 clean: function(a) {
1544 for ( var i = 0; i < a.length; i++ ) {
1545 if ( a[i].constructor == String ) {
1546 // trim whitespace, otherwise indexOf won't work as expected
1547 a[i] = jQuery.trim(a[i]);
1551 if ( !a[i].indexOf("<opt") ) {
1553 a[i] = "<select>" + a[i] + "</select>";
1554 } else if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
1556 a[i] = "<table>" + a[i] + "</table>";
1557 } else if ( !a[i].indexOf("<tr") ) {
1559 a[i] = "<table>" + a[i] + "</table>";
1560 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
1562 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
1565 var div = document.createElement("div");
1566 div.innerHTML = a[i];
1569 div = div.firstChild;
1570 if ( table != "thead" ) div = div.firstChild;
1571 if ( table == "td" ) div = div.firstChild;
1574 for ( var j = 0; j < div.childNodes.length; j++ )
1575 r.push( div.childNodes[j] );
1576 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
1577 for ( var k = 0; k < a[i].length; k++ )
1579 else if ( a[i] !== null )
1580 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].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",
1652 var s = jQuery.sibling(a);
1654 for ( var i = s.n; i < s.length; i++ )
1662 * @test t( "Element Selector", "div", ["main","foo"] );
1663 * t( "Element Selector", "body", ["body"] );
1664 * t( "Element Selector", "html", ["html"] );
1665 * ok( $("*").size() >= 30, "Element Selector" );
1666 * t( "Parent Element", "div div", ["foo"] );
1668 * t( "ID Selector", "#body", ["body"] );
1669 * t( "ID Selector w/ Element", "body#body", ["body"] );
1670 * t( "ID Selector w/ Element", "ul#first", [] );
1672 * t( "Class Selector", ".blog", ["mark","simon"] );
1673 * t( "Class Selector", ".blog.link", ["simon"] );
1674 * t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
1675 * t( "Parent Class Selector", "p .blog", ["mark","simon"] );
1677 * t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
1678 * t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
1679 * t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
1680 * t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
1682 * t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
1683 * t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
1684 * t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
1685 * t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
1686 * t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
1687 * t( "All Children", "code > *", ["anchor1","anchor2"] );
1688 * t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
1689 * t( "Adjacent", "a + a", ["groups"] );
1690 * t( "Adjacent", "a +a", ["groups"] );
1691 * t( "Adjacent", "a+ a", ["groups"] );
1692 * t( "Adjacent", "a+a", ["groups"] );
1693 * t( "Adjacent", "p + p", ["ap","en","sap"] );
1694 * t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
1695 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1696 * t( "Attribute Exists", "a[@title]", ["google"] );
1697 * t( "Attribute Exists", "*[@title]", ["google"] );
1698 * t( "Attribute Exists", "[@title]", ["google"] );
1700 * t( "Non-existing part of attribute", "[@name*=bla]", [] );
1701 * t( "Non-existing start of attribute", "[@name^=bla]", [] );
1702 * t( "Non-existing end of attribute", "[@name$=bla]", [] );
1704 * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
1705 * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
1706 * t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
1707 * t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
1708 * t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
1709 * t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
1711 * t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
1712 * t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
1713 * t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
1714 * t( "First Child", "p:first-child", ["firstp","sndp"] );
1715 * t( "Last Child", "p:last-child", ["sap"] );
1716 * t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
1717 * t( "Empty", "ul:empty", ["firstUL"] );
1718 * t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
1719 * t( "Disabled UI Element", "input:disabled", ["text2"] );
1720 * t( "Checked UI Element", "input:checked", ["radio2","check1"] );
1721 * t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
1722 * t( "Text Contains", "a:contains('Google')", ["google","groups"] );
1723 * t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
1724 * t( "Element Preceded By", "p ~ div", ["foo"] );
1725 * t( "Not", "a.blog:not(.link)", ["mark"] );
1727 * ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
1728 * t( "All Div Elements", "//div", ["main","foo"] );
1729 * t( "Absolute Path", "/html/body", ["body"] );
1730 * t( "Absolute Path w/ *", "/* /body", ["body"] );
1731 * t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
1732 * t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
1733 * t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
1734 * t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
1735 * t( "Attribute Exists", "//a[@title]", ["google"] );
1736 * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
1737 * t( "Parent Axis", "//p/..", ["main","foo"] );
1738 * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1739 * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
1740 * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
1742 * t( "nth Element", "p:nth(1)", ["ap"] );
1743 * t( "First Element", "p:first", ["firstp"] );
1744 * t( "Last Element", "p:last", ["first"] );
1745 * t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
1746 * t( "Odd Elements", "p:odd", ["ap","en","first"] );
1747 * t( "Position Equals", "p:eq(1)", ["ap"] );
1748 * t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
1749 * t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
1750 * t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
1751 * t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
1752 * t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
1754 * t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
1756 * t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
1757 * t( "All Children of ID with no children", "#firstUL/*", [] );
1759 * t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
1760 * t( "Form element :radio", ":radio", ["radio1", "radio2"] );
1761 * t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
1762 * t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
1763 * t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
1764 * t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
1765 * t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
1767 * t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
1768 * t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
1769 * t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
1772 * @type Array<Element>
1776 find: function( t, context ) {
1777 // Make sure that the context is a DOM Element
1778 if ( context && context.nodeType == undefined )
1781 // Set the correct context (if none is provided)
1782 context = context || jQuery.context || document;
1784 if ( t.constructor != String ) return [t];
1786 if ( !t.indexOf("//") ) {
1787 context = context.documentElement;
1788 t = t.substr(2,t.length);
1789 } else if ( !t.indexOf("/") ) {
1790 context = context.documentElement;
1791 t = t.substr(1,t.length);
1792 // FIX Assume the root element is right :(
1793 if ( t.indexOf("/") >= 1 )
1794 t = t.substr(t.indexOf("/"),t.length);
1797 var ret = [context];
1801 while ( t.length > 0 && last != t ) {
1805 t = jQuery.trim(t).replace( /^\/\//i, "" );
1807 var foundToken = false;
1809 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1810 if ( foundToken ) continue;
1812 var re = new RegExp("^(" + jQuery.token[i] + ")");
1816 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1817 t = jQuery.trim( t.replace( re, "" ) );
1822 if ( !foundToken ) {
1823 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1824 if ( ret[0] == context ) ret.shift();
1825 done = jQuery.merge( done, ret );
1826 r = ret = [context];
1827 t = " " + t.substr(1,t.length);
1829 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1830 var m = re2.exec(t);
1832 if ( m[1] == "#" ) {
1833 // Ummm, should make this work in all XML docs
1834 var oid = document.getElementById(m[2]);
1835 r = ret = oid ? [oid] : [];
1836 t = t.replace( re2, "" );
1838 if ( !m[2] || m[1] == "." ) m[2] = "*";
1840 for ( var i = 0; i < ret.length; i++ )
1841 r = jQuery.merge( r,
1843 jQuery.getAll(ret[i]) :
1844 ret[i].getElementsByTagName(m[2])
1852 var val = jQuery.filter(t,r);
1854 t = jQuery.trim(val.t);
1858 if ( ret && ret[0] == context ) ret.shift();
1859 done = jQuery.merge( done, ret );
1864 getAll: function(o,r) {
1866 var s = o.childNodes;
1867 for ( var i = 0; i < s.length; i++ )
1868 if ( s[i].nodeType == 1 ) {
1870 jQuery.getAll( s[i], r );
1875 attr: function(elem, name, value){
1878 "class": "className",
1879 "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
1880 cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
1881 innerHTML: "innerHTML",
1882 className: "className",
1884 disabled: "disabled",
1888 // IE actually uses filters for opacity ... elem is actually elem.style
1889 if (name == "opacity" && jQuery.browser.msie && value != undefined) {
1890 // IE has trouble with opacity if it does not have layout
1891 // Would prefer to check element.hasLayout first but don't have access to the element here
1893 if (value == 1) // Remove filter to avoid more IE weirdness
1894 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"");
1896 return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"") + "alpha(opacity=" + value * 100 + ")";
1897 } else if (name == "opacity" && jQuery.browser.msie) {
1898 return elem["filter"] ? parseFloat( elem["filter"].match(/alpha\(opacity=(.*)\)/)[1] )/100 : 1;
1901 // Mozilla doesn't play well with opacity 1
1902 if (name == "opacity" && jQuery.browser.mozilla && value == 1) value = 0.9999;
1905 if ( value != undefined ) elem[fix[name]] = value;
1906 return elem[fix[name]];
1907 } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
1908 return elem.getAttributeNode(name).nodeValue;
1909 } else if ( elem.getAttribute != undefined && elem.tagName ) { // IE elem.getAttribute passes even for style
1910 if ( value != undefined ) elem.setAttribute( name, value );
1911 return elem.getAttribute( name );
1913 name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
1914 if ( value != undefined ) elem[name] = value;
1919 // The regular expressions that power the parsing engine
1921 // Match: [@value='test'], [@foo]
1922 "\\[ *(@)S *([!*$^=]*) *('?\"?)(.*?)\\4 *\\]",
1924 // Match: [div], [div p]
1925 "(\\[)\s*(.*?)\s*\\]",
1927 // Match: :contains('foo')
1928 "(:)S\\(\"?'?([^\\)]*?)\"?'?\\)",
1930 // Match: :even, :last-chlid
1934 filter: function(t,r,not) {
1935 // Figure out if we're doing regular, or inverse, filtering
1936 var g = not !== false ? jQuery.grep :
1937 function(a,f) {return jQuery.grep(a,f,true);};
1939 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1941 var p = jQuery.parse;
1943 for ( var i = 0; i < p.length; i++ ) {
1945 // Look for, and replace, string-like sequences
1946 // and finally build a regexp out of it
1947 var re = new RegExp(
1948 "^" + p[i].replace("S", "([a-z*_-][a-z0-9_-]*)"), "i" );
1950 var m = re.exec( t );
1953 // Re-organize the first match
1955 m = ["",m[1], m[3], m[2], m[5]];
1957 // Remove what we just matched
1958 t = t.replace( re, "" );
1964 // :not() is a special case that can be optimized by
1965 // keeping it out of the expression list
1966 if ( m[1] == ":" && m[2] == "not" )
1967 r = jQuery.filter(m[3],r,false).r;
1969 // Otherwise, find the expression to execute
1971 var f = jQuery.expr[m[1]];
1972 if ( f.constructor != String )
1973 f = jQuery.expr[m[1]][m[2]];
1975 // Build a custom macro to enclose it
1976 eval("f = function(a,i){" +
1977 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1978 "return " + f + "}");
1980 // Execute it against the current filter
1985 // Return an array of filtered elements (r)
1986 // and the modified expression string (t)
1987 return { r: r, t: t };
1991 * Remove the whitespace from the beginning and end of a string.
1993 * @example $.trim(" hello, how are you? ");
1994 * @result "hello, how are you?"
1998 * @param String str The string to trim.
2002 return t.replace(/^\s+|\s+$/g, "");
2006 * All ancestors of a given element.
2010 * @type Array<Element>
2011 * @param Element elem The element to find the ancestors of.
2012 * @cat DOM/Traversing
2014 parents: function( elem ){
2016 var cur = elem.parentNode;
2017 while ( cur && cur != document ) {
2018 matched.push( cur );
2019 cur = cur.parentNode;
2025 * All elements on a specified axis.
2030 * @param Element elem The element to find all the siblings of (including itself).
2031 * @cat DOM/Traversing
2033 sibling: function(elem, pos, not) {
2037 var siblings = elem.parentNode.childNodes;
2038 for ( var i = 0; i < siblings.length; i++ ) {
2039 if ( not === true && siblings[i] == elem ) continue;
2041 if ( siblings[i].nodeType == 1 )
2042 elems.push( siblings[i] );
2043 if ( siblings[i] == elem )
2044 elems.n = elems.length - 1;
2048 return jQuery.extend( elems, {
2049 last: elems.n == elems.length - 1,
2050 cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
2051 prev: elems[elems.n - 1],
2052 next: elems[elems.n + 1]
2057 * Merge two arrays together, removing all duplicates. The final order
2058 * or the new array is: All the results from the first array, followed
2059 * by the unique results from the second array.
2061 * @example $.merge( [0,1,2], [2,3,4] )
2062 * @result [0,1,2,3,4]
2064 * @example $.merge( [3,2,1], [4,3,2] )
2069 * @param Array first The first array to merge.
2070 * @param Array second The second array to merge.
2073 merge: function(first, second) {
2076 // Move b over to the new array (this helps to avoid
2077 // StaticNodeList instances)
2078 for ( var k = 0; k < first.length; k++ )
2079 result[k] = first[k];
2081 // Now check for duplicates between a and b and only
2082 // add the unique items
2083 for ( var i = 0; i < second.length; i++ ) {
2084 var noCollision = true;
2086 // The collision-checking process
2087 for ( var j = 0; j < first.length; j++ )
2088 if ( second[i] == first[j] )
2089 noCollision = false;
2091 // If the item is unique, add it
2093 result.push( second[i] );
2100 * Filter items out of an array, by using a filter function.
2101 * The specified function will be passed two arguments: The
2102 * current array item and the index of the item in the array. The
2103 * function should return 'true' if you wish to keep the item in
2104 * the array, false if it should be removed.
2106 * @example $.grep( [0,1,2], function(i){
2113 * @param Array array The Array to find items in.
2114 * @param Function fn The function to process each item against.
2115 * @param Boolean inv Invert the selection - select the opposite of the function.
2118 grep: function(elems, fn, inv) {
2119 // If a string is passed in for the function, make a function
2120 // for it (a handy shortcut)
2121 if ( fn.constructor == String )
2122 fn = new Function("a","i","return " + fn);
2126 // Go through the array, only saving the items
2127 // that pass the validator function
2128 for ( var i = 0; i < elems.length; i++ )
2129 if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
2130 result.push( elems[i] );
2136 * Translate all items in an array to another array of items.
2137 * The translation function that is provided to this method is
2138 * called for each item in the array and is passed one argument:
2139 * The item to be translated. The function can then return:
2140 * The translated value, 'null' (to remove the item), or
2141 * an array of values - which will be flattened into the full array.
2143 * @example $.map( [0,1,2], function(i){
2148 * @example $.map( [0,1,2], function(i){
2149 * return i > 0 ? i + 1 : null;
2153 * @example $.map( [0,1,2], function(i){
2154 * return [ i, i + 1 ];
2156 * @result [0, 1, 1, 2, 2, 3]
2160 * @param Array array The Array to translate.
2161 * @param Function fn The function to process each item against.
2164 map: function(elems, fn) {
2165 // If a string is passed in for the function, make a function
2166 // for it (a handy shortcut)
2167 if ( fn.constructor == String )
2168 fn = new Function("a","return " + fn);
2172 // Go through the array, translating each of the items to their
2173 // new value (or values).
2174 for ( var i = 0; i < elems.length; i++ ) {
2175 var val = fn(elems[i],i);
2177 if ( val !== null && val != undefined ) {
2178 if ( val.constructor != Array ) val = [val];
2179 result = jQuery.merge( result, val );
2187 * A number of helper functions used for managing events.
2188 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
2192 // Bind an event to an element
2193 // Original by Dean Edwards
2194 add: function(element, type, handler) {
2195 // For whatever reason, IE has trouble passing the window object
2196 // around, causing it to be cloned in the process
2197 if ( jQuery.browser.msie && element.setInterval != undefined )
2200 // Make sure that the function being executed has a unique ID
2201 if ( !handler.guid )
2202 handler.guid = this.guid++;
2204 // Init the element's event structure
2205 if (!element.events)
2206 element.events = {};
2208 // Get the current list of functions bound to this event
2209 var handlers = element.events[type];
2211 // If it hasn't been initialized yet
2213 // Init the event handler queue
2214 handlers = element.events[type] = {};
2216 // Remember an existing handler, if it's already there
2217 if (element["on" + type])
2218 handlers[0] = element["on" + type];
2221 // Add the function to the element's handler list
2222 handlers[handler.guid] = handler;
2224 // And bind the global event handler to the element
2225 element["on" + type] = this.handle;
2227 // Remember the function in a global list (for triggering)
2228 if (!this.global[type])
2229 this.global[type] = [];
2230 this.global[type].push( element );
2236 // Detach an event or set of events from an element
2237 remove: function(element, type, handler) {
2239 if (type && element.events[type])
2241 delete element.events[type][handler.guid];
2243 for ( var i in element.events[type] )
2244 delete element.events[type][i];
2246 for ( var j in element.events )
2247 this.remove( element, j );
2250 trigger: function(type,data,element) {
2251 // Touch up the incoming data
2254 // Handle a global trigger
2256 var g = this.global[type];
2258 for ( var i = 0; i < g.length; i++ )
2259 this.trigger( type, data, g[i] );
2261 // Handle triggering a single element
2262 } else if ( element["on" + type] ) {
2263 // Pass along a fake event
2264 data.unshift( this.fix({ type: type, target: element }) );
2266 // Trigger the event
2267 element["on" + type].apply( element, data );
2271 handle: function(event) {
2272 if ( typeof jQuery == "undefined" ) return false;
2274 event = event || jQuery.event.fix( window.event );
2276 // If no correct event was found, fail
2277 if ( !event ) return false;
2279 var returnValue = true;
2281 var c = this.events[event.type];
2283 var args = [].slice.call( arguments, 1 );
2284 args.unshift( event );
2286 for ( var j in c ) {
2287 if ( c[j].apply( this, args ) === false ) {
2288 event.preventDefault();
2289 event.stopPropagation();
2290 returnValue = false;
2297 fix: function(event) {
2299 event.preventDefault = function() {
2300 this.returnValue = false;
2303 event.stopPropagation = function() {
2304 this.cancelBubble = true;
2315 * Contains flags for the useragent, read from navigator.userAgent.
2316 * Available flags are: safari, opera, msie, mozilla
2317 * This property is available before the DOM is ready, therefore you can
2318 * use it to add ready events only for certain browsers.
2320 * See <a href="http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/">
2321 * jQBrowser plugin</a> for advanced browser detection:
2323 * @example $.browser.msie
2324 * @desc returns true if the current useragent is some version of microsoft's internet explorer
2326 * @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
2327 * @desc Alerts "this is safari!" only for safari browsers
2334 var b = navigator.userAgent.toLowerCase();
2336 // Figure out what browser is being used
2338 safari: /webkit/.test(b),
2339 opera: /opera/.test(b),
2340 msie: /msie/.test(b) && !/opera/.test(b),
2341 mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
2344 // Check to see if the W3C box model is being used
2345 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
2351 * Append all of the matched elements to another, specified, set of elements.
2352 * This operation is, essentially, the reverse of doing a regular
2353 * $(A).append(B), in that instead of appending B to A, you're appending
2356 * @example $("p").appendTo("#foo");
2357 * @before <p>I would like to say: </p><div id="foo"></div>
2358 * @result <div id="foo"><p>I would like to say: </p></div>
2362 * @param String expr A jQuery expression of elements to match.
2363 * @cat DOM/Manipulation
2368 * Prepend all of the matched elements to another, specified, set of elements.
2369 * This operation is, essentially, the reverse of doing a regular
2370 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
2373 * @example $("p").prependTo("#foo");
2374 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
2375 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
2379 * @param String expr A jQuery expression of elements to match.
2380 * @cat DOM/Manipulation
2382 prependTo: "prepend",
2385 * Insert all of the matched elements before another, specified, set of elements.
2386 * This operation is, essentially, the reverse of doing a regular
2387 * $(A).before(B), in that instead of inserting B before A, you're inserting
2390 * @example $("p").insertBefore("#foo");
2391 * @before <div id="foo">Hello</div><p>I would like to say: </p>
2392 * @result <p>I would like to say: </p><div id="foo">Hello</div>
2394 * @name insertBefore
2396 * @param String expr A jQuery expression of elements to match.
2397 * @cat DOM/Manipulation
2399 insertBefore: "before",
2402 * Insert all of the matched elements after another, specified, set of elements.
2403 * This operation is, essentially, the reverse of doing a regular
2404 * $(A).after(B), in that instead of inserting B after A, you're inserting
2407 * @example $("p").insertAfter("#foo");
2408 * @before <p>I would like to say: </p><div id="foo">Hello</div>
2409 * @result <div id="foo">Hello</div><p>I would like to say: </p>
2413 * @param String expr A jQuery expression of elements to match.
2414 * @cat DOM/Manipulation
2416 insertAfter: "after"
2420 * Get the current CSS width of the first matched element.
2422 * @example $("p").width();
2423 * @before <p>This is just a test.</p>
2432 * Set the CSS width of every matched element. Be sure to include
2433 * the "px" (or other unit of measurement) after the number that you
2434 * specify, otherwise you might get strange results.
2436 * @example $("p").width("20px");
2437 * @before <p>This is just a test.</p>
2438 * @result <p style="width:20px;">This is just a test.</p>
2442 * @param String val Set the CSS property to the specified value.
2447 * Get the current CSS height of the first matched element.
2449 * @example $("p").height();
2450 * @before <p>This is just a test.</p>
2459 * Set the CSS height of every matched element. Be sure to include
2460 * the "px" (or other unit of measurement) after the number that you
2461 * specify, otherwise you might get strange results.
2463 * @example $("p").height("20px");
2464 * @before <p>This is just a test.</p>
2465 * @result <p style="height:20px;">This is just a test.</p>
2469 * @param String val Set the CSS property to the specified value.
2474 * Get the current CSS top of the first matched element.
2476 * @example $("p").top();
2477 * @before <p>This is just a test.</p>
2486 * Set the CSS top of every matched element. Be sure to include
2487 * the "px" (or other unit of measurement) after the number that you
2488 * specify, otherwise you might get strange results.
2490 * @example $("p").top("20px");
2491 * @before <p>This is just a test.</p>
2492 * @result <p style="top:20px;">This is just a test.</p>
2496 * @param String val Set the CSS property to the specified value.
2501 * Get the current CSS left of the first matched element.
2503 * @example $("p").left();
2504 * @before <p>This is just a test.</p>
2513 * Set the CSS left of every matched element. Be sure to include
2514 * the "px" (or other unit of measurement) after the number that you
2515 * specify, otherwise you might get strange results.
2517 * @example $("p").left("20px");
2518 * @before <p>This is just a test.</p>
2519 * @result <p style="left:20px;">This is just a test.</p>
2523 * @param String val Set the CSS property to the specified value.
2528 * Get the current CSS position of the first matched element.
2530 * @example $("p").position();
2531 * @before <p>This is just a test.</p>
2540 * Set the CSS position of every matched element.
2542 * @example $("p").position("relative");
2543 * @before <p>This is just a test.</p>
2544 * @result <p style="position:relative;">This is just a test.</p>
2548 * @param String val Set the CSS property to the specified value.
2553 * Get the current CSS float of the first matched element.
2555 * @example $("p").float();
2556 * @before <p>This is just a test.</p>
2565 * Set the CSS float of every matched element.
2567 * @example $("p").float("left");
2568 * @before <p>This is just a test.</p>
2569 * @result <p style="float:left;">This is just a test.</p>
2573 * @param String val Set the CSS property to the specified value.
2578 * Get the current CSS overflow of the first matched element.
2580 * @example $("p").overflow();
2581 * @before <p>This is just a test.</p>
2590 * Set the CSS overflow of every matched element.
2592 * @example $("p").overflow("auto");
2593 * @before <p>This is just a test.</p>
2594 * @result <p style="overflow:auto;">This is just a test.</p>
2598 * @param String val Set the CSS property to the specified value.
2603 * Get the current CSS color of the first matched element.
2605 * @example $("p").color();
2606 * @before <p>This is just a test.</p>
2615 * Set the CSS color of every matched element.
2617 * @example $("p").color("blue");
2618 * @before <p>This is just a test.</p>
2619 * @result <p style="color:blue;">This is just a test.</p>
2623 * @param String val Set the CSS property to the specified value.
2628 * Get the current CSS background of the first matched element.
2630 * @example $("p").background();
2631 * @before <p style="background:blue;">This is just a test.</p>
2640 * Set the CSS background of every matched element.
2642 * @example $("p").background("blue");
2643 * @before <p>This is just a test.</p>
2644 * @result <p style="background:blue;">This is just a test.</p>
2648 * @param String val Set the CSS property to the specified value.
2652 css: "width,height,top,left,position,float,overflow,color,background".split(","),
2655 * Reduce the set of matched elements to a single element.
2656 * The position of the element in the set of matched elements
2657 * starts at 0 and goes to length - 1.
2659 * @example $("p").eq(1)
2660 * @before <p>This is just a test.</p><p>So is this</p>
2661 * @result [ <p>So is this</p> ]
2665 * @param Number pos The index of the element that you wish to limit to.
2670 * Reduce the set of matched elements to all elements before a given position.
2671 * The position of the element in the set of matched elements
2672 * starts at 0 and goes to length - 1.
2674 * @example $("p").lt(1)
2675 * @before <p>This is just a test.</p><p>So is this</p>
2676 * @result [ <p>This is just a test.</p> ]
2680 * @param Number pos Reduce the set to all elements below this position.
2685 * Reduce the set of matched elements to all elements after a given position.
2686 * The position of the element in the set of matched elements
2687 * starts at 0 and goes to length - 1.
2689 * @example $("p").gt(0)
2690 * @before <p>This is just a test.</p><p>So is this</p>
2691 * @result [ <p>So is this</p> ]
2695 * @param Number pos Reduce the set to all elements after this position.
2700 * Filter the set of elements to those that contain the specified text.
2702 * @example $("p").contains("test")
2703 * @before <p>This is just a test.</p><p>So is this</p>
2704 * @result [ <p>This is just a test.</p> ]
2708 * @param String str The string that will be contained within the text of an element.
2709 * @cat DOM/Traversing
2712 filter: [ "eq", "lt", "gt", "contains" ],
2716 * Get the current value of the first matched element.
2718 * @example $("input").val();
2719 * @before <input type="text" value="some text"/>
2720 * @result "some text"
2722 * @test ok( $("#text1").val() == "Test", "Check for value of input element" );
2723 * ok( !$("#text1").val() == "", "Check for value of input element" );
2727 * @cat DOM/Attributes
2731 * Set the value of every matched element.
2733 * @example $("input").val("test");
2734 * @before <input type="text" value="some text"/>
2735 * @result <input type="text" value="test"/>
2737 * @test document.getElementById('text1').value = "bla";
2738 * ok( $("#text1").val() == "bla", "Check for modified value of input element" );
2739 * $("#text1").val('test');
2740 * ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
2744 * @param String val Set the property to the specified value.
2745 * @cat DOM/Attributes
2750 * Get the html contents of the first matched element.
2752 * @example $("div").html();
2753 * @before <div><input/></div>
2758 * @cat DOM/Attributes
2762 * Set the html contents of every matched element.
2764 * @example $("div").html("<b>new stuff</b>");
2765 * @before <div><input/></div>
2766 * @result <div><b>new stuff</b></div>
2768 * @test var div = $("div");
2769 * div.html("<b>test</b>");
2771 * for ( var i = 0; i < div.size(); i++ ) {
2772 * if ( div.get(i).childNodes.length == 0 ) pass = false;
2774 * ok( pass, "Set HTML" );
2778 * @param String val Set the html contents to the specified value.
2779 * @cat DOM/Attributes
2784 * Get the current id of the first matched element.
2786 * @example $("input").id();
2787 * @before <input type="text" id="test" value="some text"/>
2790 * @test ok( $(document.getElementById('main')).id() == "main", "Check for id" );
2791 * ok( $("#foo").id() == "foo", "Check for id" );
2792 * ok( !$("head").id(), "Check for id" );
2796 * @cat DOM/Attributes
2800 * Set the id of every matched element.
2802 * @example $("input").id("newid");
2803 * @before <input type="text" id="test" value="some text"/>
2804 * @result <input type="text" id="newid" value="some text"/>
2808 * @param String val Set the property to the specified value.
2809 * @cat DOM/Attributes
2814 * Get the current title of the first matched element.
2816 * @example $("img").title();
2817 * @before <img src="test.jpg" title="my image"/>
2818 * @result "my image"
2820 * @test ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
2821 * ok( !$("#yahoo").title(), "Check for title" );
2825 * @cat DOM/Attributes
2829 * Set the title of every matched element.
2831 * @example $("img").title("new title");
2832 * @before <img src="test.jpg" title="my image"/>
2833 * @result <img src="test.jpg" title="new image"/>
2837 * @param String val Set the property to the specified value.
2838 * @cat DOM/Attributes
2843 * Get the current name of the first matched element.
2845 * @example $("input").name();
2846 * @before <input type="text" name="username"/>
2847 * @result "username"
2849 * @test ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
2850 * ok( $("#hidden1").name() == "hidden", "Check for name" );
2851 * ok( !$("#area1").name(), "Check for name" );
2855 * @cat DOM/Attributes
2859 * Set the name of every matched element.
2861 * @example $("input").name("user");
2862 * @before <input type="text" name="username"/>
2863 * @result <input type="text" name="user"/>
2867 * @param String val Set the property to the specified value.
2868 * @cat DOM/Attributes
2873 * Get the current href of the first matched element.
2875 * @example $("a").href();
2876 * @before <a href="test.html">my link</a>
2877 * @result "test.html"
2881 * @cat DOM/Attributes
2885 * Set the href of every matched element.
2887 * @example $("a").href("test2.html");
2888 * @before <a href="test.html">my link</a>
2889 * @result <a href="test2.html">my link</a>
2893 * @param String val Set the property to the specified value.
2894 * @cat DOM/Attributes
2899 * Get the current src of the first matched element.
2901 * @example $("img").src();
2902 * @before <img src="test.jpg" title="my image"/>
2903 * @result "test.jpg"
2907 * @cat DOM/Attributes
2911 * Set the src of every matched element.
2913 * @example $("img").src("test2.jpg");
2914 * @before <img src="test.jpg" title="my image"/>
2915 * @result <img src="test2.jpg" title="my image"/>
2919 * @param String val Set the property to the specified value.
2920 * @cat DOM/Attributes
2925 * Get the current rel of the first matched element.
2927 * @example $("a").rel();
2928 * @before <a href="test.html" rel="nofollow">my link</a>
2929 * @result "nofollow"
2933 * @cat DOM/Attributes
2937 * Set the rel of every matched element.
2939 * @example $("a").rel("nofollow");
2940 * @before <a href="test.html">my link</a>
2941 * @result <a href="test.html" rel="nofollow">my link</a>
2945 * @param String val Set the property to the specified value.
2946 * @cat DOM/Attributes
2953 * Get a set of elements containing the unique parents of the matched
2956 * @example $("p").parent()
2957 * @before <div><p>Hello</p><p>Hello</p></div>
2958 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
2962 * @cat DOM/Traversing
2966 * Get a set of elements containing the unique parents of the matched
2967 * set of elements, and filtered by an expression.
2969 * @example $("p").parent(".selected")
2970 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
2971 * @result [ <div class="selected"><p>Hello Again</p></div> ]
2975 * @param String expr An expression to filter the parents with
2976 * @cat DOM/Traversing
2978 parent: "a.parentNode",
2981 * Get a set of elements containing the unique ancestors of the matched
2982 * set of elements (except for the root element).
2984 * @example $("span").ancestors()
2985 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2986 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2990 * @cat DOM/Traversing
2994 * Get a set of elements containing the unique ancestors of the matched
2995 * set of elements, and filtered by an expression.
2997 * @example $("span").ancestors("p")
2998 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2999 * @result [ <p><span>Hello</span></p> ]
3003 * @param String expr An expression to filter the ancestors with
3004 * @cat DOM/Traversing
3006 ancestors: jQuery.parents,
3009 * Get a set of elements containing the unique ancestors of the matched
3010 * set of elements (except for the root element).
3012 * @example $("span").ancestors()
3013 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
3014 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
3018 * @cat DOM/Traversing
3022 * Get a set of elements containing the unique ancestors of the matched
3023 * set of elements, and filtered by an expression.
3025 * @example $("span").ancestors("p")
3026 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
3027 * @result [ <p><span>Hello</span></p> ]
3031 * @param String expr An expression to filter the ancestors with
3032 * @cat DOM/Traversing
3034 parents: jQuery.parents,
3037 * Get a set of elements containing the unique next siblings of each of the
3038 * matched set of elements.
3040 * It only returns the very next sibling, not all next siblings.
3042 * @example $("p").next()
3043 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
3044 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
3048 * @cat DOM/Traversing
3052 * Get a set of elements containing the unique next siblings of each of the
3053 * matched set of elements, and filtered by an expression.
3055 * It only returns the very next sibling, not all next siblings.
3057 * @example $("p").next(".selected")
3058 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
3059 * @result [ <p class="selected">Hello Again</p> ]
3063 * @param String expr An expression to filter the next Elements with
3064 * @cat DOM/Traversing
3066 next: "jQuery.sibling(a).next",
3069 * Get a set of elements containing the unique previous siblings of each of the
3070 * matched set of elements.
3072 * It only returns the immediately previous sibling, not all previous siblings.
3074 * @example $("p").prev()
3075 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3076 * @result [ <div><span>Hello Again</span></div> ]
3080 * @cat DOM/Traversing
3084 * Get a set of elements containing the unique previous siblings of each of the
3085 * matched set of elements, and filtered by an expression.
3087 * It only returns the immediately previous sibling, not all previous siblings.
3089 * @example $("p").previous(".selected")
3090 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3091 * @result [ <div><span>Hello</span></div> ]
3095 * @param String expr An expression to filter the previous Elements with
3096 * @cat DOM/Traversing
3098 prev: "jQuery.sibling(a).prev",
3101 * Get a set of elements containing all of the unique siblings of each of the
3102 * matched set of elements.
3104 * @example $("div").siblings()
3105 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3106 * @result [ <p>Hello</p>, <p>And Again</p> ]
3108 * @test isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
3112 * @cat DOM/Traversing
3116 * Get a set of elements containing all of the unique siblings of each of the
3117 * matched set of elements, and filtered by an expression.
3119 * @example $("div").siblings(".selected")
3120 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
3121 * @result [ <p class="selected">Hello Again</p> ]
3123 * @test isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
3124 * isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
3128 * @param String expr An expression to filter the sibling Elements with
3129 * @cat DOM/Traversing
3131 siblings: "jQuery.sibling(a, null, true)",
3135 * Get a set of elements containing all of the unique children of each of the
3136 * matched set of elements.
3138 * @example $("div").children()
3139 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
3140 * @result [ <span>Hello Again</span> ]
3142 * @test isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
3146 * @cat DOM/Traversing
3150 * Get a set of elements containing all of the unique children of each of the
3151 * matched set of elements, and filtered by an expression.
3153 * @example $("div").children(".selected")
3154 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
3155 * @result [ <p class="selected">Hello Again</p> ]
3157 * @test isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
3161 * @param String expr An expression to filter the child Elements with
3162 * @cat DOM/Traversing
3164 children: "jQuery.sibling(a.firstChild)"
3170 * Remove an attribute from each of the matched elements.
3172 * @example $("input").removeAttr("disabled")
3173 * @before <input disabled="disabled"/>
3178 * @param String name The name of the attribute to remove.
3181 removeAttr: function( key ) {
3182 this.removeAttribute( key );
3186 * Displays each of the set of matched elements if they are hidden.
3188 * @example $("p").show()
3189 * @before <p style="display: none">Hello</p>
3190 * @result [ <p style="display: block">Hello</p> ]
3192 * @test var pass = true, div = $("div");
3193 * div.show().each(function(){
3194 * if ( this.style.display == "none" ) pass = false;
3196 * ok( pass, "Show" );
3203 this.style.display = this.oldblock ? this.oldblock : "";
3204 if ( jQuery.css(this,"display") == "none" )
3205 this.style.display = "block";
3209 * Hides each of the set of matched elements if they are shown.
3211 * @example $("p").hide()
3212 * @before <p>Hello</p>
3213 * @result [ <p style="display: none">Hello</p> ]
3215 * var pass = true, div = $("div");
3216 * div.hide().each(function(){
3217 * if ( this.style.display != "none" ) pass = false;
3219 * ok( pass, "Hide" );
3226 this.oldblock = this.oldblock || jQuery.css(this,"display");
3227 if ( this.oldblock == "none" )
3228 this.oldblock = "block";
3229 this.style.display = "none";
3233 * Toggles each of the set of matched elements. If they are shown,
3234 * toggle makes them hidden. If they are hidden, toggle
3237 * @example $("p").toggle()
3238 * @before <p>Hello</p><p style="display: none">Hello Again</p>
3239 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
3246 jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
3250 * Adds the specified class to each of the set of matched elements.
3252 * @example $("p").addClass("selected")
3253 * @before <p>Hello</p>
3254 * @result [ <p class="selected">Hello</p> ]
3256 * @test var div = $("div");
3257 * div.addClass("test");
3259 * for ( var i = 0; i < div.size(); i++ ) {
3260 * if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
3262 * ok( pass, "Add Class" );
3266 * @param String class A CSS class to add to the elements
3269 addClass: function(c){
3270 jQuery.className.add(this,c);
3274 * Removes the specified class from the set of matched elements.
3276 * @example $("p").removeClass("selected")
3277 * @before <p class="selected">Hello</p>
3278 * @result [ <p>Hello</p> ]
3280 * @test var div = $("div").addClass("test");
3281 * div.removeClass("test");
3283 * for ( var i = 0; i < div.size(); i++ ) {
3284 * if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
3286 * ok( pass, "Remove Class" );
3290 * var div = $("div").addClass("test").addClass("foo").addClass("bar");
3291 * div.removeClass("test").removeClass("bar").removeClass("foo");
3293 * for ( var i = 0; i < div.size(); i++ ) {
3294 * if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
3296 * ok( pass, "Remove multiple classes" );
3300 * @param String class A CSS class to remove from the elements
3303 removeClass: function(c){
3304 jQuery.className.remove(this,c);
3308 * Adds the specified class if it is present, removes it if it is
3311 * @example $("p").toggleClass("selected")
3312 * @before <p>Hello</p><p class="selected">Hello Again</p>
3313 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
3317 * @param String class A CSS class with which to toggle the elements
3320 toggleClass: function( c ){
3321 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
3325 * Removes all matched elements from the DOM. This does NOT remove them from the
3326 * jQuery object, allowing you to use the matched elements further.
3328 * @example $("p").remove();
3329 * @before <p>Hello</p> how are <p>you?</p>
3334 * @cat DOM/Manipulation
3338 * Removes only elements (out of the list of matched elements) that match
3339 * the specified jQuery expression. This does NOT remove them from the
3340 * jQuery object, allowing you to use the matched elements further.
3342 * @example $("p").remove(".hello");
3343 * @before <p class="hello">Hello</p> how are <p>you?</p>
3344 * @result how are <p>you?</p>
3348 * @param String expr A jQuery expression to filter elements by.
3349 * @cat DOM/Manipulation
3351 remove: function(a){
3352 if ( !a || jQuery.filter( a, [this] ).r )
3353 this.parentNode.removeChild( this );
3357 * Removes all child nodes from the set of matched elements.
3359 * @example $("p").empty()
3360 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
3361 * @result [ <p></p> ]
3365 * @cat DOM/Manipulation
3368 while ( this.firstChild )
3369 this.removeChild( this.firstChild );
3373 * Binds a handler to a particular event (like click) for each matched element.
3374 * The event handler is passed an event object that you can use to prevent
3375 * default behaviour. To stop both default action and event bubbling, your handler
3376 * has to return false.
3378 * @example $("p").bind( "click", function() {
3379 * alert( $(this).text() );
3381 * @before <p>Hello</p>
3382 * @result alert("Hello")
3384 * @example $("form").bind( "submit", function() { return false; } )
3385 * @desc Cancel a default action and prevent it from bubbling by returning false
3386 * from your function.
3388 * @example $("form").bind( "submit", function(event) {
3389 * event.preventDefault();
3391 * @desc Cancel only the default action by using the preventDefault method.
3394 * @example $("form").bind( "submit", function(event) {
3395 * event.stopPropagation();
3397 * @desc Stop only an event from bubbling by using the stopPropagation method.
3401 * @param String type An event type
3402 * @param Function fn A function to bind to the event on each of the set of matched elements
3405 bind: function( type, fn ) {
3406 if ( fn.constructor == String )
3407 fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);
3408 jQuery.event.add( this, type, fn );
3412 * The opposite of bind, removes a bound event from each of the matched
3413 * elements. You must pass the identical function that was used in the original
3416 * @example $("p").unbind( "click", function() { alert("Hello"); } )
3417 * @before <p onclick="alert('Hello');">Hello</p>
3418 * @result [ <p>Hello</p> ]
3422 * @param String type An event type
3423 * @param Function fn A function to unbind from the event on each of the set of matched elements
3428 * Removes all bound events of a particular type from each of the matched
3431 * @example $("p").unbind( "click" )
3432 * @before <p onclick="alert('Hello');">Hello</p>
3433 * @result [ <p>Hello</p> ]
3437 * @param String type An event type
3442 * Removes all bound events from each of the matched elements.
3444 * @example $("p").unbind()
3445 * @before <p onclick="alert('Hello');">Hello</p>
3446 * @result [ <p>Hello</p> ]
3452 unbind: function( type, fn ) {
3453 jQuery.event.remove( this, type, fn );
3457 * Trigger a type of event on every matched element.
3459 * @example $("p").trigger("click")
3460 * @before <p click="alert('hello')">Hello</p>
3461 * @result alert('hello')
3465 * @param String type An event type to trigger.
3468 trigger: function( type, data ) {
3469 jQuery.event.trigger( type, data, this );