Assalamu'alaikum wr wb,
kali ini saya akan share bagaimana Cara ganti menu aktif di javascript.
Berikut ini syntaxnya :
--------------------------------------------------------------------------------------
<style type="text/css">
.active {
background-color:maroon;
color:white;
}
#navMenus {
list-style:none;
width:100px;
float:left;
text-align:center;
}
li {
cursor:pointer;
}
</style>
<ul id="navMenus">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
</ul>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script type="text/javascript">
$("#navMenus").on('click', 'li', function () {
$("#navMenus li.active").removeClass("active");
// adding classname 'active' to current click li
$(this).addClass("active");
});
</script>
--------------------------------------------------------------------------------------
Semoga bermanfaat.
http://pangeran-it.blogspot.co.id/
Cara ganti menu aktif di javascript
Reviewed by Syawaluddin Amin, S.Kom
on
Maret 27, 2017
Rating:
Tidak ada komentar: