jquery - Changing CSS background color for one link while on that page -
hey trying change background color of link in nav different color rest of nav links when user on particual page link for.
the code is:
$("#nav li ul li #changebg1").css("background-color","red"); and nav html looks little this:
<ul id="nav"> <li><a href="index.php">home</a></li> <li><a href="custhelp.php">who are</a> <ul> <li id="changebg1"><a href="about.php">about</a></li> <li id="changebg2"><a href="help.php">team</a></li> </ul> </li> however, not seem change one, changes of them. can not seem find out how call id of nav , id of changebg1 1 change.
the jquery code is:
var url = window.location.href; url = url.substr(url.lastindexof("/") + 1); $("#thenav").find("a[href='" + url + "']").addclass("thenavsbg"); if (url == 'about.php'){ $("#nav li ul li #changebg1").css("background-color","red"); } any great! thanks!
try this:
$("#changebg1").css("background-color","red"); id best selector, don't need add "stuff".
you can add class li:
$("#changebg1").addclass('foo'); anyway, looks likt selector should be:
$("#nav li ul li#changebg1").css("background-color","red");
Comments
Post a Comment