If we enclose that inside HTML
script tags, it will look like this:
head tags (or
body tags), it will run as soon as we load the page.
Now this is fine — as long as you want it to run as soon as the page loads.
But, what if you don't want it to run as soon as the page loads? What if you only want it to run when a user clicks on a button?
Easy! This is where you need to use an event handler.
What's an Event Handler?
onClick attribute to the element.
The examples below demonstrate this for you.
onDblClick event handler.
alert() function in the above examples — using event handlers.