Files
JavaScript-from-Beginner-to…/Chapter 11/Exercise_11.2.html
T
2021-12-03 14:20:12 +05:30

18 lines
383 B
HTML

<!doctype html>
<html>
<body>
<div>red</div>
<div>blue</div>
<div>green</div>
<div>yellow</div>
<script>
const divs = document.querySelectorAll("div");
divs.forEach((el)=>{
el.addEventListener("click",()=>{
document.body.style.backgroundColor = el.textContent;
});
});
</script>
</body>
</html>