removeAttr('required') obsolete?

Asked

Viewed 169 times

5

I have the following line in my code:

$('#infs').removeAttr('required');

And when using the plugin jQuery Migrate, get the following Warning in debug:

JQMIGRATE: jQuery.fn.removeAttr no longer sets Boolean properties: required

1 answer

4


According to the page of warnings jQuery Migrate 3.0 plugin+

JQMIGRATE: jQuery.fn.removeAttr no longer sets boolean properties

Cause: Before jQuery 3.0, the use of .removeAttr() in an attribute boolean, as checked, selected or readonly would also define the corresponding property as false. This behavior was needed for older versions of Internet Explorer, but not correct for modern browsers because the attribute represents the value initial and property represents current value (dynamic).

Solution: almost always wrong to use .removeAttr("checked") in a element of the GIFT. The only time it can be useful is if the GIFT is later serialized back into an HTML string. In all other cases, should be used .prop("checked", false).

Therefore, the code below should solve:

$('#infs').prop('required', false);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.