UPDATE: Working answer.
This is quite a complicated question about jQuery/JS - I've found a post that addresses a similar issue here, but I'm not using raw html or a tags, so the structure of the code is quite different.
Basically I have a list of divs that need to be hidden on page load, and then I need to display each div when a trigger element is clicked. The catch is that I need to hide all of the other divs when clicking different trigger elements. Obviously display: none;
will need to be present on page load but the jQuery is beyond my current knowledge.
Example:
When this div is clicked
<div id="div1trigger">View Div 1 Contents</div>
this div is shown:
<div id="div1">Div 1 Content Here</div>
I have this working using this JS:
<script>
jQuery("#div1trigger").click(function(){
jQuery("#div1").toggle();
});
</script>
Pretty simple use of .toggle() I know, but this is where is gets complicated, I have 5 trigger divs and 5 content divs in total, each of them needs to display their corresponding div and hide all of the other divs at the same time.
I was thinking something like the following:
<script>
jQuery("#div1trigger").click(function(){
jQuery("#div1").toggle();
jQuery("#div2, #div3, #div4, #div5").hide();
});
</script>
and then this ^ 5 times over to control each trigger div (although I am almost certain there is a cleaner/more 'correct' solution to this issue).
Please consider that all trigger div's are labelled by 'divnumbertrigger' such as #div2trigger
; and all content divs are labelled 'divnumber' such as #div2
.
Lastly for visual reference here is a screenshot of the frontend to help visualise the usage, all content divs use the same area of the page (green box) and all of the 'View' buttons (inside red box) are the div triggers:
Can anyone provide me with a workable solution/correct method of achieving this?