All syntaxes of Event Listeners
The goal of this coding exam is to quickly get you off the ground with All Syntaxes Of Event Listeners
Use the below reference image.
https://assets.ccbp.in/frontend/content/dynamic-webapps/all-syntaxes-of-event-listeners-op.gif
Achieve the given functionality using JS
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
button {
display: block;
margin-top: 5px;
}
#inlineListenerBtn {
background-color: blue;
}
#onEventListenerBtn {
background-color: gray;
}
#addEventListenerBtn {
background-color: yellow;
}
</style>
</head>
<body>
<p id="message"></p>
<button id="inlineListenerBtn" onclick="inlineClick()">Button with Inline event listener</button>
<button id="onEventListenerBtn">Button with onevent listener</button>
<button id="addEventListenerBtn">Button with addEventListener</button>
<script>
var p = document.getElementById("message");
function inlineClick() {
p.innerHTML = "Inline event listener";
}
var btn2 = document.getElementById("onEventListenerBtn")
btn2.onclick = onEventClick;
function onEventClick() {
console.log("22")
p.innerHTML = "onevent listener";
}
var btn3 = document.getElementById("addEventListenerBtn");
btn3.addEventListener("click", function() {
console.log("33");
p.innerHTML = "addEventListener";
});
</script>
</body>
</html>
Comments
Leave a comment