JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<script src="/1-first-file.js"></script>
<link rel="stylesheet" type="text/css" href="/styles.css" media="screen" />
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Index</title>
</head>
<body>
<div id="div1" class="regular">
No strikethrough!
</div>
</body>
</html>
CSS
div {
background-color: rgb(204, 47, 47);
font-size: 25px;
width: 250px;
height: 250px;
}
#div1 {
margin: 10px;
text-align: center;
}
.regular {
text-decoration: none;
}
.line-through {
text-decoration: line-through;
}
JavaScript
document.addEventListener("click", (e) => {
let closestDiv = e.target.closest("div");
if (
closestDiv &&
closestDiv.id === "div1" &&
closestDiv.className === "regular"
) {
closestDiv.classList.add("line-through");
closestDiv.innerText = "Strikethrough!";
} else if (
closestDiv &&
closestDiv.id === "div1" &&
closestDiv.className === "regular line-through"
) {
closestDiv.innerText = "No strikethrough!";
closestDiv.classList.remove("line-through");
}
});