One issue I'm facing is changing the content on a page depending on the clicked link. The problem arises when the displayed content for one link persists even after clicking another link, despite setting it to not display when another link is clicked. It seems that the "display: block" property overrides the "display: none" property.
While some suggest using .show() and .hide(), I feel that method might not work best for me as I need to add a class to the elements for potential animation in the future. Thanks for understanding!
jQuery(document).ready(function() {
jQuery('#link_one').click(function() {
jQuery('#about_us').addClass('hide');
jQuery('#why_us').addClass('hide');
jQuery('#our_prods').addClass('hide');
jQuery('#accreditations').addClass('show');
});
jQuery('#link_two').click(function() {
jQuery('#why_us').addClass('hide');
jQuery('#accreditations').addClass('hide');
jQuery('#our_prods').addClass('hide');
jQuery('#about_us').addClass('show');
});
jQuery('#link_three').click(function() {
jQuery('#about_us').addClass('hide');
jQuery('#our_prods').addClass('hide');
jQuery('#accreditations').addClass('hide');
jQuery('#why_us').addClass('show');
});
});
nav {
width: 100%;
text-align: center;
}
nav ul {
list-style-type: none;
}
nav ul li {
display: inline-block;
}
nav ul li a {
font-size: 40px;
margin: 0 10px;
}
p {
font-size: 30px;
font-weight: bold;
}
div {
width: 100%;
text-align: center;
}
.hide {
display: none;
}
.show {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav>
<ul>
<li><a id="link_one" href="#">link 1</a></li>
<li><a id="link_two" href="#">link 2</a></li>
<li><a id="link_three" href="#">link 4</a></li>
</ul>
</nav>
<div id="about_us">
<p>About Us Page - to be displayed by default</p>
</div>
<div id="accreditations">
<p>Accreditations Page Content - Link 1</p>
</div>
<div id="our_prods">
<p>Our products - Link 2</p>
</div>
<div id="why_us">
<p>Why us content - link 3</p>
</div>