I have links that lead to another page with different contents.
<ul class="menu">
<li><a href="/services#item1" class="menu-btn">Item 1</a></li>
<li><a href="/services#item2" class="menu-btn">Item 2</a></li>
<li><a href="/services#item3" class="menu-btn">Item 3</a></li>
</ul>
This the code on the /services
page:
<div class="menu-content item-1">Content item 1</div>
<div class="menu-content item-2">Content item 2</div>
<div class="menu-content item-3">Content item 3</div>
I found the bellow JS, but it works only when clicking on the anchor link on the same page.
var $content = $('.menu-content');
function showContent(type) {
$content.hide().filter('.' + type).show();
}
$('.menu').on('click', '.menu-btn', function(e) {
showContent(e.currentTarget.hash.slice(1));
e.preventDefault();
});
I need is to display only the content related to the anchor link when load the /services
page.