It should be: I click on the button - the corresponding content is included. Does not work.
function showIt() { var chart = document.getElementsByClassName('chart'); var button = document.getElementsByTagName('input'); function hideAll() { for (i = 0; i < chart.length; i++) { chart[i].style.display = 'none'; } } for (i = 0; i < button.length; i++) { switch (chart[i]) { case chart[0]: hideAll(); chart[0].style.display = 'block'; break; case chart[1]: hideAll(); chart[1].style.display = 'block'; break; case chart[2]: hideAll(); chart[2].style.display = 'block'; break; case 3: hideAll(); chart[3].style.display = 'block'; break; } } } .chart { display: none; } <ul class="navigation"> <a class="main" href="#url">Choose year</a> <li class="n2"><input type="button" value="2011" onclick="showIt()"></li> <li class="n3"><input type="button" value="2012" onclick="showIt()"></li> <li class="n4"><input type="button" value="2013" onclick="showIt()"></li> <li class="n5"><input type="button" value="2014" onclick="showIt()"></li> </ul> <div id="charts"> <div class="chart" id="chart_div1" style="width: 100%; height: 25px;">1</div> <div class="chart" id="chart_div2" style="width: 100%; height: 25px;">2</div> <div class="chart" id="chart_div3" style="width: 100%; height: 25px;">3</div> <div class="chart" id="chart_div4" style="width: 100%; height: 25px;">4</div> </div>
for-switch-case, devoid of meaning, is, you see, not a trifle. And about "without jQuery" - do I understand correctly that you cannot write code written using jQuery into code without jQuery? - Regent