Reference Link: https://stackoverflow.com/questions/10650233/checked-checked-vs-checked-true
Ask:
1 What's the difference between the below and the usages? 2 3 document.getElementById (' MyRadio '). Checked = "Checked"; 4 and 5 6 document.getElementById (' MyRadio '). Checked = true; 7 for me, both is behaving the same. But, I am just curious to know why there exist and methods to do the same. 8 9 Which one would be the ideal usage? I need to support IE7 and higher versions.
View Code
For:
1 document.getElementById (' MyRadio '). Checked is a Boolean value. It should be true or False23document.getElementById (' MyRadio '). Checked = "checked"; casts The string to a Boolean, which is true. 4 5 document.getElementById (' MyRadio '). Checked = true; just assigns true without casting. 6 7 Use True as it was marginally more efficient and was more intention revealing to maintainers.
View Code
document.getElementById (' MyRadio '). Checked is a Boolean value . It's supposed to be real or fake.
document.getElementById (' MyRadio '). Checked = "Checked"; Converts a string to a Boolean value, which is correct.
document.getElementById (' MyRadio '). Checked = true; Just assign true without projecting.
Use True because it is a bit more efficient and more intended for maintainers to show.
So setting the value of this single attribute to True or false is the right one .
The property has only one value for this type of HTML property, and how to set the value; for example: checked = "checked" vs checked = True