[thelist] [JS] hilite function for in-page link
Hassan Schroeder
hassan at webtuitive.com
Wed Jul 9 09:37:12 CDT 2003
Stephen Caudill wrote:
>So my thought was to simply change the color of the question once
> a link had been clicked...
> function hilite(IDhref){
> var lenID = IDhref.length
> var strID = IDhref.substring(1,lenID);
alert(strID);
> document.getElementById(strID).style.color = 'blue';
> }
>
> and called it like so:
>
> <a href="#example" onclick="hilite(this.href)">example</a>
The alert() inserted above shows that your IDhref value is actually
'http://www.mccinnovations.com/support/faq_test.asp#contact' rather
than just '#contact'; so strID is
'ttp://www.mccinnovations.com/support/faq_test.asp#contact'
I'd suggest that, rather than substring() you use
var strID = IDhref.split('#');
document.getElementById(strID[1]).style.color = 'blue';
Couple minor things: 'blue' isn't very distinctive, since your links
are also blue; if it were me, I'd set the background-color to yellow,
or something a little more obvious.
And don't forget you'll also need to turn *off* the selection when a
user stays in the same page and clicks on another link :-)
HTH!
--
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design === (+1) 408-938-0567 === http://webtuitive.com
dream. code.
More information about the thelist
mailing list