Here is the structure I am working with to display titles before the corresponding div with data-attribute.
I am aiming to achieve this layout:
1st Title
2nd Title
3rd Title
4th Title
When "1st Title" is clicked, the layout should transform into:
1st Title
First Content
2nd Title
3rd Title
4th Title
My question is, is there a way to implement this accordion functionality without altering the existing HTML structure (which consists of ul, li elements followed by the content divs)?
ul {
display:none;
}
div:before {
content:attr(data-title);
display:block;
font-size:14px;
background:gray;
text-align:center;
line-height:14px
}
div {
background:lightgray;
}
<ul>
<li id="first">1st Header</li>
<li id="second">2nd Header</li>
<li id="third">3rd Header</li>
<li id="fourth">4th header</li>
</ul>
<div id="first_div" data-title="1st Header title">First content <br/>1111111111111111111111</div>
<div id="second_div" data-title="2nd Header title">Second content <br/>22222222222222222222</div>
<div id="third_div" data-title="3rd Header title">Third content <br/>33333333333333333333</div>
<div id="fourth_div" data-title="4th Header title">Fourth content <br/>4444444444444444444</div>