Hi leds, I have following HTML code:
<h3 id="heading_xx">heading xx</h3>
<table id="table_xx">...</table>
<h3 id="nadpis_yy">heading yy</h3>
<table id="table_yy">...</table>
By clicking on the heading I need to slide(toggle) the coresponding table.
I have following code:
var allTabs = document.getElementsByTagName('table');
for(i=1; i<allTabs.length; i++) { // skipping the first table
var aTab = allTabs[i];
id_str = aTab.id.substring(7,aTab.id.length); // id_str = xx OR yy
var nadpis = $('heading_'+id_str); // found corresponding heading
var tableid = 'table_'+id_str; // prepairing table id string
nadpis.addEvent("click",function(){
alert('id_str = '+tableid); // I get ''table_yy'. If i put this line BEFORE addEvent, it works. But not here.
$(tableid).slide('toggle');
});
}
Yeah, its not exactly tuned, but it should work.
But what I am getting as 'tableid' on the last line is allways id of the last table. So no matter what heading i click, only the last table toggles.
Any ideas?
THX!