is there a way to set the checkbox checked by default with the name attribute not class or id ?
<input type="checkbox" name="test">
i tried this but doesn’t work:
document.getElementByName("test").checked = true;
Please provide a jsfiddle.
Thanks in advance!
Yes, it is possible. However, there is no
getElementByNamemethod, there is onlygetElementsByName. So if you have a single element with name"test", you can do:Otherwise, you can set an ID to the element and use
document.getElementById.DEMO: http://jsfiddle.net/GKFcR/