javascript - JS function to hide or show elements -
i have json files, load them both 2 tables this:
$(window).load(function(){ $.getjson('http://1xxxxxx/xxxxx_1_18.json', function(data) { var output="<div class='outer'>"; (var in data.lbclassic118) { output+="<div style='visibility:hidden;' class='lbclassic118'id="+"age" + data.lbclassic118[i].ageinweeks+">"+ '<table class="table table-responsive"><tr class="cabecera"><th colspan="3"><center><strong>age (weeks)'+ data.lbclassic118[i].ageinweeks+'</strong></center></th></tr><tr><td rowspan="3">body weight (g)</td><td>average</td><td><strong>'+ data.lbclassic118[i].average+'</strong></td></tr><tr><td>range min</td><td><strong>'+ data.lbclassic118[i].rangemin+'</strong></td></tr><tr><td>range mmax</td><td><strong>'+ data.lbclassic118[i].rangemmax+'</strong></td></tr><tr><td rowspan="3">feed sonsumption</td><td>kj bird day</td><td><strong>'+ data.lbclassic118[i].kjbirdday+'</strong></td></tr><tr><td>g bird day</td><td><strong>'+ data.lbclassic118[i].gbirdday+'</strong></td></tr><tr><td>cumulative</td><td><strong>'+ data.lbclassic118[i].cumulative+'</strong></td></tr></table>' +"</div>"; } output+="</div>"; document.getelementbyid("placeholder1").innerhtml=output; }); }); $(window).load(function(){ $.getjson('http://xxxxxx/xxxxxx.json', function(data) { var output="<div class='outer'>"; (var in data.lbclassic1990) { output+="<div style='visibility:hidden;' class='lbclassic1990'id="+"age" + data.lbclassic1990[i].ageinweeks+">"+ '<table class="table table-responsive"><tr class="cabecera"><th colspan="3"><center><strong>age (weeks) '+ data.lbclassic1990[i].ageinweeks+'</strong></center></th></tr><tr><td>egg no. per h.h.</td><td>cumul.</td><td><strong>'+data.lbclassic1990[i].cumul+'</strong></td></tr><tr><td rowspan="2">rate of lay %</td><td>per h.h.</td><td><strong>'+data.lbclassic1990[i].perhh+'</strong></td></tr><tr><td>per h.d.</td><td><strong>'+data.lbclassic1990[i].perhd+'</strong></td></tr><tr><td rowspan="2"> egg weight (g)</td><td>egg weight in week</td><td><strong>'+data.lbclassic1990[i].eggweightinweek+'</strong></td></tr><tr><td>egg mass cumul.</td><td><strong>'+data.lbclassic1990[i].eggmasscumul+'</strong></td></tr><tr><td rowspan="2">egg mass -- g/h.d. -- kg/h.h.</td><td>egg mass in week</td><td><strong>'+data.lbclassic1990[i].eggmassinweek+'</strong></td></tr><tr><td>egg mass cumul.</td><td><strong>'+data.lbclassic1990[i].eggmasscumul2+'</strong></td></tr></table>' +"</div>"; } output+="</div>"; document.getelementbyid("placeholder2").innerhtml=output; }); });
the information comes should, have no problems that. however, i'm trying show 1 table @ time, not tables @ same time (don't want table each element in jsons) seen, 1 time.
for i'm implemeting function slider control show or hide tables.
here's images of html output data structure:
now, want to hide or show different divs (tables) script:
<script> function leslider(valor) { var elementos_lbclassic118 = document.getelementsbyclassname("lbclassic118"); var elementos_lbclassic1990 = document.getelementsbyclassname("lbclassic1990"); var total_elementos = elementos_lbclassic118.length + elementos_lbclassic1990.length; var i; (i = 1; < total_elementos.length+1; i++) { document.getelementbyid("age"+i).style.visibility = "hidden"; } document.getelementbyid("age"+valor).style.visibility = "visible"; }
however won't work, 1st json show elements never hide it, , second 1 place them on top of each other, not sure i'm failing.
i guess wrong "leslider" function. how use "leslider" function, let's me see code.
Comments
Post a Comment