Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<div class="expand-icon">
<a href="#rulesTreeDiv" class="collapsed" data-toggle="collapse">
<i class="fas fa-expand-alt icon-1x"></i>
<!-- <i class="fas fa-compress-alt icon-1x"></i> -->
</a>
</div>


When i click on the expand-alt icon div will hide and then icon has to change to the below icon
div is hiding and the icon is not changing when i click

What I have tried:

$("#expand-icon").click(function(){
$(this).find("i").toggleClass("fas fa-compress-alt");
});
Posted
Updated 23-Apr-20 6:06am

1 solution

Try:
JavaScript
$(".expand-icon").click(function(){
    var me = $(this);
    var isCollapsed = me.find("a[data-toggle='collapse']").is(".collapsed");
    me.find("i.fas").toggleClass("fa-expand-alt", !isCollapsed).toggleClass("fa-compress-alt", isCollapsed); 
});
Demo[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900