I'm currently working on a project where I have a div with predefined dimensions, but the content inside is set to not display initially.
Above this div, there are several p tags that act as clickable links to reveal different content within the div when clicked. However, I'm having trouble getting this functionality to work properly.
HTML
<p id="link1">Content 1</p>
<p id="link2">Content 2</p>
<p id="link3">Content 3</p>
<div class="subcontent">
<div class="hide cont1">
<p>Title</p>
<p>Content 1</p>
</div>
<div class="hide cont2">
<p>Title</p>
<p>Content 2</p>
</div>
<div class="hide cont3">
<p>Title</p>
<p>Content 3</p>
</div>
</div>
CSS
.subcontent{
box-sizing: border-box;
border: solid 1px #DDD;
height:300px;
width: 70%;
padding: 0px 15px;
margin-left: 22%;
margin-bottom: 10px;
font-size: 90%;
}
.hide {
display: none;
Can anyone provide suggestions on how to make Content 1 visible when #link1 is clicked?
Additionally, how can I ensure that any previously displayed content is hidden before revealing new content?
I apologize if my explanation is unclear - I am still learning and appreciate any guidance provided.