+ 2

I am not able to see the alert pop up window ..why??

<button onclick ="alert()">explore</button> <script> function alert () { document.getElementbyId("demo").innerHTML =alert(); } </script> <p id ="demo"> </p>

7th Apr 2018, 2:21 PM
mohd shahnawaz
mohd shahnawaz - avatar
3 Respostas
+ 6
Spelling of getElementById is wrong(b in by should be capital) You named the function alert and it calls itself and thus keeps on calling itself and after a specific no of iterations, it the interpreter gives error. You overrided the alert function (the one that should show a pop up box) with a function you created now it cant call the original alert. Why are you doing this : document.getElementById("demo").innerHTML=alert(); The function you defined does not return anything and the original alert function also does not return anything. After fixing the above bugs also, undefined will be written to the p with id demo.
7th Apr 2018, 4:10 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 2
change the function from alert to something else...^_^
7th Apr 2018, 3:09 PM
Rohit
Rohit - avatar
+ 1
ty swapnil
7th Apr 2018, 4:12 PM
mohd shahnawaz
mohd shahnawaz - avatar