How To Add Class To Tag When I Click On It
I need to add class='active' to tag when i click on to become Notice i have multiple tags and i need to class='active' o
Solution 1:
Use .parent()
and .addClass()
$(function(){
$('a').click(function(e){
e.preventDefault();
$(this).parent().addClass('active');
})
})
.active {
background-color: orange;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="nav">
<li>
<a href="#">
Personal Informations <i class="pe-7s-user"></i>
</a>
</li>
<li>
<a href="#">
Qualifications <i class="pe-7s-note2"></i>
</a>
</li>
</ul>
Post a Comment for "How To Add Class To Tag When I Click On It"