Skip to content

Commit 8eba236

Browse files
committed
17 Lesson
1 parent 04bb356 commit 8eba236

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

app.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,20 @@ searchBar.addEventListener('keyup', (e) => {
5757
book.style.display = 'none';
5858
}
5959
});
60+
});
61+
62+
// tabbed content
63+
const tabs = document.querySelector('.tabs');
64+
const panels = document.querySelectorAll('.panel');
65+
tabs.addEventListener('click', (e) => {
66+
if(e.target.tagName == 'LI'){
67+
const targetPanel = document.querySelector(e.target.dataset.target);
68+
Array.from(panels).forEach((panel) => {
69+
if(panel == targetPanel){
70+
panel.classList.add('active');
71+
}else{
72+
panel.classList.remove('active');
73+
}
74+
});
75+
}
6076
});

index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ <h2 class="title">Books to Read</h2>
4444
<input type="text" placeholder="Add a book..." />
4545
<button>Add</button>
4646
</form>
47+
<div id="tabbed-content">
48+
<ul class="tabs">
49+
<li data-target="#about" class="active">About</li>
50+
<li data-target="#contact">Contact</li>
51+
</ul>
52+
<div class="panel active" id="about">
53+
<p>Content for about tab...</p>
54+
<p>Text</p>
55+
</div>
56+
<div class="panel" id="contact">
57+
<p>Content for contact tab...</p>
58+
<p>Text</p>
59+
</div>
60+
</div>
4761

4862
</div>
4963
<script src="app.js"></script>

0 commit comments

Comments
 (0)