John Resig schrieb: > Hey everyone - > > I stumbled across a point of optimization today, all of the following > attributes (and probably more - let me know) can only have a single > value. > > checked="checked" > multiple="multiple" > disabled="disabled" > readonly="readonly" > disabled="disabled" > selected="selected" > > I'd like to add in methods like: > .checked( true | false ) > > Which does this in the background (but for each attribute): > > $.fn.checked = function(b) { > if ( b ) > this.attr( "checked", "checked" ); > else > this.removeAttr( "checked" ); > }; > > What do you think?
John, these are great additions, but please be advised that in some browsers this.attr('checked', 'checked') won't work as expected. I suggest that way (unless the fix is already done in attr which I don't quite remember right now): if ( b ) this.checked = true; else this.checked = false; I think if you want to completely remove the attribute you can use removeAttr but that has to be distinguished from setting the value to false. -- Klaus _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/