I created a span element that changes its background color when clicked, but I want the background color to switch to the newly clicked span while removing it from the previously clicked one. Can someone help me achieve this?
CSS
list-style: none;
font-size: 14px;
padding: 7px 0px 7px 23px;
}
ul li a {
color: #676a74;
text-decoration: none;
}
ul li a span {
float: left;
width: 11px;
height: 11px;
margin-left: -13px;
margin-right: 5px;
top: 4px;
border: 1px solid #d1d3d7;
position: relative;
transition: all 0.5s ease-in-out;
}
ul li a span.active {
background: green;
}
HTML
<li>
<a href=""><span class="list"></span>Electronics</a>
</li>
<li>
<a href=""><span class="list"></span>Clothes</a>
</li>
<li>
<a href=""><span class="list"></span>Home & Office</a>
</li>
</ul>
JQUERY
e.preventDefault(); $(this).parent().find(".list").addClass("active").siblings().removeClass("active");
});