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. ๐๐ฌ
Top comments (0)