+ 3

Why is button onclick saying function does not exist?

Here is my code. Please copy the code and paste it and run the code to check the problem. Please tell me why this is happening. My code says the function event() does not exist even though i defined the function. <!DOCTYPE html> <html> <head> <script type=text/javascript> function event() { alert("hello"); } </script> <title>Page Title</title> </head> <body> <button onclick= "event()">hello</button> </body> </html>

1st Jun 2020, 2:45 PM
Asef Dian🇧🇩
Asef Dian🇧🇩 - avatar
3 Respostas
+ 4
event is a Keyword in js try using different name it will work 👍 https://code.sololearn.com/WWPSTx81wJyj/?ref=app
1st Jun 2020, 2:48 PM
Madhav
Madhav - avatar
+ 2
Event is Js Syntax in javascript you can't name it as function like you can't make variable as var,let or const So like this you can define the inbuilt javascript function
2nd Jun 2020, 9:02 AM
Coder
Coder - avatar
0
event is reserved
1st Jun 2020, 3:25 PM
Prabhakar Rai
Prabhakar Rai - avatar