Skip to content Skip to sidebar Skip to footer

Target A Link If That Link Links To The Current Page?

this may be a stupid question as I can't seem to find an answer :P Is there a way with javascript/jQuery to Target all links on a page ONLY if they link to the current page? Say i'

Solution 1:

Try the following:

<!DOCTYPE html><html><head><scriptsrc="http://code.jquery.com/jquery-latest.js"></script></head><body><ulid="sidebar"><li><ahref="/one">One</a></li><li><ahref="/two">Two</a></li><li><ahref="/three">Three</a></li></ul><script>var pathname = window.location.pathname;
//$("a:contains('One')").css("color", "red"); // This will make One red (notice capital O)
$("a:contains(pathname)").css("color", "red");

</script>

Post a Comment for "Target A Link If That Link Links To The Current Page?"