0

how to use keydown event if i change getElementById to getElementByTagName

snipping code from w3school

<script>
function keydownFunction() {
  document.getElementById("demo").style.backgroundColor = "red";
}

function keyupFunction() {
  document.getElementById("demo").style.backgroundColor = "green";
}
</script>

I changed to

<p>
<input type="text" id="demo" onkeydown="keydownFunction()" onkeyup="keyupFunction()">
</p>

<script>
function keydownFunction() {
  document.getElementsByTagName("p").style.backgroundColor = "red";
}

function keyupFunction() {
  document.getElementsByTagName("p").style.backgroundColor = "green";
}
</script>

and it doesnt work

adtybrhn
  • 23
  • 6

0 Answers0