jquery - how to change the navigation item color when it will active? -
my css style have
#nav { position: relative; }
and html code
<div class="header-background"> <!-- <div> --> <div id="logo">site title</div> <div id="nav"> <nav id="desktop-nav"> <a class="nav-item" href="#1">about</a> <a class="nav-item" href="#2">news</a> <a class="nav-item" href="#3">community</a> <a class="nav-item" href="#4">docs</a> </nav> </div>
here have about,news,community,docs these 4 field..i want when click button suppose "about" time "about" button color change yellow , other buttons text color white... so,i using jquery
$(".desktop-nav a").live("click",function(){ $(".desktop-nav a").removeclass("active"); $(this).addclass("active"); });
but color not changing..guys suggest me something..
as of jquery 1.7, .live() method deprecated. use .on() attach event handlers.
according html code, nav tag has id not class.
here working code:
$("#desktop-nav a").on("click", function(){ $("#desktop-nav a").removeclass("active"); $(this).addclass("active"); });
Comments
Post a Comment