removeAttr ('required') obsolete?

5

I have the following line in my code:

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

And when I use the jQuery Migrate plugin, I get the following warning in the debug:

  

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

    
asked by anonymous 25.07.2017 / 17:21

1 answer

4

According to warnings page plugin jQuery Migrate 3.0 +

  

JQMIGRATE: jQuery.fn.removeAttr does not define any more Boolean properties

     

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

     

Solution: It is almost always wrong to use .removeAttr("checked") in one   element of the DOM. The only time that might be useful is if the DOM is   then serialized back to an HTML string. In all   the other cases, should be used .prop("checked", false) .

Therefore, the code below should resolve:

$('#infs').prop('required', false);
    
25.07.2017 / 18:00