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

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -