mukesh kumar

mukesh kumar

  • NA
  • 259
  • 2.1k

addEventListener not working on content page.

Oct 6 2018 10:58 PM
when i run this code on asp.net content page then it's not working and error message comes that "0x800a1391 - JavaScript runtime error: 'btn' is undefined" but when i run this code on html page then it's execute without any errors.
 
<input type="button" value="Click" id="btn" />
<script type="text/javascript">
btn.addEventListener("mouseover", changeColorOnMouseOver, false);
btn.addEventListener("mouseout", changeColorOnMouseOut, false);

function changeColorOnMouseOver() {
this.style.background = 'red';
this.style.color = 'yellow';
}

function changeColorOnMouseOut() {
this.style.background = 'black';
this.style.color = 'white';
}
</script> 

Answers (1)