GetElementsByID vs. GetElementByName [English]

The title is obviously wrong. Actually you must say GetElementByName and GetElementsByName. This is just logical, since an ID number can only exist once, or may only exist once, while a name can exist several times. That’s why GetElementsByName produces an Array, even if there is only one element with this name.

<!-- http://de.selfhtml.org/javascript/objekte/document.htm#get_element_by_id -->

document.getElementById("unentschlossen").align = wie;

<!-- http://de.selfhtml.org/javascript/objekte/document.htm#get_elements_by_name -->

document.getElementsByName("Zutat")[0].checked = true;

Leave a Reply

Your email address will not be published. Required fields are marked *