Project 1
This commit is contained in:
parent
b40f1fa9dc
commit
d05cedb985
45
Chapter 10/Project 1
Normal file
45
Chapter 10/Project 1
Normal file
@ -0,0 +1,45 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>JS Tester</title>
|
||||
<style>
|
||||
.active {
|
||||
display: block !important;
|
||||
}
|
||||
.myText {
|
||||
display: none;
|
||||
}
|
||||
.title {
|
||||
font-size: 1.5em;
|
||||
background-color: #ddd;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="title">Title #1</div>
|
||||
<div class="myText">Just some text #1</div>
|
||||
<div class="title">Title #2</div>
|
||||
<div class="myText">Just some text #2</div>
|
||||
<div class="title">Title #3</div>
|
||||
<div class="myText">Just some text #3</div>
|
||||
</div>
|
||||
<script>
|
||||
const menus = document.querySelectorAll(".title");
|
||||
const openText = document.querySelectorAll(".myText");
|
||||
menus.forEach((el) => {
|
||||
el.addEventListener("click", (e) => {
|
||||
console.log(el.nextElementSibling);
|
||||
remover();
|
||||
el.nextElementSibling.classList.toggle("active");
|
||||
})
|
||||
})
|
||||
function remover() {
|
||||
openText.forEach((ele) => {
|
||||
ele.classList.remove("active");
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user