Is there generally a difference between removeAttr(x)
and attr(x, '')
in jQuery?
If so, when to use each one?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With