I am trying this sidebar of a dashboard and it looks like this
The top child or the one with the brighter green color on it has a class active_link which basically tells you that you are in this part of the dashboard. So the idea is that I want the class active link to be added to the certain element that I have clicked upon while the rest who are not clicked don't have (Meaning that if the element already have the active_link but it is not the one that I have clicked upon then the class will be removed however if it does not have the active_link class and it is the one I clicked it will be added to that certain element). However, I have a problem.I tried running this code:
$(function(){
$(".sidebar_link").click(function(){
$(".sidebar_link").each(function(index){
if($(this).data('clicked', true)){
if($(this).hasClass('active_link') == false){
$(this).addClass('active_link');
}
}else{
if($(this).hasClass('active_link')){
$(this).removeClass('active_link');
}
}
});
});
})
And this is what happened:
Which what I could tell is just a disaster, any tips? Thank you in advance! Here is the HTML
<div class="sidebar_menu">
<div class="sidebar_link active_link">
<i class="fa fa-home"></i>
<a href="#">Dashboard</a>
</div>
<h2>MANAGE</h2>
<div class="sidebar_link">
<i class="fa fa-building-o"></i>
<a href="#">See Admin Notif</a>
</div>
<div class="sidebar_link">
<i class="fa fa-wrench"></i>
<a href="#">Update Profile</a>
</div>
<div class="sidebar_link">
<i class="fa fa-archive"></i>
<a href="#">Donate</a>
</div>
<div class="sidebar_link">
<i class="fa fa-handshake-o"></i>
<a href="#">Connect</a>
</div>
<div class="sidebar_logout">
<i class="fa fa-power-off"></i>
<a href="#">Log out</a>
</div>
</div>

