+ 2

How to use onclick?

pls show me one example. thanks.

7th Sep 2016, 9:48 AM
HawkEye
HawkEye - avatar
2 Answers
+ 5
html: <button onclick="document.write('Hello world!');">Click me!</button> You can also define your own function and use it with onclick. <button onclick="myFunc()">Click me!</button> <script type="text/javascript"> function myFunc() { document.write("Hello world!"); } </script> Alternative way with anonymous function: <button onclick="(function() {document.write('Hello world!');})()">Click me!</button> Sorry for the edits.
7th Sep 2016, 9:54 AM
Zen
Zen - avatar
0
thanks bro
7th Sep 2016, 9:55 AM
HawkEye
HawkEye - avatar