I can't seem to get my arrows to show in the right direction when a collapsing item is collapsed or expanded (JSFiddle)
Code:
$('body').on("click", "span#expandcollapse", function ()
{
$(this).text(function(i, currentText)
{
return currentText === 'Expand All' ? 'Collapse All' : 'Expand All';
});
if($(this).text() === 'Expand All')
{
//Currently collapsed
if($('.projectscontainer').find("div.destarrow").hasClass('arrow-right'))
$('.projectscontainer').find('div.destarrow').toggleClass("arrow-right arrow-down");
$(".projectscontainer").find(".srcprojects").toggle(false);
}
else
{
//Currently expanded
$(".projectscontainer").find(".srcprojects").toggle(true);
if($('.projectscontainer').find("div.destarrow").hasClass('arrow-down'))
$('.projectscontainer').find('div.destarrow').toggleClass("arrow-down arrow-right");
}
});
This line is not working as intended:
if($('.projectscontainer').find("div.destarrow").hasClass('arrow-down'))
$('.projectscontainer').find('div.destarrow').toggleClass("arrow-down arrow-right");
When I click expand all, the items should expand (working), and the arrows should point down (not working). When I click collapse all, the opposite should occur. For example, if I click one of the green items, then click expand all, the arrow for the item clicked is in a different direction.
What am I doing wrong? And are there any performance problems here I need to fix if I have a huge list? Thanks!