+ 9
My onclick atribugte doesn't work. Why?
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <button onclick="click()">OK</button> <script> function click(){ alert("Hello"); } </script> </body> </html>
4 Antworten
+ 12
Thanks everybody. When i changed clik it really worked.
+ 7
So this is a very good question and a lot of people don't know it but the name click () is already reserved so you aren't allowed to use it just use anything else for the name of the function like sayHello () and it will work
hope this helps
~Kamil
+ 4
'Cause you put script after tag? (...or try removing parenthesis from onclick)
0
Try declaring the function script before the button. Perhaps put the script between the head tags.