Question of the Day: Event Handling in JavaScript π
Erasmus Kotoka
Posted on May 23, 2024
Hey everyone! Let's dive into the world of JavaScript together. Hereβs an interactive question to test your knowledge on event handling in JavaScript.
π§ Question
What will be the output of the following code snippet when you click the button with the ID myButton
?
<!DOCTYPE html>
<html>
<head>
<title>Event Handling Example</title>
</head>
<body>
<button id="myButton">Click Me!</button>
<script>
document.getElementById('myButton').addEventListener('click', function() {
alert('Button clicked!');
});
document.getElementById('myButton').addEventListener('click', function() {
console.log('Button was clicked!');
});
</script>
</body>
</html>
Options:
A. Only an alert box with the message "Button clicked!" will appear.
B. Only "Button was clicked!" will be logged to the console.
C. Both the alert box and the console log will appear.
D. Neither the alert box nor the console log will appear.
Explanation:
Feel free to share your thoughts and explanations in the comments below! Let's learn together. ππ¬
COdeWith #KOToka
KEEPCoding
π πͺ π
π©
Erasmus Kotoka
Posted on May 23, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.