Forum Moderators: open
Is it possible to set a textual anchor to link to another part of a page and the text where the anchor has linked to changes format e.g colour, bold etc?
---------------------------------------------------
ANCHOR LINK TO SECTION 1
ANCHOR LINK TO SECTION 2
SECTION 1
dskjflsdaflkadsflldf adsl kfjdslkj flkasd
d;ljkdasl;flksdaflkajsdlflsdajf
SECTION 2
flkjflkdjlkjaldjflksdajlf
dfsfjsaldflksdaflkajlfds
---------------------------------------------------
Note: I dont want change "ANCHOR LINK TO SECTION 2" text format on click I want to change the SECTION 2 text. Also if possible to change back when another anchor link is clicked.
Hope you understand
Thanks
Steve
You will be able to do this with a combination of Javascript and DHTML.
You need to trap the "onclick" event for the source anchor, and then use the DOM (document object model) to change the innerHTML of the target text to include some different font attributes.
Google for "javascript DHTML" to learn the mechanics.
<body><script type='text/javascript'>
var prev = '';
function do_highlight(name)
{
if(prev)
{
document.getElementById(prev).style.color = 'blue';
}
document.getElementById(name).style.color = 'red';prev = name;
}</script>
<a href='#1' onclick='do_highlight("one");'>LINK TO SECTION 1</a>
<br>
<a href='#2' onclick='do_highlight("two");'>LINK TO SECTION 2</a>
<hr>
<a name='1'></a><h2 id='one' style='color:blue;'>SECTION 1</h2>
foo foo foo foo foo foo
<hr>
<a name='2'></a><h2 id='two' style='color:blue;'>SECTION 2</h2>
bar bar bar bar bar bar
</body>