JavaScript getElementByName doesnt work
JavaScript getElementByName doesnt work
Its getElementsByName
. Note the plural. It returns an array-like NodeList of elements with that name
attribute.
getElementsByName
exists, which returns a collection of the elements. If you plan to find only one:
document.getElementsByName(hi)[0].setAttribute(value, my value is high);
Edit: a, HTML there (didnt see that before the edit). No hi element in HTML, possibly in some XML format there is…
JavaScript getElementByName doesnt work
not getElementByName
but getElementsByName
, and it returns array.
<html>
<head>
<script language=javascript>
function fn() {
document.getElementById(para).setAttribute(name,hi);
x = document.getElementsByName(hi);
x[0].setAttribute(value,my value is high);
}
</script>
</head>
<body onload=fn()>
<input type=text id=para />
</body>
</html>