I have this simple HTML/JS file that I’m working with. When I click the generate button, I should the output of the normalize
function shown as text on the screen, but that’s not happening. Can someone help me figure out why the p
element is not being updated?
function normalize(str) {
output = str.toLowerCase();
return output;
}
function generate() {
input = normalize(document.getElementById("input").value);
document.getElementById("output").textContents = input;
}
<div id="input_div">
<input type="text" size="25" id="input">
<input type="button" value="Generate" id="gen" onclick="generate()">
</div>
<p id="output"></p>
2
Answers
A typo.
The property you’re looking for is
textContent
nottextContents
.You can either use "textContent".
OR "innerHTML"