No warning from jquery Migrate plug-in when using removeProp() incorrectly

380 views Asked by At

Before I explain the issue let me tell you I am clearly aware that jQuery removeProp should not be used on native properties such as disabled, checked and selected. https://api.jquery.com/removeProp/

We upgraded the jQuery from 1.12.3 to 3.6.0. We used the JQuery migrate plug-in to identify compatibility issues and fix all the warnings generated in console.

$(“#x”).removeProp(“disabled”) did work in 1.12.3 and stopped working after upgrading to latest version. But we were not able to identify the issue unless we tested the pages manually. I want to know why jQuery migrate plug-in did not give us a warning regarding the same.

I know we used it wrongly before and we are happy to correct it to $(“#x”).prop(“disabled”,false)

1

There are 1 answers

0
Akshay G On BEST ANSWER

This is an explanation, by Timmy Willison from jQuery Core Team in this bug report https://github.com/jquery/jquery/issues/4887

I think this is just a docs issue. We should change that to say "This can remove the property completely or have no effect at all." I followed the code and it's just calling delete, which is the right thing. 1.x used to set properties to undefined for old IE, which is no longer necessary and technically invalid.

That said, this is somewhat moot. The reason needs updating, but the recommendation remains valid. There's no reason you should need to remove a native property (nor should you expect that to work–Blink is making it impossible anyway). It's not the same as removing a content attribute, which would actually set the corresponding property to false. Setting to false is the right thing here.

The issue raised resulted in the change in the documentation of .removeProp(). https://github.com/jquery/api.jquery.com/pull/1189