I am facing an issue with dynamically generated divs in asp.net. My goal is to display the contents of each div by clicking on its header. I attempted to achieve this using the following code:
$(function () {
var myHead = $(".toggle-container").find(".toggle-header");
var myBody = $(myHead).parent().find(".toggle-content");
$(myHead).click(function () {
if ($(myBody).css('display') === 'none') {
$(this).children('i').removeClass('icon-chevron-sign-down').addClass('icon-chevron-sign-up');
$(this).parent().find(".toggle-content").slideDown("slow");
} else if ($(myBody).css('display') === 'block') {
$(this).children('i').removeClass('icon-chevron-sign-up').addClass('icon-chevron-sign-down');
$(this).parent().find(".toggle-content").slideUp("slow");
};
});
});
However, this solution only works for the first header and does not collapse the children content for the rest of the headers. You can view my current progress on this JsFiddle. Any suggestions on how to fix this issue would be greatly appreciated.