I have written toggle code below, I need "active" class should toggle when "Map / View" toggle. When I click on another link first should remove and apply to clicked link.
HTML:
<div class="member-view-switch">
<a href="#" class="toggle-button active">Tile</a>
<a href="#" class="toggle-button">Map</a>
</div>
<div class="toggle-item target-tile-view">
Tile View
</div>
<div class="toggle-item target-map-view">
Map View
</div>
CSS:
.member-view-switch {
margin-bottom: 20px;
}
a,
:hover,
:focus {
color;
#333333;
text-decoration: none;
padding-right: 15px;
}
.active {
color: blue;
font-weight: bold;
}
.toggle-item {
border: 1px solid #333;
padding: 20px;
margin-bottom: 20px;
}
jQuery:
$(document).ready(function() {
$(".target-map-view").css("display", "none");
$(".toggle-button").click(function() {
if ($(this).hasClass("active")) {
$(".target-tile-view").show();
$(".target-map-view").hide();
} else {
$(".target-tile-view").hide();
$(".target-map-view").show();
}
});
});