Code Snippet
Highlight All Links To Current Page
$(function(){
$("a").each(function(){
if ($(this).attr("href") == window.location.pathname){
$(this).addClass("selected");
}
});
});This function will add the class "selected" to any links (even relative) that point to the current page.
I’m looking for a script that has a menu that shows what part of the page ur on. EX:
LINK 1 LINK2 LINK3 (bold cause ur on that area)
LINK 3 Area
This is exactly what I’m looking for, but I’m unsure how to deploy it…
Does this need to go in Script tags in the Head section of my page?
How do I define the “selected” class in my styles.css sheet?
How can I edit this line:
if ($(this).attr(“href”) == window.location.pathname){
into something that may result to true as long as the pathname is found. I need an alternative for the == operators. Is there something in JS that emulates SQL’s “LIKE”?
Thanks.
Thank you very much for this, there are hundreds of scripts about that do this , but this is the first one that actually works, does what it says on the tin. You are a genious, and have saved me a lot of pain, Thanks again!!!!!!!!!
Ah, this is so difficult! I don’t understand any of it :(
I guess I’ll just have to pay someone to keep working on my site.
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.