When you click on an anchor with the class .extra, it adds the "extra-active" class and removes the "extra" class. However, when you click on an anchor with the extra-active class, it does not remove the extra-active class and replace it with extra.
Here is the HTML code:
$("a.extra").click(function(e){
$(this).addClass("extra-active").removeClass("extra");
e.preventDefault();
})
$("a.extra-active").click(function(e){
$(this).removeClass("extra-active").addClass("extra");
e.preventDefault();
})
.extra{
display:inline-block;
height: 128px;
width: 128px;
background-color:grey;
padding:12px;
border-radius:8px;
}
.extra-group{
p {
text-align:center;
}
}
.extra:hover{
background-color:blue;
}
.extra-active{
display:inline-block;
height: 128px;
width: 128px;
background-color:red !important;
padding:12px;
border-radius:8px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span style="display:inline-block;">
<span class="extra-group">
<a class="extra" href="" title = "An hour of Ironing" id="extra-ironing" style = "background-image: url('{{ url_for('static', filename='book-icons/iron-icon.png') }}'); background-size: 80% 80%; background-repeat: no-repeat; background-position: center center;"></a>
<p>An Hours Ironing</p>
</span>
<span class="extra-group">
<a class="extra" href="" title = "Inside the Fridge" id="extra-fridge" style = "background-image: url('{{ url_for('static', filename='book-icons/fridge-icon.png') }}'); background-size: 80% 80%; background-repeat: no-repeat; background-position: center center;"></a>
<p>Inside the Fridge</p>
</span>
<span class="extra-group">
<a class="extra" href="" title = "Inside the Oven" id="extra-oven" style = "background-image: url('{{ url_for('static', filename='book-icons/oven-icon.png') }}'); background-size: 80% 80%;; background-repeat: no-repeat; background-position: center center;"></a>
<p>Inside the Oven</p>
</span>
<span class="extra-group">
<a class="extra" href="" title = "A load of Washing" id="extra-washing" style = "background-image: url('{{ url_for('static', filename='book-icons/washer-icon.png') }}'); background-size: 80% 80%; background-repeat: no-repeat; background-position: center center;"></a>
<p>A load of Washing</p>
</span>
<span class="extra-group">
<a class="extra " href="" title = "Interior Windows" id="extra-windows" style = "background-image: url('{{ url_for('static', filename='book-icons/window-icon.png') }}'); background-size: 80% 80%; background-repeat: no-repeat; background-position: center center;"></a>
<p>Interior Windows</p>
</span>
</span>