File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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} ) ;
Original file line number Diff line number Diff 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 >
You can’t perform that action at this time.
0 commit comments