Home > Article > Web Front-end > How to implement a navigation bar link to jump after clicking it, and add color to the corresponding link on the new page
html:
<p class="nav"> <ul> <li class="active"><a href="a.html">aaa</a></li> <li><a href="b.html">bbb</a></li> <li><a href="c.html">ccc</a></li> </ul> </p>
jquery:
$(".nav li a").each(function (i) { var $me = $(this); var lochref = $.trim(window.location.href); var mehref = $.trim($me.get(0).href); if (lochref.indexOf(mehref) != -1) { $me.parent().addClass("active"); } else { $me.parent().removeClass("active"); } });
css:
.active{background-color:#ed0505;}
The above is the detailed content of How to implement a navigation bar link to jump after clicking it, and add color to the corresponding link on the new page. For more information, please follow other related articles on the PHP Chinese website!