I am trying to show some dynamically generated graphs on a single page, and then hide them until a user wants to see them.
What I want to happen is when the div named 'Show_When_Closed' is clicked hide that div and show the divs named 'Show_When_Open' and 'Graph' and then when 'Show_When_Open' is clicked hide it and 'Graph' and show 'Show_When_Closed.'The for loop will run X amount of times, so the html code will be repeated multiple times.
My code below does not work as it uses Css tags and not dynamic ids or some Jquery way of the code knowning which div to show. I am sure there is a simple way of achieving the task but my javascript is very poor.
Thanks to anyone who helps.
{% for value in graphs_to_render %}
<div class='graph_holder' id=maindivs>
<div class='graph_header_1' name='Show_When_Closed'> {{value}} <i class="fas fa-chevron-right"></i></div>
<div class='graph_header_2' name='Show_When_Open' style='display:none;'> {{value}} <i class="fas fa-chevron-down"></i></div>
<div name='Graph' class= 'graph_main' style='display:none;' >
<embed type="image/svg+xml" src= {{graphs_to_render[value]|safe}} />
</div>
</input>
</div>
{% endfor %}
<script>
$(document).ready(function() {
$('.graph_header_1').on('click', function(){
$('.graph_main').toggle();
$('.graph_header_1').toggle();
$('.graph_header_2').toggle();
});
$('.graph_header_2').on('click', function(){
$('.graph_main').toggle();
$('.graph_header_1').toggle();
$('.graph_header_2').toggle();
});
});