The current situation is this: The code below works to toggle a div once the corresponding link is clicked on. It also hides the div if you click on that link again.
What I want this to do is hide all divs unless you click on the corresponding a href link. When you do click on this a href link, it shows the right div and then hides the others. And it automatically 'jumps' down to the toggled div, similar to the effect of if you had an anchor tag in there linking the a href link and the div.
Currently when I click on the link, it shows the div but I still have to scroll down the page to view the div. It does not automatically jump down to that div that was toggled. It also does not hide the other divs when you click on the current link for viewing. I played around with slideToggle() but I would still have to scroll down to view the div that was toggled.
Here is sample code of what I have:
<div class="row">
<div class="large-12 columns">
<a href="javascript:toggleByClass('content1')" class="link-list"> Content 1 </a>
<a href="javascript:toggleByClass('content2')" class="link-list"> Content 2 </a>
<a href="javascript:toggleByClass('content3')" class="link-list"> Content 3 </a>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<div class="content1" style="display: none;">
<p> Information in Content 1</p>
</div>
<div class="content2" style="display: none;">
<p> Information in Content 2</p>
</div>
<div class="content3" style="display: none;">
<p> Information in Content 3</p>
</div>
</div>
</div>
<script type="text/javascript">
function toggleByClass(className) {
$("." + className).toggle();
}
</script>
Any advice for direction is greatly appreciated.
- After receiving a link saying this might be a possible duplicate question - I wanted to point out that I was not trying to add an anchor tag to jump to content on a page. I wanted to jump down a page to view a toggled div, which was already in place, and hide the other divs that were not toggled.