I have an anchor text that when click adds an active class to another class. I want to remove it when it has an active class or if I click the anchor text again. How can I do th
try this example
<style type="text/css">
.sector-active
{
color: green;
}
</style>
<div class="container">
<div class="main-sectors">
<a href="#" class="sector-active">Name1</a>
<a href="#" class="p-l-35">Name2</a>
<a href="#" class="p-l-35">Name3</a>
<a href="#" class="p-l-35">Name4</a>
<a href="#" class="p-l-35">Name5</a>
</div>
</div>
<script type="text/javascript" src="../library/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('a').click(function()
{
$(this).removeClass('p-1-35');
$('a').removeClass('sector-active');
$(this).addClass('sector-active');
});
});
</script>
this code will be add sector-active
class to clicked a
tag
and remove sector-active
class from another a
tag
if you can add sector-active
class to all clicked a
tag then comment to following line
// $('a').removeClass('sector-active');
this will help you
Try this
$(function(){
$("#menu1").click(function(){
$(this).toggleClass("active");
$("a.mm-title").toggleClass("remove");
});
});
Let me know if it is helpful