I have multiple divs setup, with headers and content.
When you click the header, it expands the content on the selected div, and hides all others.
This works fine, but I need to get the ID’s of all the content divs, that have been hidden or shown.
This is my jquery for the hide/show:
$(".CollapsableHeader").next(".CollapsableDiv").hide();
$(".CollapsableHeader").click(function () {
$('.active').not(this).toggleClass('active').next('.CollapsableDiv').slideToggle(300, function () {
alert($(this).next('.CollapsableDiv').attr('id'));
});
$(this).toggleClass('active').next().slideToggle("fast");
});
So, in this example, my alert always comes up as, undefined.
Everything I have tried, comes up as undefined.
Any idea how I can get the ID’s of the .CollapsableDiv‘s?
If you’re looking for the
idof the “next”.CollapsableDivafter the.CollapsableHeaderthat was clicked, grab it in the click handler rather than theslideTogglecallback:The reason is that the
thiswithin yourslideTogglecallback is a different element (specifically, it’s whatever you end up with from$('.active').not(this).toggleClass('active').next('.CollapsableDiv').)