Skip to main content
Handling event part 2
Handling Events
Let's display an alert popup when the user clicks a specified button:
<button onclick="show()">Click Me</button>
<script>
function show() {
alert("Hi there");
}
</script>Try It Yourself
Event handlers can be assigned to elements.For example:
var x = document.getElementById("demo");
x.onclick = function () {
document.body.innerHTML = Date();
}Try It Yourself
You can attach events to almost all HTML elements.
Comments
Post a Comment