Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removeAttr(x) vs. attr(x, '') in jQuery

Tags:

jquery

Is there generally a difference between removeAttr(x) and attr(x, '') in jQuery?

If so, when to use each one?

like image 236
JoelFan Avatar asked Nov 18 '10 16:11

JoelFan


1 Answers

Given that the defninition of removeAttr from the jQuery library (see below). I'd say yes.

removeAttr: function( name, fn ) {
        return this.each(function(){
            jQuery.attr( this, name, "" );
            if ( this.nodeType === 1 ) {
                this.removeAttribute( name );
            }
        });

Source: Jquery 1.4.3 uncompressed version

Although it is inherently subjective. I think using removeAttr is a more self-documenting approach. However, I could see other people thinking the opposite.

like image 61
JohnFx Avatar answered Oct 30 '22 15:10

JohnFx