Make .attr(name, null) equivalent to removeAttr(name). (Was roughly this before - but is now consistent across platforms). Fixes #6341.
This commit is contained in:
parent
cf672a2e7a
commit
c7c0677230
|
@ -295,8 +295,15 @@ jQuery.extend({
|
|||
jQuery.error( "type property can't be changed" );
|
||||
}
|
||||
|
||||
if ( value === null ) {
|
||||
if ( elem.nodeType === 1 ) {
|
||||
elem.removeAttribute( name );
|
||||
}
|
||||
|
||||
} else {
|
||||
elem[ name ] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// browsers index elements by id/name on forms, give priority to attributes.
|
||||
if ( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) {
|
||||
|
|
|
@ -98,15 +98,18 @@ test("attr(Hash)", function() {
|
|||
});
|
||||
|
||||
test("attr(String, Object)", function() {
|
||||
expect(23);
|
||||
expect(24);
|
||||
|
||||
var div = jQuery("div").attr("foo", "bar"),
|
||||
fail = false;
|
||||
|
||||
for ( var i = 0; i < div.size(); i++ ) {
|
||||
if ( div.get(i).getAttribute('foo') != "bar" ){
|
||||
fail = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
equals( fail, false, "Set Attribute, the #"+fail+" element didn't get the attribute 'foo'" );
|
||||
|
||||
// Fails on IE since recent changes to .attr()
|
||||
|
@ -114,6 +117,8 @@ test("attr(String, Object)", function() {
|
|||
|
||||
jQuery("#name").attr('name', 'something');
|
||||
equals( jQuery("#name").attr('name'), 'something', 'Set name attribute' );
|
||||
jQuery("#name").attr('name', null);
|
||||
equals( jQuery("#name").attr('title'), '', 'Remove name attribute' );
|
||||
jQuery("#check2").attr('checked', true);
|
||||
equals( document.getElementById('check2').checked, true, 'Set checked attribute' );
|
||||
jQuery("#check2").attr('checked', false);
|
||||
|
|
Loading…
Reference in a new issue