By default, the checkbox is selected.

Is there a difference between the two default check methods:

document.getElementById(checkboxId).defaultChecked = checked; 

against

 document.getElementById(checkboxId).checked = checked; 
+6
source share
3 answers

I think it makes no difference if you use it as a setter. but if you use it as a getter, there will be a difference.

becouse.default Checked as a name that already tells you, checks the default value, not the current one.

-2
source

defaultChecked is the default state, checked is the current state.

If you change defaultChecked and then click <input type="reset"> , set the reset flag to the state specified in the defaultChecked property.

If you change checked , the state changes immediately.

+10
source

The defaultChecked property returns the default value of the checked attribute. This property returns true if the checkbox is selected by default, otherwise it returns false. http://www.w3schools.com/jsref/prop_checkbox_defaultchecked.asp

The checked property sets or returns the checked state of the flag. http://www.w3schools.com/jsref/prop_checkbox_checked.asp

+1
source

Source: https://habr.com/ru/post/910827/


All Articles