Reputation: 75
var modify = document.queryAll("#tab");
for(var i=0; i<modify.length; i++)
{
modify[i].on.click.add((Event e) => show_content(i));
}
// code for hide_content()
i have two function show_content() and hide_content() that operates on the div's i'm not able to detect second time click on a div to trigger hide_content(). i've tried with a semaphore and - no luck
<div id="tab"> </div>
<div id="content"> </div>
<div id="tab"> </div>
<div id="content"> </div>
Upvotes: 0
Views: 197
Reputation: 8483
queryAll
is used for non-unique elements. Using queryAll
for an unique element with the ID tab
doesn't make any sense. You should use query('#tab')
where you get just a single DivElement
as its return value.
However I'm not sure, I undersand your problem but if you need a toggle button, you're maybe looking for something like this:
DivElement uniqeDiv;
void toggle() {
if(uniqeDiv.hidden) {
// uniqeDiv.hidden = false;
show();
} else {
// uniqeDiv.hidden = true;
hide();
}
}
void main() {
uniqeDiv = query('#tab');
uniqeDiv.on.click.add((Event e) => toggle());
}
Upvotes: 1