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 ?
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 i = 0; i < a.length; i++ )
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.attr, function(i,n){
765 jQuery.fn[ i ] = function(h) {
766 return h == undefined ?
767 this.length ? this[0][n] : null :
772 jQuery.each( jQuery.macros.css, function(i,n){
773 jQuery.fn[ i ] = function(h) {
774 return h == undefined ?
775 ( this.length ? jQuery.css( this[0], n ) : null ) :
783 * A generic iterator function, which can be used to seemlessly
784 * iterate over both objects and arrays.
787 * @param Object obj The object, or array, to iterate over.
788 * @param Object fn The function that will be executed on every object.
791 each: function( obj, fn, args ) {
792 if ( obj.length == undefined )
794 fn.apply( obj[i], args || [i, obj[i]] );
796 for ( var i = 0; i < obj.length; i++ )
797 fn.apply( obj[i], args || [i, obj[i]] );
803 if (jQuery.className.has(o,c)) return;
804 o.className += ( o.className ? " " : "" ) + c;
806 remove: function(o,c){
807 o.className = !c ? "" :
809 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
814 return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
819 * Swap in/out style options.
822 swap: function(e,o,f) {
824 e.style["old"+i] = e.style[i];
829 e.style[i] = e.style["old"+i];
833 if ( p == "height" || p == "width" ) {
834 var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
837 old["padding" + d[i]] = 0;
838 old["border" + d[i] + "Width"] = 0;
841 jQuery.swap( e, old, function() {
842 if (jQuery.css(e,"display") != "none") {
843 oHeight = e.offsetHeight;
844 oWidth = e.offsetWidth;
846 jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "" },
848 oHeight = e.clientHeight;
849 oWidth = e.clientWidth;
853 return p == "height" ? oHeight : oWidth;
854 } else if ( p == "opacity" && jQuery.browser.msie )
855 return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
857 return jQuery.curCSS( e, p );
860 curCSS: function(e,p,force) {
863 if (!force && e.style[p])
865 else if (e.currentStyle) {
866 p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
867 r = e.currentStyle[p];
868 } else if (document.defaultView && document.defaultView.getComputedStyle) {
869 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
870 var s = document.defaultView.getComputedStyle(e,"");
871 r = s ? s.getPropertyValue(p) : null;
879 for ( var i = 0; i < a.length; i++ ) {
880 if ( a[i].constructor == String ) {
882 if ( !a[i].indexOf("<tr") ) {
884 a[i] = "<table>" + a[i] + "</table>";
885 } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
887 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
890 var div = document.createElement("div");
891 div.innerHTML = a[i];
894 div = div.firstChild.firstChild;
895 if ( td ) div = div.firstChild;
898 for ( var j = 0; j < div.childNodes.length; j++ )
899 r.push( div.childNodes[j] );
900 } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
901 for ( var k = 0; k < a[i].length; k++ )
903 else if ( a[i] !== null )
904 r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
910 "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
911 "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
919 last: "i==r.length-1",
924 "first-child": "jQuery.sibling(a,0).cur",
925 "last-child": "jQuery.sibling(a,0).last",
926 "only-child": "jQuery.sibling(a).length==1",
929 parent: "a.childNodes.length",
930 empty: "!a.childNodes.length",
933 contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
936 visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
937 hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
940 enabled: "!a.disabled",
941 disabled: "a.disabled",
944 ".": "jQuery.className.has(a,m[2])",
948 "^=": "!z.indexOf(m[4])",
949 "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
950 "*=": "z.indexOf(m[4])>=0",
953 "[": "jQuery.find(m[2],a).length"
957 "\\.\\.|/\\.\\.", "a.parentNode",
958 ">|/", "jQuery.sibling(a.firstChild)",
959 "\\+", "jQuery.sibling(a).next",
962 var s = jQuery.sibling(a);
964 for ( var i = s.n; i < s.length; i++ )
970 find: function( t, context ) {
971 // Make sure that the context is a DOM Element
972 if ( context && context.nodeType == undefined )
975 // Set the correct context (if none is provided)
976 context = context || jQuery.context || document;
978 if ( t.constructor != String ) return [t];
980 if ( !t.indexOf("//") ) {
981 context = context.documentElement;
982 t = t.substr(2,t.length);
983 } else if ( !t.indexOf("/") ) {
984 context = context.documentElement;
985 t = t.substr(1,t.length);
986 // FIX Assume the root element is right :(
987 if ( t.indexOf("/") >= 1 )
988 t = t.substr(t.indexOf("/"),t.length);
995 while ( t.length > 0 && last != t ) {
999 t = jQuery.trim(t).replace( /^\/\//i, "" );
1001 var foundToken = false;
1003 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
1004 var re = new RegExp("^(" + jQuery.token[i] + ")");
1008 r = ret = jQuery.map( ret, jQuery.token[i+1] );
1009 t = jQuery.trim( t.replace( re, "" ) );
1014 if ( !foundToken ) {
1015 if ( !t.indexOf(",") || !t.indexOf("|") ) {
1016 if ( ret[0] == context ) ret.shift();
1017 done = jQuery.merge( done, ret );
1018 r = ret = [context];
1019 t = " " + t.substr(1,t.length);
1021 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
1022 var m = re2.exec(t);
1024 if ( m[1] == "#" ) {
1025 // Ummm, should make this work in all XML docs
1026 var oid = document.getElementById(m[2]);
1027 r = ret = oid ? [oid] : [];
1028 t = t.replace( re2, "" );
1030 if ( !m[2] || m[1] == "." ) m[2] = "*";
1032 for ( var i = 0; i < ret.length; i++ )
1033 r = jQuery.merge( r,
1035 jQuery.getAll(ret[i]) :
1036 ret[i].getElementsByTagName(m[2])
1043 var val = jQuery.filter(t,r);
1045 t = jQuery.trim(val.t);
1049 if ( ret && ret[0] == context ) ret.shift();
1050 done = jQuery.merge( done, ret );
1055 getAll: function(o,r) {
1057 var s = o.childNodes;
1058 for ( var i = 0; i < s.length; i++ )
1059 if ( s[i].nodeType == 1 ) {
1061 jQuery.getAll( s[i], r );
1066 attr: function(o,a,v){
1067 if ( a && a.constructor == String ) {
1070 "class": "className",
1074 a = (fix[a] && fix[a].replace && fix[a] || a)
1075 .replace(/-([a-z])/ig,function(z,b){
1076 return b.toUpperCase();
1079 if ( v != undefined ) {
1081 if ( o.setAttribute && a != "disabled" )
1082 o.setAttribute(a,v);
1085 return o[a] || o.getAttribute && o.getAttribute(a) || "";
1090 // The regular expressions that power the parsing engine
1092 // Match: [@value='test'], [@foo]
1093 [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
1095 // Match: [div], [div p]
1098 // Match: :contains('foo')
1099 [ "(:)S\\(Q\\)", 0 ],
1101 // Match: :even, :last-chlid
1105 filter: function(t,r,not) {
1106 // Figure out if we're doing regular, or inverse, filtering
1107 var g = not !== false ? jQuery.grep :
1108 function(a,f) {return jQuery.grep(a,f,true);};
1110 while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
1112 var p = jQuery.parse;
1114 for ( var i = 0; i < p.length; i++ ) {
1115 var re = new RegExp( "^" + p[i][0]
1117 // Look for a string-like sequence
1118 .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
1120 // Look for something (optionally) enclosed with quotes
1121 .replace( 'Q', " *'?\"?([^'\"]*)'?\"? *" ), "i" );
1123 var m = re.exec( t );
1126 // Re-organize the match
1128 m = ["", m[1], m[3], m[2], m[4]];
1130 // Remove what we just matched
1131 t = t.replace( re, "" );
1137 // :not() is a special case that can be optomized by
1138 // keeping it out of the expression list
1139 if ( m[1] == ":" && m[2] == "not" )
1140 r = jQuery.filter(m[3],r,false).r;
1142 // Otherwise, find the expression to execute
1144 var f = jQuery.expr[m[1]];
1145 if ( f.constructor != String )
1146 f = jQuery.expr[m[1]][m[2]];
1148 // Build a custom macro to enclose it
1149 eval("f = function(a,i){" +
1150 ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
1151 "return " + f + "}");
1153 // Execute it against the current filter
1158 // Return an array of filtered elements (r)
1159 // and the modified expression string (t)
1160 return { r: r, t: t };
1164 * Remove the whitespace from the beginning and end of a string.
1169 * @param String str The string to trim.
1172 return t.replace(/^\s+|\s+$/g, "");
1176 * All ancestors of a given element.
1180 * @type Array<Element>
1181 * @param Element elem The element to find the ancestors of.
1183 parents: function(a){
1185 var c = a.parentNode;
1186 while ( c && c != document ) {
1194 * All elements on a specified axis.
1199 * @param Element elem The element to find all the siblings of (including itself).
1201 sibling: function(a,n) {
1203 var tmp = a.parentNode.childNodes;
1204 for ( var i = 0; i < tmp.length; i++ ) {
1205 if ( tmp[i].nodeType == 1 )
1206 type.push( tmp[i] );
1208 type.n = type.length - 1;
1210 type.last = type.n == type.length - 1;
1212 n == "even" && type.n % 2 == 0 ||
1213 n == "odd" && type.n % 2 ||
1215 type.prev = type[type.n - 1];
1216 type.next = type[type.n + 1];
1221 * Merge two arrays together, removing all duplicates.
1226 * @param Array a The first array to merge.
1227 * @param Array b The second array to merge.
1229 merge: function(a,b) {
1232 // Move b over to the new array (this helps to avoid
1233 // StaticNodeList instances)
1234 for ( var k = 0; k < b.length; k++ )
1237 // Now check for duplicates between a and b and only
1238 // add the unique items
1239 for ( var i = 0; i < a.length; i++ ) {
1242 // The collision-checking process
1243 for ( var j = 0; j < b.length; j++ )
1247 // If the item is unique, add it
1256 * Remove items that aren't matched in an array. The function passed
1257 * in to this method will be passed two arguments: 'a' (which is the
1258 * array item) and 'i' (which is the index of the item in the array).
1263 * @param Array array The Array to find items in.
1264 * @param Function fn The function to process each item against.
1265 * @param Boolean inv Invert the selection - select the opposite of the function.
1267 grep: function(a,f,s) {
1268 // If a string is passed in for the function, make a function
1269 // for it (a handy shortcut)
1270 if ( f.constructor == String )
1271 f = new Function("a","i","return " + f);
1275 // Go through the array, only saving the items
1276 // that pass the validator function
1277 for ( var i = 0; i < a.length; i++ )
1278 if ( !s && f(a[i],i) || s && !f(a[i],i) )
1285 * Translate all items in array to another array of items. The translation function
1286 * that is provided to this method is passed one argument: 'a' (the item to be
1287 * translated). If an array is returned, that array is mapped out and merged into
1288 * the full array. Additionally, returning 'null' or 'undefined' will delete the item
1289 * from the array. Both of these changes imply that the size of the array may not
1290 * be the same size upon completion, as it was when it started.
1295 * @param Array array The Array to translate.
1296 * @param Function fn The function to process each item against.
1298 map: function(a,f) {
1299 // If a string is passed in for the function, make a function
1300 // for it (a handy shortcut)
1301 if ( f.constructor == String )
1302 f = new Function("a","return " + f);
1306 // Go through the array, translating each of the items to their
1307 // new value (or values).
1308 for ( var i = 0; i < a.length; i++ ) {
1310 if ( t !== null && t != undefined ) {
1311 if ( t.constructor != Array ) t = [t];
1312 r = jQuery.merge( t, r );
1319 * A number of helper functions used for managing events.
1320 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
1324 // Bind an event to an element
1325 // Original by Dean Edwards
1326 add: function(element, type, handler) {
1327 // For whatever reason, IE has trouble passing the window object
1328 // around, causing it to be cloned in the process
1329 if ( jQuery.browser.msie && element.setInterval != undefined )
1332 // Make sure that the function being executed has a unique ID
1333 if ( !handler.guid )
1334 handler.guid = this.guid++;
1336 // Init the element's event structure
1337 if (!element.events)
1338 element.events = {};
1340 // Get the current list of functions bound to this event
1341 var handlers = element.events[type];
1343 // If it hasn't been initialized yet
1345 // Init the event handler queue
1346 handlers = element.events[type] = {};
1348 // Remember an existing handler, if it's already there
1349 if (element["on" + type])
1350 handlers[0] = element["on" + type];
1353 // Add the function to the element's handler list
1354 handlers[handler.guid] = handler;
1356 // And bind the global event handler to the element
1357 element["on" + type] = this.handle;
1359 // Remember the function in a global list (for triggering)
1360 if (!this.global[type])
1361 this.global[type] = [];
1362 this.global[type].push( element );
1368 // Detach an event or set of events from an element
1369 remove: function(element, type, handler) {
1371 if (type && element.events[type])
1373 delete element.events[type][handler.guid];
1375 for ( var i in element.events[type] )
1376 delete element.events[type][i];
1378 for ( var j in element.events )
1379 this.remove( element, j );
1382 trigger: function(type,data,element) {
1383 // Touch up the incoming data
1386 // Handle a global trigger
1388 var g = this.global[type];
1390 for ( var i = 0; i < g.length; i++ )
1391 this.trigger( type, data, g[i] );
1393 // Handle triggering a single element
1394 } else if ( element["on" + type] ) {
1395 // Pass along a fake event
1396 data.unshift( this.fix({ type: type, target: element }) );
1398 // Trigger the event
1399 element["on" + type].apply( element, data );
1403 handle: function(event) {
1404 if ( typeof jQuery == "undefined" ) return;
1406 event = event || jQuery.event.fix( window.event );
1408 // If no correct event was found, fail
1409 if ( !event ) return;
1411 var returnValue = true;
1413 var c = this.events[event.type];
1415 for ( var j in c ) {
1416 if ( c[j].apply( this, [event] ) === false ) {
1417 event.preventDefault();
1418 event.stopPropagation();
1419 returnValue = false;
1426 fix: function(event) {
1428 event.preventDefault = function() {
1429 this.returnValue = false;
1432 event.stopPropagation = function() {
1433 this.cancelBubble = true;
1444 var b = navigator.userAgent.toLowerCase();
1446 // Figure out what browser is being used
1448 safari: /webkit/.test(b),
1449 opera: /opera/.test(b),
1450 msie: /msie/.test(b) && !/opera/.test(b),
1451 mozilla: /mozilla/.test(b) && !/compatible/.test(b)
1454 // Check to see if the W3C box model is being used
1455 jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
1461 * Append all of the matched elements to another, specified, set of elements.
1462 * This operation is, essentially, the reverse of doing a regular
1463 * $(A).append(B), in that instead of appending B to A, you're appending
1466 * @example $("p").appendTo("#foo");
1467 * @before <p>I would like to say: </p><div id="foo"></div>
1468 * @result <div id="foo"><p>I would like to say: </p></div>
1472 * @param String expr A jQuery expression of elements to match.
1477 * Prepend all of the matched elements to another, specified, set of elements.
1478 * This operation is, essentially, the reverse of doing a regular
1479 * $(A).prepend(B), in that instead of prepending B to A, you're prepending
1482 * @example $("p").prependTo("#foo");
1483 * @before <p>I would like to say: </p><div id="foo"><b>Hello</b></div>
1484 * @result <div id="foo"><p>I would like to say: </p><b>Hello</b></div>
1488 * @param String expr A jQuery expression of elements to match.
1490 prepend: "prependTo",
1493 * Insert all of the matched elements before another, specified, set of elements.
1494 * This operation is, essentially, the reverse of doing a regular
1495 * $(A).before(B), in that instead of inserting B before A, you're inserting
1498 * @example $("p").insertBefore("#foo");
1499 * @before <div id="foo">Hello</div><p>I would like to say: </p>
1500 * @result <p>I would like to say: </p><div id="foo">Hello</div>
1502 * @name insertBefore
1504 * @param String expr A jQuery expression of elements to match.
1506 before: "insertBefore",
1509 * Insert all of the matched elements after another, specified, set of elements.
1510 * This operation is, essentially, the reverse of doing a regular
1511 * $(A).after(B), in that instead of inserting B after A, you're inserting
1514 * @example $("p").insertAfter("#foo");
1515 * @before <p>I would like to say: </p><div id="foo">Hello</div>
1516 * @result <div id="foo">Hello</div><p>I would like to say: </p>
1520 * @param String expr A jQuery expression of elements to match.
1522 after: "insertAfter"
1526 * Get the current CSS width of the first matched element.
1528 * @example $("p").width();
1529 * @before <p>This is just a test.</p>
1537 * Set the CSS width of every matched element. Be sure to include
1538 * the "px" (or other unit of measurement) after the number that you
1539 * specify, otherwise you might get strange results.
1541 * @example $("p").width("20px");
1542 * @before <p>This is just a test.</p>
1543 * @result <p style="width:20px;">This is just a test.</p>
1547 * @param String val Set the CSS property to the specified value.
1551 * Get the current CSS height of the first matched element.
1553 * @example $("p").height();
1554 * @before <p>This is just a test.</p>
1562 * Set the CSS height of every matched element. Be sure to include
1563 * the "px" (or other unit of measurement) after the number that you
1564 * specify, otherwise you might get strange results.
1566 * @example $("p").height("20px");
1567 * @before <p>This is just a test.</p>
1568 * @result <p style="height:20px;">This is just a test.</p>
1572 * @param String val Set the CSS property to the specified value.
1576 * Get the current CSS top of the first matched element.
1578 * @example $("p").top();
1579 * @before <p>This is just a test.</p>
1587 * Set the CSS top of every matched element. Be sure to include
1588 * the "px" (or other unit of measurement) after the number that you
1589 * specify, otherwise you might get strange results.
1591 * @example $("p").top("20px");
1592 * @before <p>This is just a test.</p>
1593 * @result <p style="top:20px;">This is just a test.</p>
1597 * @param String val Set the CSS property to the specified value.
1601 * Get the current CSS left of the first matched element.
1603 * @example $("p").left();
1604 * @before <p>This is just a test.</p>
1612 * Set the CSS left of every matched element. Be sure to include
1613 * the "px" (or other unit of measurement) after the number that you
1614 * specify, otherwise you might get strange results.
1616 * @example $("p").left("20px");
1617 * @before <p>This is just a test.</p>
1618 * @result <p style="left:20px;">This is just a test.</p>
1622 * @param String val Set the CSS property to the specified value.
1626 * Get the current CSS position of the first matched element.
1628 * @example $("p").position();
1629 * @before <p>This is just a test.</p>
1637 * Set the CSS position of every matched element.
1639 * @example $("p").position("relative");
1640 * @before <p>This is just a test.</p>
1641 * @result <p style="position:relative;">This is just a test.</p>
1645 * @param String val Set the CSS property to the specified value.
1649 * Get the current CSS float of the first matched element.
1651 * @example $("p").float();
1652 * @before <p>This is just a test.</p>
1660 * Set the CSS float of every matched element.
1662 * @example $("p").float("left");
1663 * @before <p>This is just a test.</p>
1664 * @result <p style="float:left;">This is just a test.</p>
1668 * @param String val Set the CSS property to the specified value.
1672 * Get the current CSS overflow of the first matched element.
1674 * @example $("p").overflow();
1675 * @before <p>This is just a test.</p>
1683 * Set the CSS overflow of every matched element.
1685 * @example $("p").overflow("auto");
1686 * @before <p>This is just a test.</p>
1687 * @result <p style="overflow:auto;">This is just a test.</p>
1691 * @param String val Set the CSS property to the specified value.
1695 * Get the current CSS color of the first matched element.
1697 * @example $("p").color();
1698 * @before <p>This is just a test.</p>
1706 * Set the CSS color of every matched element.
1708 * @example $("p").color("blue");
1709 * @before <p>This is just a test.</p>
1710 * @result <p style="color:blue;">This is just a test.</p>
1714 * @param String val Set the CSS property to the specified value.
1718 * Get the current CSS background of the first matched element.
1720 * @example $("p").background();
1721 * @before <p>This is just a test.</p>
1729 * Set the CSS background of every matched element.
1731 * @example $("p").background("blue");
1732 * @before <p>This is just a test.</p>
1733 * @result <p style="background:blue;">This is just a test.</p>
1737 * @param String val Set the CSS property to the specified value.
1740 css: "width,height,top,left,position,float,overflow,color,background".split(","),
1744 * Get the current value of the first matched element.
1746 * @example $("input").val();
1747 * @before <input type="text" value="some text"/>
1748 * @result "some text"
1755 * Set the value of every matched element.
1757 * @example $("input").value("test");
1758 * @before <input type="text" value="some text"/>
1759 * @result <input type="text" value="test"/>
1763 * @param String val Set the property to the specified value.
1768 * Get the html contents of the first matched element.
1770 * @example $("div").html();
1771 * @before <div><input/></div>
1779 * Set the html contents of every matched element.
1781 * @example $("div").html("<b>new stuff</b>");
1782 * @before <div><input/></div>
1783 * @result <div><b>new stuff</b</div>
1787 * @param String val Set the html contents to the specified value.
1792 * Get the current id of the first matched element.
1794 * @example $("input").id();
1795 * @before <input type="text" id="test" value="some text"/>
1803 * Set the id of every matched element.
1805 * @example $("input").id("newid");
1806 * @before <input type="text" id="test" value="some text"/>
1807 * @result <input type="text" id="newid" value="some text"/>
1811 * @param String val Set the property to the specified value.
1816 * Get the current title of the first matched element.
1818 * @example $("img").title();
1819 * @before <img src="test.jpg" title="my image"/>
1820 * @result "my image"
1827 * Set the title of every matched element.
1829 * @example $("img").title("new title");
1830 * @before <img src="test.jpg" title="my image"/>
1831 * @result <img src="test.jpg" title="new image"/>
1835 * @param String val Set the property to the specified value.
1840 * Get the current name of the first matched element.
1842 * @example $("input").name();
1843 * @before <input type="text" name="username"/>
1844 * @result "username"
1851 * Set the name of every matched element.
1853 * @example $("input").name("user");
1854 * @before <input type="text" name="username"/>
1855 * @result <input type="text" name="user"/>
1859 * @param String val Set the property to the specified value.
1864 * Get the current href of the first matched element.
1866 * @example $("a").href();
1867 * @before <a href="test.html">my link</a>
1868 * @result "test.html"
1875 * Set the href of every matched element.
1877 * @example $("a").href("test2.html");
1878 * @before <a href="test.html">my link</a>
1879 * @result <a href="test2.html">my link</a>
1883 * @param String val Set the property to the specified value.
1888 * Get the current src of the first matched element.
1890 * @example $("img").src();
1891 * @before <img src="test.jpg" title="my image"/>
1892 * @result "test.jpg"
1899 * Set the src of every matched element.
1901 * @example $("img").src("test2.jpg");
1902 * @before <img src="test.jpg" title="my image"/>
1903 * @result <img src="test2.jpg" title="my image"/>
1907 * @param String val Set the property to the specified value.
1912 * Get the current rel of the first matched element.
1914 * @example $("a").rel();
1915 * @before <a href="test.html" rel="nofollow">my link</a>
1916 * @result "nofollow"
1923 * Set the rel of every matched element.
1925 * @example $("a").rel("nofollow");
1926 * @before <a href="test.html">my link</a>
1927 * @result <a href="test.html" rel="nofollow">my link</a>
1931 * @param String val Set the property to the specified value.
1938 * Get a set of elements containing the unique parents of the matched
1941 * @example $("p").parent()
1942 * @before <div><p>Hello</p><p>Hello</p></div>
1943 * @result [ <div><p>Hello</p><p>Hello</p></div> ]
1950 * Get a set of elements containing the unique parents of the matched
1951 * set of elements, and filtered by an expression.
1953 * @example $("p").parent(".selected")
1954 * @before <div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
1955 * @result [ <div class="selected"><p>Hello Again</p></div> ]
1959 * @param String expr An expression to filter the parents with
1961 parent: "a.parentNode",
1964 * Get a set of elements containing the unique ancestors of the matched
1967 * @example $("span").ancestors()
1968 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1969 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
1976 * Get a set of elements containing the unique ancestors of the matched
1977 * set of elements, and filtered by an expression.
1979 * @example $("span").ancestors("p")
1980 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1981 * @result [ <p><span>Hello</span></p> ]
1985 * @param String expr An expression to filter the ancestors with
1987 ancestors: jQuery.parents,
1990 * Get a set of elements containing the unique ancestors of the matched
1993 * @example $("span").ancestors()
1994 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
1995 * @result [ <body>...</body>, <div>...</div>, <p><span>Hello</span></p> ]
2002 * Get a set of elements containing the unique ancestors of the matched
2003 * set of elements, and filtered by an expression.
2005 * @example $("span").ancestors("p")
2006 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
2007 * @result [ <p><span>Hello</span></p> ]
2011 * @param String expr An expression to filter the ancestors with
2013 parents: jQuery.parents,
2016 * Get a set of elements containing the unique next siblings of each of the
2017 * matched set of elements.
2019 * It only returns the very next sibling, not all next siblings.
2021 * @example $("p").next()
2022 * @before <p>Hello</p><p>Hello Again</p><div><span>And Again</span></div>
2023 * @result [ <p>Hello Again</p>, <div><span>And Again</span></div> ]
2030 * Get a set of elements containing the unique next siblings of each of the
2031 * matched set of elements, and filtered by an expression.
2033 * It only returns the very next sibling, not all next siblings.
2035 * @example $("p").next(".selected")
2036 * @before <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>
2037 * @result [ <p class="selected">Hello Again</p> ]
2041 * @param String expr An expression to filter the next Elements with
2043 next: "jQuery.sibling(a).next",
2046 * Get a set of elements containing the unique previous siblings of each of the
2047 * matched set of elements.
2049 * It only returns the immediately previous sibling, not all previous siblings.
2051 * @example $("p").previous()
2052 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2053 * @result [ <div><span>Hello Again</span></div> ]
2060 * Get a set of elements containing the unique previous siblings of each of the
2061 * matched set of elements, and filtered by an expression.
2063 * It only returns the immediately previous sibling, not all previous siblings.
2065 * @example $("p").previous(".selected")
2066 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2067 * @result [ <div><span>Hello</span></div> ]
2071 * @param String expr An expression to filter the previous Elements with
2073 prev: "jQuery.sibling(a).prev",
2076 * Get a set of elements containing all of the unique siblings of each of the
2077 * matched set of elements.
2079 * @example $("div").siblings()
2080 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2081 * @result [ <p>Hello</p>, <p>And Again</p> ]
2088 * Get a set of elements containing all of the unique siblings of each of the
2089 * matched set of elements, and filtered by an expression.
2091 * @example $("div").siblings(".selected")
2092 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
2093 * @result [ <p class="selected">Hello Again</p> ]
2097 * @param String expr An expression to filter the sibling Elements with
2099 siblings: jQuery.sibling,
2103 * Get a set of elements containing all of the unique children of each of the
2104 * matched set of elements.
2106 * @example $("div").children()
2107 * @before <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
2108 * @result [ <span>Hello Again</span> ]
2115 * Get a set of elements containing all of the unique siblings of each of the
2116 * matched set of elements, and filtered by an expression.
2118 * @example $("div").children(".selected")
2119 * @before <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
2120 * @result [ <p class="selected">Hello Again</p> ]
2124 * @param String expr An expression to filter the child Elements with
2126 children: "a.childNodes"
2131 * Displays each of the set of matched elements if they are hidden.
2133 * @example $("p").show()
2134 * @before <p style="display: none">Hello</p>
2135 * @result [ <p style="display: block">Hello</p> ]
2141 this.style.display = this.oldblock ? this.oldblock : "";
2142 if ( jQuery.css(this,"display") == "none" )
2143 this.style.display = "block";
2147 * Hides each of the set of matched elements if they are shown.
2149 * @example $("p").hide()
2150 * @before <p>Hello</p>
2151 * @result [ <p style="display: none">Hello</p> ]
2157 this.oldblock = this.oldblock || jQuery.css(this,"display");
2158 if ( this.oldblock == "none" )
2159 this.oldblock = "block";
2160 this.style.display = "none";
2164 * Toggles each of the set of matched elements. If they are shown,
2165 * toggle makes them hidden. If they are hidden, toggle
2168 * @example $("p").toggle()
2169 * @before <p>Hello</p><p style="display: none">Hello Again</p>
2170 * @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
2176 var d = jQuery.css(this,"display");
2177 $(this)[ !d || d == "none" ? "show" : "hide" ]();
2181 * Adds the specified class to each of the set of matched elements.
2183 * @example ("p").addClass("selected")
2184 * @before <p>Hello</p>
2185 * @result [ <p class="selected">Hello</p> ]
2189 * @param String class A CSS class to add to the elements
2191 addClass: function(c){
2192 jQuery.className.add(this,c);
2196 * The opposite of addClass. Removes the specified class from the
2197 * set of matched elements.
2199 * @example ("p").removeClass("selected")
2200 * @before <p class="selected">Hello</p>
2201 * @result [ <p>Hello</p> ]
2205 * @param String class A CSS class to remove from the elements
2207 removeClass: function(c){
2208 jQuery.className.remove(this,c);
2212 * Adds the specified class if it is present. Remove it if it is
2215 * @example ("p").toggleClass("selected")
2216 * @before <p>Hello</p><p class="selected">Hello Again</p>
2217 * @result [ <p class="selected">Hello</p>, <p>Hello Again</p> ]
2221 * @param String class A CSS class with which to toggle the elements
2223 toggleClass: function( c ){
2224 jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
2230 remove: function(a){
2231 if ( !a || jQuery.filter( [this], a ).r )
2232 this.parentNode.removeChild( this );
2236 * Removes all child nodes from the set of matched elements.
2238 * @example ("p").empty()
2239 * @before <p>Hello, <span>Person</span> <a href="#">and person</a></p>
2240 * @result [ <p></p> ]
2246 while ( this.firstChild )
2247 this.removeChild( this.firstChild );
2251 * Binds a particular event (like click) to a each of a set of match elements.
2253 * @example $("p").bind( "click", function() { alert("Hello"); } )
2254 * @before <p>Hello</p>
2255 * @result [ <p>Hello</p> ]
2257 * Cancel a default action and prevent it from bubbling by returning false
2258 * from your function.
2260 * @example $("form").bind( "submit", function() { return false; } )
2262 * Cancel a default action by using the preventDefault method.
2264 * @example $("form").bind( "submit", function() { e.preventDefault(); } )
2266 * Stop an event from bubbling by using the stopPropogation method.
2268 * @example $("form").bind( "submit", function() { e.stopPropogation(); } )
2272 * @param String type An event type
2273 * @param Function fn A function to bind to the event on each of the set of matched elements
2275 bind: function( type, fn ) {
2276 if ( fn.constructor == String )
2277 fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
2278 jQuery.event.add( this, type, fn );
2282 * The opposite of bind, removes a bound event from each of the matched
2283 * elements. You must pass the identical function that was used in the original
2286 * @example $("p").unbind( "click", function() { alert("Hello"); } )
2287 * @before <p onclick="alert('Hello');">Hello</p>
2288 * @result [ <p>Hello</p> ]
2292 * @param String type An event type
2293 * @param Function fn A function to unbind from the event on each of the set of matched elements
2297 * Removes all bound events of a particular type from each of the matched
2300 * @example $("p").unbind( "click" )
2301 * @before <p onclick="alert('Hello');">Hello</p>
2302 * @result [ <p>Hello</p> ]
2306 * @param String type An event type
2310 * Removes all bound events from each of the matched elements.
2312 * @example $("p").unbind()
2313 * @before <p onclick="alert('Hello');">Hello</p>
2314 * @result [ <p>Hello</p> ]
2319 unbind: function( type, fn ) {
2320 jQuery.event.remove( this, type, fn );
2324 * Trigger a type of event on every matched element.
2326 * @example $("p").trigger("click")
2327 * @before <p click="alert('hello')">Hello</p>
2328 * @result alert('hello')
2332 * @param String type An event type to trigger.
2334 trigger: function( type, data ) {
2335 jQuery.event.trigger( type, data, this );