When you want to use Javascript to change HTML, how do you know when to use either of the following?
document.getElementById("randomNumber").value = number;
document.getElementById("randomNumber").innerHTML = number;
When you want to use Javascript to change HTML, how do you know when to use either of the following?
document.getElementById("randomNumber").value = number;
document.getElementById("randomNumber").innerHTML = number;
Setting the value is normally used for input/form elements. innerHTML is normally used for div, span, td and similar elements.
Here is a link showing the use of ID.value: http://www.javascript-coder.com/javascript-form/javascript-form-value.phtml
It's a little late for him but I was also looking for an answer and I think according to Skyrim answer It is possible to do something like this Thanks
function enterValue() {
var childNodes = document.body.childNodes;
for (x of childNodes) {
if(x.nodeName=="INPUT"){
// element is an INPUT html tag
x.value = "my input value";
}else{
// element is anything other than an INPUT
x.innerHTML = "my input value";
}
}
}
<!DOCTYPE html>
<html>
<body>
<input name="mInput" />
<div></div>
<p id="demo"></p>
<input type="button" onclick="enterValue()" value="enterValue">
</body>
</html>