+ 2
How to use onclick?
pls show me one example. thanks.
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.
0
thanks bro



