Skip to content

Commit 12b2e87

Browse files
author
Argenis Contreras
committed
Add click handler for image
1 parent a02cd27 commit 12b2e87

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

first-website/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,7 @@ <h1 style="text-align: center;">Mozzila is cool </h1>
4949
<p class="quote">"JavaScript is the language of web browsers" - John Doe</p>
5050

5151
<p>Sed scelerisque commodo odio, ut consectetur arcu sodales in. Curabitur vitae rhoncus arcu. Mauris hendrerit rhoncus diam sit amet hendrerit. Suspendisse potenti. Aenean semper rhoncus mi, non semper urna porta nec. Quisque condimentum est et ultricies aliquam. Etiam et eros in dolor tempus maximus eu id turpis. Aliquam ac leo sed ligula tincidunt vulputate. Suspendisse sagittis et mauris in euismod. Integer suscipit sapien sit amet nunc finibus, sed faucibus dui dictum. Phasellus ac velit nisi.</p>
52+
53+
<script src="scripts/main.js?v=2"></script>
5254
</body>
5355
</html>

first-website/scripts/main.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function sayOuch() {
2+
const message = "Ouch! Stop poking me!";
3+
4+
// Visible + debuggable feedback (some embedded previews can block alert popups).
5+
console.log(message);
6+
7+
const heading = document.querySelector("h1");
8+
if (heading) {
9+
heading.textContent = message;
10+
}
11+
12+
alert(message);
13+
}
14+
15+
document.addEventListener("DOMContentLoaded", () => {
16+
const foxImage = document.querySelector("img");
17+
if (foxImage) {
18+
foxImage.onclick = sayOuch;
19+
}
20+
});

0 commit comments

Comments
 (0)