Reputation: 16622
The code below working for only first div. I can't display other divs when i clicked on the other "img"s. Do you know a method to reach second (next) element?
$(document).ready(function() {
$('.imgOpenClose').click(function() {
if ($(this).attr("src") == "images/openTree.gif") {
$(this).attr("src", "images/closeTree.gif");
$(this).parent().find('div').eq(0).show();
}
else {
$(this).attr("src", "images/openTree.gif");
$(this).parent().find('div').eq(0).hide();
}
});
});
Upvotes: 2
Views: 7343
Reputation: 532435
Since you have a break element following the image, you'll need to use nextAll and select the first DIV instead of simply using next
with a filter as in my original answer.
$('.imgOpenClose').click( function() {
$(this).nextAll('div:first').toggle();
});
Upvotes: 2
Reputation: 60564
If you have several images with the same class-tag, you can still do it without having to append a unique id:
$(function() {
$('.imgOpenClose').click(function() {
$(this).next('div').children('table').toggle();
});
});
Upvotes: 1