View Full Version : Highlight Named Anchor Destination

09-27-2012, 07:32 PM
Objective: When a link to a named anchor is clicked, have the named anchor get a background highlight to make it stand out.


The links of course send you just fine to the anchor, and now I would like the anchored element, in this case the respective <h> tags, to have a highlighted background when their link has been selected.

I've dug around & found a couple scripts, but I'm doing something wrong; I can't get them to work.

In the moment I have this in the head of document and no other new code added:

<script type="text/javascript">
function highlightAnchor(name) {
location.hash = name;
document.getElementById(name).style.backgroundColo r = "#CCCCCC";

Correct finish to this or does anyone have a working script laying around?

09-29-2012, 04:35 PM
With jQuery


Without jQuery


09-29-2012, 09:19 PM
Like a champ, thank you sir...