[thelist] [JS] hilite function for in-page link

Stephen Caudill SCaudill at municode.com
Wed Jul 9 10:34:16 CDT 2003

Wow!  I still have a ton to learn about JavaScript!  

Thanks to Tom, Hassan and David for your excellent suggestions.  Since I'm a 'keep it simple' kinda guy (well that and I won't use code I just plain don't understand), I'm using the suggestions from Hassan and Tom. This is what I ended up with:

function hilite(IDhref){
	// build array of ID's of questions
	var IDarray = new Array('techsup', 'contact', 'multi', 'noImport', 'missingPages', 'noAppear');
	// remove hiliting for any questions already hilited
	for(i=0; i<=IDarray.length-1; i++){
		document.getElementById(IDarray[i]).style.backgroundColor = "white";
	// get ID from anchor's href
	var hrefArray = IDhref.length
	var strID = IDhref.split('#');
	// hilite the appropriate question
	document.getElementById(strID[1]).style.backgroundColor = 'yellow';

and called it like this:
<a href="#contact" onclick="hilite(this.href)">blah blah blah</a>

Works Great!! :)

I'd have loved to have been able to do this a bit more programatically (as in David's example where the onclicks are added dynamically), but that's a bit beyond me at the moment... though if anyone knows any good tutorials, I'd love to hear about them.

Thanks Again,

More information about the thelist mailing list