Event Handling in Javascript
Event Handling in Javascript
Event Handling in Javascript
An HTML event can be something the browser does, or something a user does.
When java script code is included in HTML, js react over these events and
allow the execution. This process of reacting over the events is called Event
Handling. Thus, js handles the HTML events via Event Handlers.
For example, when a user clicks over the browser, add js code, which will
execute the task to be performed on the event.
<button onclick="document.getElementById('demo').innerHTML=Date()">
Date and Time
</button>
<p id="demo"></p>
</body>
</html>
Drag n Drop
<!DOCTYPE HTML> <script>
<html> function allowDrop(ev) {
<head> ev.preventDefault();
<style> }
#div1 {
width: 350px; function drag(ev) {
height: 70px; ev.dataTransfer.setData("text", ev.target.id);
padding: 10px; }
border: 1px solid #aaaaaa;
} function drop(ev) {
</style> ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>
</body>
</html>