2 * jQuery - New Wave Javascript
4 * Copyright (c) 2006 John Resig (jquery.com)
5 * Licensed under the MIT License:
6 * http://www.opensource.org/licenses/mit-license.php
12 // Global undefined variable
13 window.undefined = window.undefined;
16 * Create a new jQuery Object
19 function jQuery(a,c) {
21 // Initalize the extra macro functions
22 if ( !jQuery.initDone ) jQuery.init();
24 // Shortcut for document ready (because $(document).each() is silly)
25 if ( a && a.constructor == Function && jQuery.fn.ready )
26 return jQuery(document).ready(a);
28 // Make sure t hat a selection was provided
29 a = a || jQuery.context || document;
32 * Handle support for overriding other $() functions. Way too many libraries
33 * provide this function to simply ignore it and overwrite it.
36 // Check to see if this is a possible collision case
37 if ( jQuery._$ && !c && a.constructor == String &&
39 // Make sure that the expression is a colliding one
40 !/[^a-zA-Z0-9_-]/.test(a) &&
42 // and that there are no elements that match it
43 // (this is the one truly ambiguous case)
44 !document.getElementsByTagName(a).length )
46 // Use the default method, in case it works some voodoo
47 return jQuery._$( a );
50 // Watch for when a jQuery object is passed as the selector
54 // Watch for when a jQuery object is passed at the context
56 return jQuery(c.get()).find(a);
58 // If the context is global, return a new object
60 return new jQuery(a,c);
62 // Handle HTML strings
63 var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
64 if ( m ) a = jQuery.clean( [ m[1] ] );
66 // Watch for when an array is passed in
67 this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
68 // Assume that it is an array of DOM Elements
69 jQuery.merge( a, [] ) :
71 // Find the matching elements and save them for later
72 jQuery.find( a, c ) );
74 var fn = arguments[ arguments.length - 1 ];
75 if ( fn && fn.constructor == Function )
79 // Map over the $ in case of overwrite
83 // Map the jQuery namespace to the '$' one
86 jQuery.fn = jQuery.prototype = {
88 * The current SVN version of jQuery.
98 * The number of elements currently matched.
100 * @example $("img").length;
101 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
110 * The number of elements currently matched.
112 * @example $("img").size();
113 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
124 * Access all matched elements. This serves as a backwards-compatible
125 * way of accessing all matched elements (other than the jQuery object
126 * itself, which is, in fact, an array of elements).
128 * @example $("img").get();
129 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
130 * @result [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]
133 * @type Array<Element>
137 * Access a single matched element. <tt>num</tt> is used to access the
138 * <tt>num</tt>th element matched.
140 * @example $("img").get(1);
141 * @before <img src="test1.jpg"/> <img src="test2.jpg"/>
142 * @result [ <img src="test1.jpg"/> ]
146 * @param Number num Access the element in the <tt>num</tt>th position.
150 * Set the jQuery object to an array of elements.
152 * @example $("img").get([ document.body ]);
153 * @result $("img").get() == [ document.body ]
158 * @param Elements elems An array of elements
160 get: function( num ) {
161 // Watch for when an array (of elements) is passed in
162 if ( num && num.constructor == Array ) {
164 // Use a tricky hack to make the jQuery object
165 // look and feel like an array
167 [].push.apply( this, num );
171 return num == undefined ?
173 // Return a 'clean' array
174 jQuery.map( this, function(a){ return a } ) :
176 // Return just the object
181 * Execute a function within the context of every matched element.
182 * This means that every time the passed-in function is executed
183 * (which is once for every element matched) the 'this' keyword
184 * points to the specific element.
186 * Additionally, the function, when executed, is passed a single
187 * argument representing the position of the element in the matched
190 * @example $("img").each(function(){ this.src = "test.jpg"; });
191 * @before <img/> <img/>
192 * @result <img src="test.jpg"/> <img src="test.jpg"/>
196 * @param Function fn A function to execute
198 each: function( fn, args ) {
199 return jQuery.each( this, fn, args );
203 * Access a property on the first matched element.
204 * This method makes it easy to retreive a property value
205 * from the first matched element.
207 * @example $("img").attr("src");
208 * @before <img src="test.jpg"/>
213 * @param String name The name of the property to access.
217 * Set a hash of key/value object properties to all matched elements.
218 * This serves as the best way to set a large number of properties
219 * on all matched elements.
221 * @example $("img").attr({ src: "test.jpg", alt: "Test Image" });
223 * @result <img src="test.jpg" alt="Test Image"/>
227 * @param Hash prop A set of key/value pairs to set as object properties.
231 * Set a single property to a value, on all matched elements.
233 * @example $("img").attr("src","test.jpg");
235 * @result <img src="test.jpg"/>
239 * @param String key The name of the property to set.
240 * @param Object value The value to set the property to.
242 attr: function( key, value, type ) {
243 // Check to see if we're setting style values
244 return key.constructor != String || value != undefined ?
245 this.each(function(){
246 // See if we're setting a hash of styles
247 if ( value == undefined )
248 // Set all the styles
249 for ( var prop in key )
251 type ? this.style : this,
255 // See if we're setting a single key/value style
258 type ? this.style : this,
263 // Look for the case where we're accessing a style value
264 jQuery[ type || "attr" ]( this[0], key );
268 * Access a style property on the first matched element.
269 * This method makes it easy to retreive a style property value
270 * from the first matched element.
272 * @example $("p").css("red");
273 * @before <p style="color:red;">Test Paragraph.</p>
278 * @param String name The name of the property to access.
282 * Set a hash of key/value style properties to all matched elements.
283 * This serves as the best way to set a large number of style properties
284 * on all matched elements.
286 * @example $("p").css({ color: "red", background: "blue" });
287 * @before <p>Test Paragraph.</p>
288 * @result <p style="color:red; background:blue;">Test Paragraph.</p>
292 * @param Hash prop A set of key/value pairs to set as style properties.
296 * Set a single style property to a value, on all matched elements.
298 * @example $("p").css("color","red");
299 * @before <p>Test Paragraph.</p>
300 * @result <p style="color:red;">Test Paragraph.</p>
304 * @param String key The name of the property to set.
305 * @param Object value The value to set the property to.
307 css: function( key, value ) {
308 return this.attr( key, value, "curCSS" );
312 * Retreive the text contents of all matched elements. The result is
313 * a string that contains the combined text contents of all matched
314 * elements. This method works on both HTML and XML documents.
316 * @example $("p").text();
317 * @before <p>Test Paragraph.</p>
318 * @result Test Paragraph.
326 for ( var j = 0; j < e.length; j++ ) {
327 var r = e[j].childNodes;
328 for ( var i = 0; i < r.length; i++ )
329 t += r[i].nodeType != 1 ?
330 r[i].nodeValue : jQuery.fn.text([ r[i] ]);
336 * Wrap all matched elements with a structure of other elements.
337 * This wrapping process is most useful for injecting additional
338 * stucture into a document, without ruining the original semantic
339 * qualities of a document.
341 * The way that is works is that it goes through the first element argument
342 * provided and finds the deepest element within the structure - it is that
343 * element that will en-wrap everything else.
345 * @example $("p").wrap("<div class='wrap'></div>");
346 * @before <p>Test Paragraph.</p>
347 * @result <div class='wrap'><p>Test Paragraph.</p></div>
351 * @any String html A string of HTML, that will be created on the fly and wrapped around the target.
352 * @any Element elem A DOM element that will be wrapped.
353 * @any Array<Element> elems An array of elements, the first of which will be wrapped.
354 * @any Object obj Any object, converted to a string, then a text node.
357 // The elements to wrap the target around
358 var a = jQuery.clean(arguments);
360 // Wrap each of the matched elements individually
361 return this.each(function(){
362 // Clone the structure that we're using to wrap
363 var b = a[0].cloneNode(true);
365 // Insert it before the element to be wrapped
366 this.parentNode.insertBefore( b, this );
368 // Find he deepest point in the wrap structure
369 while ( b.firstChild )
372 // Move the matched element to within the wrap structure
373 b.appendChild( this );
378 * Append any number of elements to the inside of all matched elements.
379 * This operation is similar to doing an <tt>appendChild</tt> to all the
380 * specified elements, adding them into the document.
382 * @example $("p").append("<b>Hello</b>");
383 * @before <p>I would like to say: </p>
384 * @result <p>I would like to say: <b>Hello</b></p>
388 * @any String html A string of HTML, that will be created on the fly and appended to the target.
389 * @any Element elem A DOM element that will be appended.
390 * @any Array<Element> elems An array of elements, all of which will be appended.
391 * @any Object obj Any object, converted to a string, then a text node.
394 return this.domManip(arguments, true, 1, function(a){
395 this.appendChild( a );
400 * Prepend any number of elements to the inside of all matched elements.
401 * This operation is the best way to insert a set of elements inside, at the
402 * beginning, of all the matched element.
404 * @example $("p").prepend("<b>Hello</b>");
405 * @before <p>, how are you?</p>
406 * @result <p><b>Hello</b>, how are you?</p>
410 * @any String html A string of HTML, that will be created on the fly and prepended to the target.
411 * @any Element elem A DOM element that will be prepended.
412 * @any Array<Element> elems An array of elements, all of which will be prepended.
413 * @any Object obj Any object, converted to a string, then a text node.
415 prepend: function() {
416 return this.domManip(arguments, true, -1, function(a){
417 this.insertBefore( a, this.firstChild );
422 * Insert any number of elements before each of the matched elements.
424 * @example $("p").before("<b>Hello</b>");
425 * @before <p>how are you?</p>
426 * @result <b>Hello</b><p>how are you?</p>
430 * @any String html A string of HTML, that will be created on the fly and inserted.
431 * @any Element elem A DOM element that will beinserted.
432 * @any Array<Element> elems An array of elements, all of which will be inserted.
433 * @any Object obj Any object, converted to a string, then a text node.
436 return this.domManip(arguments, false, 1, function(a){
437 this.parentNode.insertBefore( a, this );
442 * Insert any number of elements after each of the matched elements.
444 * @example $("p").after("<p>I'm doing fine.</p>");
445 * @before <p>How are you?</p>
446 * @result <p>How are you?</p><p>I'm doing fine.</p>
450 * @any String html A string of HTML, that will be created on the fly and inserted.
451 * @any Element elem A DOM element that will beinserted.
452 * @any Array<Element> elems An array of elements, all of which will be inserted.
453 * @any Object obj Any object, converted to a string, then a text node.
456 return this.domManip(arguments, false, -1, function(a){
457 this.parentNode.insertBefore( a, this.nextSibling );
462 * End the most recent 'destructive' operation, reverting the list of matched elements
463 * back to its previous state. After an end operation, the list of matched elements will
464 * revert to the last state of matched elements.
466 * @example $("p").find("span").end();
467 * @before <p><span>Hello</span>, how are you?</p>
468 * @result $("p").find("span").end() == [ <p>...</p> ]
474 return this.get( this.stack.pop() );
478 * Searches for all elements that match the specified expression.
479 * This method is the optimal way of finding additional descendant
480 * elements with which to process.
482 * All searching is done using a jQuery expression. The expression can be
483 * written using CSS 1-3 Selector syntax, or basic XPath.
485 * @example $("p").find("span");
486 * @before <p><span>Hello</span>, how are you?</p>
487 * @result $("p").find("span") == [ <span>Hello</span> ]
491 * @param String expr An expression to search with.
494 return this.pushStack( jQuery.map( this, function(a){
495 return jQuery.find(t,a);
500 * Removes all elements from the set of matched elements that do not
501 * match the specified expression. This method is used to narrow down
502 * the results of a search.
504 * All searching is done using a jQuery expression. The expression
505 * can be written using CSS 1-3 Selector syntax, or basic XPath.
507 * @example $("p").filter(".selected")
508 * @before <p class="selected">Hello</p><p>How are you?</p>
509 * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
513 * @param String expr An expression to search with.
517 * Removes all elements from the set of matched elements that do not
518 * match at least one of the expressions passed to the function. This
519 * method is used when you want to filter the set of matched elements
520 * through more than one expression.
522 * Elements will be retained in the jQuery object if they match at
523 * least one of the expressions passed.
525 * @example $("p").filter([".selected", ":first"])
526 * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
527 * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
531 * @param Array<String> exprs A set of expressions to evaluate against
533 filter: function(t) {
534 return this.pushStack(
535 t.constructor == Array &&
536 jQuery.map(this,function(a){
537 for ( var i = 0; i < t.length; i++ )
538 if ( jQuery.filter(t[i],[a]).r.length )
542 t.constructor == Boolean &&
543 ( t ? this.get() : [] ) ||
545 t.constructor == Function &&
546 jQuery.grep( this, t ) ||
548 jQuery.filter(t,this).r, arguments );
552 * Removes the specified Element from the set of matched elements. This
553 * method is used to remove a single Element from a jQuery object.
555 * @example $("p").not( document.getElementById("selected") )
556 * @before <p>Hello</p><p id="selected">Hello Again</p>
557 * @result [ <p>Hello</p> ]
561 * @param Element el An element to remove from the set
565 * Removes elements matching the specified expression from the set
566 * of matched elements. This method is used to remove one or more
567 * elements from a jQuery object.
569 * @example $("p").not("#selected")
570 * @before <p>Hello</p><p id="selected">Hello Again</p>
571 * @result [ <p>Hello</p> ]
575 * @param String expr An expression with which to remove matching elements
578 return this.pushStack( t.constructor == String ?
579 jQuery.filter(t,this,false).r :
580 jQuery.grep(this,function(a){ return a != t; }), arguments );
584 * Adds the elements matched by the expression to the jQuery object. This
585 * can be used to concatenate the result sets of two expressions.
587 * @example $("p").add("span")
588 * @before <p>Hello</p><p><span>Hello Again</span></p>
589 * @result [ <p>Hello</p>, <span>Hello Again</span> ]
593 * @param String expr An expression whose matched elements are added
597 * Adds each of the Elements in the array to the set of matched elements.
598 * This is used to add a set of Elements to a jQuery object.
600 * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
601 * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
602 * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
606 * @param Array<Element> els An array of Elements to add
610 * Adds a single Element to the set of matched elements. This is used to
611 * add a single Element to a jQuery object.
613 * @example $("p").add( document.getElementById("a") )
614 * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
615 * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
619 * @param Element el An Element to add
622 return this.pushStack( jQuery.merge( this, t.constructor == String ?
623 jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
627 * A wrapper function for each() to be used by append and prepend.
628 * Handles cases where you're trying to modify the inner contents of
629 * a table, when you actually need to work with the tbody.
632 * @param {String} expr The expression with which to filter
636 return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
645 * @param Boolean table
647 * @param Function fn The function doing the DOM manipulation.
650 domManip: function(args, table, dir, fn){
651 var clone = this.size() > 1;
652 var a = jQuery.clean(args);
654 return this.each(function(){
657 if ( table && this.nodeName == "TABLE" ) {
658 var tbody = this.getElementsByTagName("tbody");
660 if ( !tbody.length ) {
661 obj = document.createElement("tbody");
662 this.appendChild( obj );
667 for ( var i = ( dir < 0 ? a.length - 1 : 0 );
668 i != ( dir < 0 ? dir : a.length ); i += dir ) {
669 fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
683 pushStack: function(a,args) {
684 var fn = args && args[args.length-1];
686 if ( !fn || fn.constructor != Function ) {
687 if ( !this.stack ) this.stack = [];
688 this.stack.push( this.get() );
691 var old = this.get();
693 if ( fn.constructor == Function )
694 return this.each( fn );
713 * Extend one object with another, returning the original,
714 * modified, object. This is a great utility for simple inheritance.
717 * @param Object obj The object to extend
718 * @param Object prop The object that will be merged into the first.
721 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
722 if ( !prop ) { prop = obj; obj = this; }
723 for ( var i in prop ) obj[i] = prop[i];
736 jQuery.initDone = true;
738 jQuery.each( jQuery.macros.axis, function(i,n){
739 jQuery.fn[ i ] = function(a) {
740 var ret = jQuery.map(this,n);
741 if ( a && a.constructor == String )
742 ret = jQuery.filter(a,ret).r;
743 return this.pushStack( ret, arguments );
747 jQuery.each( jQuery.macros.to, function(i,n){
748 jQuery.fn[ i ] = function(){
750 return this.each(function(){
751 for ( var j = 0; j < a.length; j++ )
757 jQuery.each( jQuery.macros.each, function(i,n){
758 jQuery.fn[ i ] = function() {
759 return this.each( n, arguments );
763 jQuery.each( jQuery.macros.filter, function(i,n){
764 jQuery.fn[ n ] = function(num,fn) {
765 return this.filter( ":" + n + "(" + num + ")", fn );
769 jQuery.each( jQuery.macros.attr, function(i,n){
771 jQuery.fn[ i ] = function(h) {
772 return h == undefined ?
773 this.length ? this[0][n] : null :
778 jQuery.each( jQuery.macros.css, function(i,n){
779 jQuery.fn[ i ] = function(h) {
780 return h == undefined ?
781 ( this.length ? jQuery.css( this[0], n ) : null ) :
789 * A generic iterator function, which can be used to seemlessly
790 * iterate over both objects and arrays.
793 * @param Object obj The object, or array, to iterate over.
794 * @param Object fn The function that will be executed on every object.
797 each: function( obj, fn, args ) {
798 if ( obj.length == undefined )
800 fn.apply( obj[i], args || [i, obj[i]] );
802 for ( var i = 0; i < obj.length; i++ )
803 fn.apply( obj[i], args || [i, obj[i]] );
809 if (jQuery.className.has(o,c)) return;
810 o.className += ( o.className ? " " : "" ) + c;
812 remove: function(o,c){
813 o.className = !c ? "" :
815 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
820 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
825 * Swap in/out style options.
828 swap: function(e,o,f) {
830 e.style["old"+i] = e.style[i];
835 e.style[i] = e.style["old"+i];
839 if ( p == "height" || p == "width" ) {
840 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
843 old["padding" + d[i]] = 0;
844 old["border" + d[i] + "Width"] = 0;
847 jQuery.swap( e, old, function() {
848 if (jQuery.css(e,"display") != "none") {
849 oHeight = e.offsetHeight;
850 oWidth = e.offsetWidth;
852 jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
854 oHeight = e.clientHeight;
855 oWidth = e.clientWidth;
859 return p == "height" ? oHeight : oWidth;
860 } else if ( p == "opacity" && jQuery.browser.msie )
861 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
863 return jQuery.curCSS( e, p );
866 curCSS: function(e,p,force) {
869 if (!force && e.style[p])
871 else if (e.currentStyle) {
872 p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
873 r = e.currentStyle[p];
874 } else if (document.defaultView && document.defaultView.getComputedStyle) {
875 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
876 var s = document.defaultView.getComputedStyle(e,"");
877 r = s ? s.getPropertyValue(p) : null;
885 for ( var i = 0; i < a.length; i++ ) {
886 if ( a[i].constructor == String ) {
888 if ( !a[i].indexOf("<tr") ) {
890 a[i] = "<table>" + a[i] + "</table>";
891 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
893 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
896 var div = document.createElement("div");
897 div.innerHTML = a[i];
900 div = div.firstChild.firstChild;
901 if ( td ) div = div.firstChild;
904 for ( var j = 0; j < div.childNodes.length; j++ )
905 r.push( div.childNodes[j] );
906 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
907 for ( var k = 0; k < a[i].length; k++ )
909 else if ( a[i] !== null )
910 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
916 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
917 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
925 last: "i==r.length-1",
930 "first-child": "jQuery.sibling(a,0).cur",
931 "last-child": "jQuery.sibling(a,0).last",
932 "only-child": "jQuery.sibling(a).length==1",
935 parent: "a.childNodes.length",
936 empty: "!a.childNodes.length",
939 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
942 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
943 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
946 enabled: "!a.disabled",
947 disabled: "a.disabled",
950 ".": "jQuery.className.has(a,m[2])",
954 "^=": "!z.indexOf(m[4])",
955 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
956 "*=": "z.indexOf(m[4])>=0",
959 "[": "jQuery.find(m[2],a).length"
963 "\\.\\.|/\\.\\.", "a.parentNode",
964 ">|/", "jQuery.sibling(a.firstChild)",
965 "\\+", "jQuery.sibling(a).next",
968 var s = jQuery.sibling(a);
970 for ( var i = s.n; i < s.length; i++ )
976 find: function( t, context ) {
977 // Make sure that the context is a DOM Element
978 if ( context && context.nodeType == undefined )
981 // Set the correct context (if none is provided)
982 context = context || jQuery.context || document;
984 if ( t.constructor != String ) return [t];
986 if ( !t.indexOf("//") ) {
987 context = context.documentElement;
988 t = t.substr(2,t.length);
989 } else if ( !t.indexOf("/") ) {
990 context = context.documentElement;
991 t = t.substr(1,t.length);
992 // FIX Assume the root element is right :(
993 if ( t.indexOf("/") >= 1 )
994 t = t.substr(t.indexOf("/"),t.length);
1001 while ( t.length > 0 && last != t ) {
1005 t = jQuery.trim(t).replace( /^\/\//i, "" );
1007 var foundToken = false;
1009 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1010 var re = new RegExp("^(" + jQuery.token[i] + ")");
1014 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1015 t = jQuery.trim( t.replace( re, "" ) );
1020 if ( !foundToken ) {
1021 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1022 if ( ret[0] == context ) ret.shift();
1023 done = jQuery.merge( done, ret );
1024 r = ret = [context];
1025 t = " " + t.substr(1,t.length);
1027 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1028 var m = re2.exec(t);
1030 if ( m[1] == "#" ) {
1031 // Ummm, should make this work in all XML docs
1032 var oid = document.getElementById(m[2]);
1033 r = ret = oid ? [oid] : [];
1034 t = t.replace( re2, "" );
1036 if ( !m[2] || m[1] == "." ) m[2] = "*";
1038 for ( var i = 0; i < ret.length; i++ )
1039 r = jQuery.merge( r,
1041 jQuery.getAll(ret[i]) :
1042 ret[i].getElementsByTagName(m[2])
1049 var val = jQuery.filter(t,r);
1051 t = jQuery.trim(val.t);
1055 if ( ret && ret[0] == context ) ret.shift();
1056 done = jQuery.merge( done, ret );
1061 getAll: function(o,r) {
1063 var s = o.childNodes;
1064 for ( var i = 0; i < s.length; i++ )
1065 if ( s[i].nodeType == 1 ) {
1067 jQuery.getAll( s[i], r );
1072 attr: function(o,a,v){
1073 if ( a && a.constructor == String ) {
1076 "class": "className",
1080 a = (fix[a] && fix[a].replace && fix[a] || a)
1081 .replace(/-([a-z])/ig,function(z,b){
1082 return b.toUpperCase();
1085 if ( v != undefined ) {
1087 if ( o.setAttribute && a != "disabled" )
1088 o.setAttribute(a,v);
1091 return o[a] || o.getAttribute && o.getAttribute(a) || "";
1096 // The regular expressions that power the parsing engine
1098 // Match: [@value='test'], [@foo]
1099 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1101 // Match: [div], [div p]
1104 // Match: :contains('foo')
1105 [ "(:)S\\(Q\\)", 0 ],
1107 // Match: :even, :last-chlid
1111 filter: function(t,r,not) {
1112 // Figure out if we're doing regular, or inverse, filtering
1113 var g = not !== false ? jQuery.grep :
1114 function(a,f) {return jQuery.grep(a,f,true);};
1116 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1118 var p = jQuery.parse;
1120 for ( var i = 0; i < p.length; i++ ) {
1121 var re = new RegExp( "^" + p[i][0]
1123 // Look for a string-like sequence
1124 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1126 // Look for something (optionally) enclosed with quotes
1127 .replace( 'Q', " *'?\"?([^'\"]*)'?\"? *" ), "i" );
1129 var m = re.exec( t );
1132 // Re-organize the match
1134 m = ["", m[1], m[3], m[2], m[4]];
1136 // Remove what we just matched
1137 t = t.replace( re, "" );
1143 // :not() is a special case that can be optomized by
1144 // keeping it out of the expression list
1145 if ( m[1] == ":" && m[2] == "not" )
1146 r = jQuery.filter(m[3],r,false).r;
1148 // Otherwise, find the expression to execute
1150 var f = jQuery.expr[m[1]];
1151 if ( f.constructor != String )
1152 f = jQuery.expr[m[1]][m[2]];
1154 // Build a custom macro to enclose it
1155 eval("f = function(a,i){" +
1156 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1157 "return " + f + "}");
1159 // Execute it against the current filter
1164 // Return an array of filtered elements (r)
1165 // and the modified expression string (t)
1166 return { r: r, t: t };
1170 * Remove the whitespace from the beginning and end of a string.
1175 * @param String str The string to trim.
1178 return t.replace(/^\s+|\s+$/g, "");
1182 * All ancestors of a given element.
1186 * @type Array<Element>
1187 * @param Element elem The element to find the ancestors of.
1189 parents: function(a){
1191 var c = a.parentNode;
1192 while ( c && c != document ) {
1200 * All elements on a specified axis.
1205 * @param Element elem The element to find all the siblings of (including itself).
1207 sibling: function(a,n) {
1209 var tmp = a.parentNode.childNodes;
1210 for ( var i = 0; i < tmp.length; i++ ) {
1211 if ( tmp[i].nodeType == 1 )
1212 type.push( tmp[i] );
1214 type.n = type.length - 1;
1216 type.last = type.n == type.length - 1;
1218 n == "even" && type.n % 2 == 0 ||
1219 n == "odd" && type.n % 2 ||
1221 type.prev = type[type.n - 1];
1222 type.next = type[type.n + 1];
1227 * Merge two arrays together, removing all duplicates.
1232 * @param Array a The first array to merge.
1233 * @param Array b The second array to merge.
1235 merge: function(a,b) {
1238 // Move b over to the new array (this helps to avoid
1239 // StaticNodeList instances)
1240 for ( var k = 0; k < b.length; k++ )
1243 // Now check for duplicates between a and b and only
1244 // add the unique items
1245 for ( var i = 0; i < a.length; i++ ) {
1248 // The collision-checking process
1249 for ( var j = 0; j < b.length; j++ )
1253 // If the item is unique, add it
1262 * Remove items that aren't matched in an array. The function passed
1263 * in to this method will be passed two arguments: 'a' (which is the
1264 * array item) and 'i' (which is the index of the item in the array).
1269 * @param Array array The Array to find items in.
1270 * @param Function fn The function to process each item against.
1271 * @param Boolean inv Invert the selection - select the opposite of the function.
1273 grep: function(a,f,s) {
1274 // If a string is passed in for the function, make a function
1275 // for it (a handy shortcut)
1276 if ( f.constructor == String )
1277 f = new Function("a","i","return " + f);
1281 // Go through the array, only saving the items
1282 // that pass the validator function
1283 for ( var i = 0; i < a.length; i++ )
1284 if ( !s && f(a[i],i) || s && !f(a[i],i) )
1291 * Translate all items in array to another array of items. The translation function
1292 * that is provided to this method is passed one argument: 'a' (the item to be
1293 * translated). If an array is returned, that array is mapped out and merged into
1294 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1295 * from the array. Both of these changes imply that the size of the array may not
1296 * be the same size upon completion, as it was when it started.
1301 * @param Array array The Array to translate.
1302 * @param Function fn The function to process each item against.
1304 map: function(a,f) {
1305 // If a string is passed in for the function, make a function
1306 // for it (a handy shortcut)
1307 if ( f.constructor == String )
1308 f = new Function("a","return " + f);
1312 // Go through the array, translating each of the items to their
1313 // new value (or values).
1314 for ( var i = 0; i < a.length; i++ ) {
1316 if ( t !== null && t != undefined ) {
1317 if ( t.constructor != Array ) t = [t];
1318 r = jQuery.merge( t, r );
1325 * A number of helper functions used for managing events.
1326 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1330 // Bind an event to an element
1331 // Original by Dean Edwards
1332 add: function(element, type, handler) {
1333 // For whatever reason, IE has trouble passing the window object
1334 // around, causing it to be cloned in the process
1335 if ( jQuery.browser.msie && element.setInterval != undefined )
1338 // Make sure that the function being executed has a unique ID
1339 if ( !handler.guid )
1340 handler.guid = this.guid++;
1342 // Init the element's event structure
1343 if (!element.events)
1344 element.events = {};
1346 // Get the current list of functions bound to this event
1347 var handlers = element.events[type];
1349 // If it hasn't been initialized yet
1351 // Init the event handler queue
1352 handlers = element.events[type] = {};
1354 // Remember an existing handler, if it's already there
1355 if (element["on" + type])
1356 handlers[0] = element["on" + type];
1359 // Add the function to the element's handler list
1360 handlers[handler.guid] = handler;
1362 // And bind the global event handler to the element
1363 element["on" + type] = this.handle;
1365 // Remember the function in a global list (for triggering)
1366 if (!this.global[type])
1367 this.global[type] = [];
1368 this.global[type].push( element );
1374 // Detach an event or set of events from an element
1375 remove: function(element, type, handler) {
1377 if (type && element.events[type])
1379 delete element.events[type][handler.guid];
1381 for ( var i in element.events[type] )
1382 delete element.events[type][i];
1384 for ( var j in element.events )
1385 this.remove( element, j );
1388 trigger: function(type,data,element) {
1389 // Touch up the incoming data
1392 // Handle a global trigger
1394 var g = this.global[type];
1396 for ( var i = 0; i < g.length; i++ )
1397 this.trigger( type, data, g[i] );
1399 // Handle triggering a single element
1400 } else if ( element["on" + type] ) {
1401 // Pass along a fake event
1402 data.unshift( this.fix({ type: type, target: element }) );
1404 // Trigger the event
1405 element["on" + type].apply( element, data );
1409 handle: function(event) {
1410 if ( typeof jQuery == "undefined" ) return;
1412 event = event || jQuery.event.fix( window.event );
1414 // If no correct event was found, fail
1415 if ( !event ) return;
1417 var returnValue = true;
1419 var c = this.events[event.type];
1421 for ( var j in c ) {
1422 if ( c[j].apply( this, [event] ) === false ) {
1423 event.preventDefault();
1424 event.stopPropagation();
1425 returnValue = false;
1432 fix: function(event) {
1434 event.preventDefault = function() {
1435 this.returnValue = false;
1438 event.stopPropagation = function() {
1439 this.cancelBubble = true;
1450 var b = navigator.userAgent.toLowerCase();
1452 // Figure out what browser is being used
1454 safari: /webkit/.test(b),
1455 opera: /opera/.test(b),
1456 msie: /msie/.test(b) && !/opera/.test(b),
1457 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1460 // Check to see if the W3C box model is being used
1461 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1467 * Append all of the matched elements to another, specified, set of elements.
1468 * This operation is, essentially, the reverse of doing a regular
1469 * $(A).append(B), in that instead of appending B to A, you're appending
1472 * @example $("p").appendTo("#foo");
1473 * @before <p>I would like to say: </p><div id="foo"></div>
1474 * @result <div id="foo"><p>I would like to say: </p></div>
1478 * @param String expr A jQuery expression of elements to match.
1483 * Prepend all of the matched elements to another, specified, set of elements.
1484 * This operation is, essentially, the reverse of doing a regular
1485 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1488 * @example $("p").prependTo("#foo");
1489 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1490 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1494 * @param String expr A jQuery expression of elements to match.
1496 prependTo: "prepend",
1499 * Insert all of the matched elements before another, specified, set of elements.
1500 * This operation is, essentially, the reverse of doing a regular
1501 * $(A).before(B), in that instead of inserting B before A, you're inserting
1504 * @example $("p").insertBefore("#foo");
1505 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1506 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1508 * @name insertBefore
1510 * @param String expr A jQuery expression of elements to match.
1512 insertBefore: "before",
1515 * Insert all of the matched elements after another, specified, set of elements.
1516 * This operation is, essentially, the reverse of doing a regular
1517 * $(A).after(B), in that instead of inserting B after A, you're inserting
1520 * @example $("p").insertAfter("#foo");
1521 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1522 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1526 * @param String expr A jQuery expression of elements to match.
1528 insertAfter: "after"
1532 * Get the current CSS width of the first matched element.
1534 * @example $("p").width();
1535 * @before <p>This is just a test.</p>
1543 * Set the CSS width of every matched element. Be sure to include
1544 * the "px" (or other unit of measurement) after the number that you
1545 * specify, otherwise you might get strange results.
1547 * @example $("p").width("20px");
1548 * @before <p>This is just a test.</p>
1549 * @result <p style="width:20px;">This is just a test.</p>
1553 * @param String val Set the CSS property to the specified value.
1557 * Get the current CSS height of the first matched element.
1559 * @example $("p").height();
1560 * @before <p>This is just a test.</p>
1568 * Set the CSS height of every matched element. Be sure to include
1569 * the "px" (or other unit of measurement) after the number that you
1570 * specify, otherwise you might get strange results.
1572 * @example $("p").height("20px");
1573 * @before <p>This is just a test.</p>
1574 * @result <p style="height:20px;">This is just a test.</p>
1578 * @param String val Set the CSS property to the specified value.
1582 * Get the current CSS top of the first matched element.
1584 * @example $("p").top();
1585 * @before <p>This is just a test.</p>
1593 * Set the CSS top of every matched element. Be sure to include
1594 * the "px" (or other unit of measurement) after the number that you
1595 * specify, otherwise you might get strange results.
1597 * @example $("p").top("20px");
1598 * @before <p>This is just a test.</p>
1599 * @result <p style="top:20px;">This is just a test.</p>
1603 * @param String val Set the CSS property to the specified value.
1607 * Get the current CSS left of the first matched element.
1609 * @example $("p").left();
1610 * @before <p>This is just a test.</p>
1618 * Set the CSS left of every matched element. Be sure to include
1619 * the "px" (or other unit of measurement) after the number that you
1620 * specify, otherwise you might get strange results.
1622 * @example $("p").left("20px");
1623 * @before <p>This is just a test.</p>
1624 * @result <p style="left:20px;">This is just a test.</p>
1628 * @param String val Set the CSS property to the specified value.
1632 * Get the current CSS position of the first matched element.
1634 * @example $("p").position();
1635 * @before <p>This is just a test.</p>
1643 * Set the CSS position of every matched element.
1645 * @example $("p").position("relative");
1646 * @before <p>This is just a test.</p>
1647 * @result <p style="position:relative;">This is just a test.</p>
1651 * @param String val Set the CSS property to the specified value.
1655 * Get the current CSS float of the first matched element.
1657 * @example $("p").float();
1658 * @before <p>This is just a test.</p>
1666 * Set the CSS float of every matched element.
1668 * @example $("p").float("left");
1669 * @before <p>This is just a test.</p>
1670 * @result <p style="float:left;">This is just a test.</p>
1674 * @param String val Set the CSS property to the specified value.
1678 * Get the current CSS overflow of the first matched element.
1680 * @example $("p").overflow();
1681 * @before <p>This is just a test.</p>
1689 * Set the CSS overflow of every matched element.
1691 * @example $("p").overflow("auto");
1692 * @before <p>This is just a test.</p>
1693 * @result <p style="overflow:auto;">This is just a test.</p>
1697 * @param String val Set the CSS property to the specified value.
1701 * Get the current CSS color of the first matched element.
1703 * @example $("p").color();
1704 * @before <p>This is just a test.</p>
1712 * Set the CSS color of every matched element.
1714 * @example $("p").color("blue");
1715 * @before <p>This is just a test.</p>
1716 * @result <p style="color:blue;">This is just a test.</p>
1720 * @param String val Set the CSS property to the specified value.
1724 * Get the current CSS background of the first matched element.
1726 * @example $("p").background();
1727 * @before <p>This is just a test.</p>
1735 * Set the CSS background of every matched element.
1737 * @example $("p").background("blue");
1738 * @before <p>This is just a test.</p>
1739 * @result <p style="background:blue;">This is just a test.</p>
1743 * @param String val Set the CSS property to the specified value.
1746 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1748 filter: [ "eq", "lt", "gt", "contains" ],
1752 * Get the current value of the first matched element.
1754 * @example $("input").val();
1755 * @before <input type="text" value="some text"/>
1756 * @result "some text"
1763 * Set the value of every matched element.
1765 * @example $("input").value("test");
1766 * @before <input type="text" value="some text"/>
1767 * @result <input type="text" value="test"/>
1771 * @param String val Set the property to the specified value.
1776 * Get the html contents of the first matched element.
1778 * @example $("div").html();
1779 * @before <div><input/></div>
1787 * Set the html contents of every matched element.
1789 * @example $("div").html("<b>new stuff</b>");
1790 * @before <div><input/></div>
1791 * @result <div><b>new stuff</b</div>
1795 * @param String val Set the html contents to the specified value.
1800 * Get the current id of the first matched element.
1802 * @example $("input").id();
1803 * @before <input type="text" id="test" value="some text"/>
1811 * Set the id of every matched element.
1813 * @example $("input").id("newid");
1814 * @before <input type="text" id="test" value="some text"/>
1815 * @result <input type="text" id="newid" value="some text"/>
1819 * @param String val Set the property to the specified value.
1824 * Get the current title of the first matched element.
1826 * @example $("img").title();
1827 * @before <img src="test.jpg" title="my image"/>
1828 * @result "my image"
1835 * Set the title of every matched element.
1837 * @example $("img").title("new title");
1838 * @before <img src="test.jpg" title="my image"/>
1839 * @result <img src="test.jpg" title="new image"/>
1843 * @param String val Set the property to the specified value.
1848 * Get the current name of the first matched element.
1850 * @example $("input").name();
1851 * @before <input type="text" name="username"/>
1852 * @result "username"
1859 * Set the name of every matched element.
1861 * @example $("input").name("user");
1862 * @before <input type="text" name="username"/>
1863 * @result <input type="text" name="user"/>
1867 * @param String val Set the property to the specified value.
1872 * Get the current href of the first matched element.
1874 * @example $("a").href();
1875 * @before <a href="test.html">my link</a>
1876 * @result "test.html"
1883 * Set the href of every matched element.
1885 * @example $("a").href("test2.html");
1886 * @before <a href="test.html">my link</a>
1887 * @result <a href="test2.html">my link</a>
1891 * @param String val Set the property to the specified value.
1896 * Get the current src of the first matched element.
1898 * @example $("img").src();
1899 * @before <img src="test.jpg" title="my image"/>
1900 * @result "test.jpg"
1907 * Set the src of every matched element.
1909 * @example $("img").src("test2.jpg");
1910 * @before <img src="test.jpg" title="my image"/>
1911 * @result <img src="test2.jpg" title="my image"/>
1915 * @param String val Set the property to the specified value.
1920 * Get the current rel of the first matched element.
1922 * @example $("a").rel();
1923 * @before <a href="test.html" rel="nofollow">my link</a>
1924 * @result "nofollow"
1931 * Set the rel of every matched element.
1933 * @example $("a").rel("nofollow");
1934 * @before <a href="test.html">my link</a>
1935 * @result <a href="test.html" rel="nofollow">my link</a>
1939 * @param String val Set the property to the specified value.
1946 * Get a set of elements containing the unique parents of the matched
1949 * @example $("p").parent()
1950 * @before <div><p>Hello</p><p>Hello</p></div>
1951 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1958 * Get a set of elements containing the unique parents of the matched
1959 * set of elements, and filtered by an expression.
1961 * @example $("p").parent(".selected")
1962 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1963 * @result [ <div class="selected"><p>Hello Again</p></div> ]
1967 * @param String expr An expression to filter the parents with
1969 parent: "a.parentNode",
1972 * Get a set of elements containing the unique ancestors of the matched
1975 * @example $("span").ancestors()
1976 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1977 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1984 * Get a set of elements containing the unique ancestors of the matched
1985 * set of elements, and filtered by an expression.
1987 * @example $("span").ancestors("p")
1988 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1989 * @result [ <p><span>Hello</span></p> ]
1993 * @param String expr An expression to filter the ancestors with
1995 ancestors: jQuery.parents,
1998 * Get a set of elements containing the unique ancestors of the matched
2001 * @example $("span").ancestors()
2002 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2003 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2010 * Get a set of elements containing the unique ancestors of the matched
2011 * set of elements, and filtered by an expression.
2013 * @example $("span").ancestors("p")
2014 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2015 * @result [ <p><span>Hello</span></p> ]
2019 * @param String expr An expression to filter the ancestors with
2021 parents: jQuery.parents,
2024 * Get a set of elements containing the unique next siblings of each of the
2025 * matched set of elements.
2027 * It only returns the very next sibling, not all next siblings.
2029 * @example $("p").next()
2030 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2031 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2038 * Get a set of elements containing the unique next siblings of each of the
2039 * matched set of elements, and filtered by an expression.
2041 * It only returns the very next sibling, not all next siblings.
2043 * @example $("p").next(".selected")
2044 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2045 * @result [ <p class="selected">Hello Again</p> ]
2049 * @param String expr An expression to filter the next Elements with
2051 next: "jQuery.sibling(a).next",
2054 * Get a set of elements containing the unique previous siblings of each of the
2055 * matched set of elements.
2057 * It only returns the immediately previous sibling, not all previous siblings.
2059 * @example $("p").previous()
2060 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2061 * @result [ <div><span>Hello Again</span></div> ]
2068 * Get a set of elements containing the unique previous siblings of each of the
2069 * matched set of elements, and filtered by an expression.
2071 * It only returns the immediately previous sibling, not all previous siblings.
2073 * @example $("p").previous(".selected")
2074 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2075 * @result [ <div><span>Hello</span></div> ]
2079 * @param String expr An expression to filter the previous Elements with
2081 prev: "jQuery.sibling(a).prev",
2084 * Get a set of elements containing all of the unique siblings of each of the
2085 * matched set of elements.
2087 * @example $("div").siblings()
2088 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2089 * @result [ <p>Hello</p>, <p>And Again</p> ]
2096 * Get a set of elements containing all of the unique siblings of each of the
2097 * matched set of elements, and filtered by an expression.
2099 * @example $("div").siblings(".selected")
2100 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2101 * @result [ <p class="selected">Hello Again</p> ]
2105 * @param String expr An expression to filter the sibling Elements with
2107 siblings: jQuery.sibling,
2111 * Get a set of elements containing all of the unique children of each of the
2112 * matched set of elements.
2114 * @example $("div").children()
2115 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2116 * @result [ <span>Hello Again</span> ]
2123 * Get a set of elements containing all of the unique siblings of each of the
2124 * matched set of elements, and filtered by an expression.
2126 * @example $("div").children(".selected")
2127 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2128 * @result [ <p class="selected">Hello Again</p> ]
2132 * @param String expr An expression to filter the child Elements with
2134 children: "a.childNodes"
2139 * Displays each of the set of matched elements if they are hidden.
2141 * @example $("p").show()
2142 * @before <p style="display: none">Hello</p>
2143 * @result [ <p style="display: block">Hello</p> ]
2149 this.style.display = this.oldblock ? this.oldblock : "";
2150 if ( jQuery.css(this,"display") == "none" )
2151 this.style.display = "block";
2155 * Hides each of the set of matched elements if they are shown.
2157 * @example $("p").hide()
2158 * @before <p>Hello</p>
2159 * @result [ <p style="display: none">Hello</p> ]
2165 this.oldblock = this.oldblock || jQuery.css(this,"display");
2166 if ( this.oldblock == "none" )
2167 this.oldblock = "block";
2168 this.style.display = "none";
2172 * Toggles each of the set of matched elements. If they are shown,
2173 * toggle makes them hidden. If they are hidden, toggle
2176 * @example $("p").toggle()
2177 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2178 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2183 _toggle: function(){
2184 var d = jQuery.css(this,"display");
2185 $(this)[ !d || d == "none" ? "show" : "hide" ]();
2189 * Adds the specified class to each of the set of matched elements.
2191 * @example ("p").addClass("selected")
2192 * @before <p>Hello</p>
2193 * @result [ <p class="selected">Hello</p> ]
2197 * @param String class A CSS class to add to the elements
2199 addClass: function(c){
2200 jQuery.className.add(this,c);
2204 * The opposite of addClass. Removes the specified class from the
2205 * set of matched elements.
2207 * @example ("p").removeClass("selected")
2208 * @before <p class="selected">Hello</p>
2209 * @result [ <p>Hello</p> ]
2213 * @param String class A CSS class to remove from the elements
2215 removeClass: function(c){
2216 jQuery.className.remove(this,c);
2220 * Adds the specified class if it is present. Remove it if it is
2223 * @example ("p").toggleClass("selected")
2224 * @before <p>Hello</p><p class="selected">Hello Again</p>
2225 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2229 * @param String class A CSS class with which to toggle the elements
2231 toggleClass: function( c ){
2232 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2238 remove: function(a){
2239 if ( !a || jQuery.filter( [this], a ).r )
2240 this.parentNode.removeChild( this );
2244 * Removes all child nodes from the set of matched elements.
2246 * @example ("p").empty()
2247 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2248 * @result [ <p></p> ]
2254 while ( this.firstChild )
2255 this.removeChild( this.firstChild );
2259 * Binds a particular event (like click) to a each of a set of match elements.
2261 * @example $("p").bind( "click", function() { alert("Hello"); } )
2262 * @before <p>Hello</p>
2263 * @result [ <p>Hello</p> ]
2265 * Cancel a default action and prevent it from bubbling by returning false
2266 * from your function.
2268 * @example $("form").bind( "submit", function() { return false; } )
2270 * Cancel a default action by using the preventDefault method.
2272 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2274 * Stop an event from bubbling by using the stopPropogation method.
2276 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2280 * @param String type An event type
2281 * @param Function fn A function to bind to the event on each of the set of matched elements
2283 bind: function( type, fn ) {
2284 if ( fn.constructor == String )
2285 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2286 jQuery.event.add( this, type, fn );
2290 * The opposite of bind, removes a bound event from each of the matched
2291 * elements. You must pass the identical function that was used in the original
2294 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2295 * @before <p onclick="alert('Hello');">Hello</p>
2296 * @result [ <p>Hello</p> ]
2300 * @param String type An event type
2301 * @param Function fn A function to unbind from the event on each of the set of matched elements
2305 * Removes all bound events of a particular type from each of the matched
2308 * @example $("p").unbind( "click" )
2309 * @before <p onclick="alert('Hello');">Hello</p>
2310 * @result [ <p>Hello</p> ]
2314 * @param String type An event type
2318 * Removes all bound events from each of the matched elements.
2320 * @example $("p").unbind()
2321 * @before <p onclick="alert('Hello');">Hello</p>
2322 * @result [ <p>Hello</p> ]
2327 unbind: function( type, fn ) {
2328 jQuery.event.remove( this, type, fn );
2332 * Trigger a type of event on every matched element.
2334 * @example $("p").trigger("click")
2335 * @before <p click="alert('hello')">Hello</p>
2336 * @result alert('hello')
2340 * @param String type An event type to trigger.
2342 trigger: function( type, data ) {
2343 jQuery.event.trigger( type, data, this );