X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fattributes.js;h=f463b4afba70fa5992c19c2dce061a3a0de8f43d;hb=b50f41a2e3ba9ab9a7bcf69a9633b0a8258015d6;hp=4393a9fdbc38a449f279d752a83e218db8ab3efb;hpb=086822e6419c89c33b322bacbbc891148a4b3647;p=jquery.git diff --git a/src/attributes.js b/src/attributes.js index 4393a9f..f463b4a 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -55,7 +55,9 @@ jQuery.fn.extend({ elem.className = value; } else { - var className = " " + elem.className + " ", setClass = elem.className; + var className = " " + elem.className + " ", + setClass = elem.className; + for ( var c = 0, cl = classNames.length; c < cl; c++ ) { if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) { setClass += " " + classNames[c]; @@ -103,7 +105,8 @@ jQuery.fn.extend({ }, toggleClass: function( value, stateVal ) { - var type = typeof value, isBool = typeof stateVal === "boolean"; + var type = typeof value, + isBool = typeof stateVal === "boolean"; if ( jQuery.isFunction( value ) ) { return this.each(function(i) { @@ -115,7 +118,9 @@ jQuery.fn.extend({ return this.each(function() { if ( type === "string" ) { // toggle individual class names - var className, i = 0, self = jQuery(this), + var className, + i = 0, + self = jQuery( this ), state = stateVal, classNames = value.split( rspaces ); @@ -200,7 +205,6 @@ jQuery.fn.extend({ if ( rradiocheck.test( elem.type ) && !jQuery.support.checkOn ) { return elem.getAttribute("value") === null ? "on" : elem.value; } - // Everything else, we just grab the value return (elem.value || "").replace(rreturn, ""); @@ -266,7 +270,7 @@ jQuery.extend({ height: true, offset: true }, - + attr: function( elem, name, value, pass ) { // don't set attributes on text and comment nodes if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) { @@ -295,7 +299,7 @@ jQuery.extend({ var parent = elem.parentNode; if ( parent ) { parent.selectedIndex; - + // Make sure that it also works with optgroups, see #5701 if ( parent.parentNode ) { parent.parentNode.selectedIndex; @@ -369,6 +373,11 @@ jQuery.extend({ // Non-existent attributes return null, we normalize to undefined return attr === null ? undefined : attr; } + // Handle everything which isn't a DOM element node + if ( set ) { + elem[ name ] = value; + } + return elem[ name ]; } });