add solution

solution
Colt 10 years ago
parent ca07b4c73d
commit 953303acef
  1. 35
      app.js
  2. 10
      index.html
  3. 3
      style.css

@ -0,0 +1,35 @@
var styleListElements = function(){
var list_items = document.querySelectorAll("div#essentials > ul > li");
for (var i = list_items.length - 1; i >= 0; i--) {
// for (initializer, condition, counter)
list_items[i].style.backgroundColor = "yellow";
list_items[i].addEventListener("click", selectItem);
}
};
var selectItem = function(event){
// console.log(this.innerHTML);
this.classList.add("selected");
document.querySelector("img").setAttribute("src","./images/" + this.innerHTML + ".jpeg");
};
var changeGreeting = function(){
var greeting_div = document.getElementById("greeting");
greeting_div.innerHTML = "Hello Planet earth!";
};
var resetButtonHandler = function() {
var list_items = document.querySelectorAll("li");
for (var i = list_items.length - 1; i >= 0; i--) {
list_items[i].className = "";
}
document.querySelector("img").setAttribute("src","./images/panic.jpeg");
};
var initialize = function(){
changeGreeting();
styleListElements();
document.querySelector("#reset").addEventListener("click",resetButtonHandler);
};
window.onload=initialize;

@ -2,13 +2,9 @@
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>The DOM playground</title> <title>Le DOM playground</title>
<style> <link rel="stylesheet" href="style.css">
.selected{ font-weight: bold;} <script src="app.js" ></script>
</style>
<script>
console.log("JavaScript is alive");
</script>
</head> </head>
<body> <body>
<div id="greeting"> <div id="greeting">

@ -0,0 +1,3 @@
.selected {
text-decoration: line-through;
}
Loading…
Cancel
Save