Javascript doesn't work in html file -
i have html file:
<html> <head> <script type="text/javascript" src="new.js"></script> </head> <body> <p id="contentbi" >you should click here! </p> </body> </html> and javascript file:
function doalert() { alert("hi!"); } function addevent () { thebi=document.getelementbyid("contentbi"); thebi.addeventlistener("click",doalert); } document.addeventlistener("load",addevent); javascript doesn't run.
use window.addeventlistener("load",addevent); instead of document.addeventlistener("load",addevent);
demo
Comments
Post a Comment