HTML events happen to HTML codes. When we add Javascript in HTML pages, Javascript then react to those HTML pages.HTML event does by the browser or a user.
Some common HTML events are -->>
Here is a list of some common HTML events:
1- onchange---> An HTML element has been changed
2- onclick-------------> Something happens which defined when element is clicked
3- onmouseover----> Event occur when user moves the mouse over an HTML element
4-onmouseout------> Event occur when mouse away from an HTML element
5-onkeydown-------> When any keyboard key is pushed
6-onload-------------> Event occur when browser finished loading the web page
JavaScript lets the code to be executed when events are detected.
Examples
<html>
<body>
<button onclick="getElementById('time').innerHTML=Date()">Click here to get time?</button>
<p id="time"></p>
</body>
</html>
In the above code on click event is performed to get the time .
example 2
<!DOCTYPE html>
<html>
<body onload="welcomemessage()">
<p id="text"></p>
<script>
function welcomemessage() {
var text = "";
if (navigator.cookieEnabled == true) {
text = "You are welcome here";
} else {
text = "OOps wront page";
}
document.getElementById("text").innerHTML = text;
}
</script>
</body>
</html>
the above example is of onload event
0 Comment(s)