logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > Javascript and JS frameworks
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 09-27-2012, 06:32 PM   #1
johnMoss
johnMoss's Avatar
 
Join Date: Dec 2010
Location: Dallas
Posts: 867
Default Highlight Named Anchor Destination

Objective: When a link to a named anchor is clicked, have the named anchor get a background highlight to make it stand out.

http://www.yontif.com/faq.html

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:

Code:
<script type="text/javascript">
 function highlightAnchor(name) {
  location.hash = name;
  document.getElementById(name).style.backgroundColor = "#CCCCCC";
 }
</script>
Correct finish to this or does anyone have a working script laying around?
__________________
LinkedIn: jM
johnMoss is offline   Reply With Quote
Old 09-29-2012, 03:35 PM   #2
ranjan
 
Join Date: Dec 2004
Posts: 405
Default

With jQuery

http://jsfiddle.net/JQzgP/

Without jQuery

http://jsfiddle.net/uH4UP/

Last edited by ranjan; 09-29-2012 at 03:52 PM..
ranjan is offline   Reply With Quote
Old 09-29-2012, 08:19 PM   #3
johnMoss
johnMoss's Avatar
 
Join Date: Dec 2010
Location: Dallas
Posts: 867
Default

Like a champ, thank you sir...
__________________
LinkedIn: jM
johnMoss is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:28 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com