Simple Javascript question

9 views
Skip to first unread message

Eyal

unread,
Jul 31, 2012, 7:05:15 AM7/31/12
to webmaste...@googlegroups.com
Hi guys,

I'm using the following javascript to change the color of links after clicking them (credit and thanks to  www.vicsjavascripts.org.uk/Home.htm)

var Lst;

function CngClass(obj){
 if (Lst) Lst.className='';
 obj.className='selected';
 Lst=obj;
}

The links then all have this added to them:

onclick="CngClass(this);"


It works fantastically. Now I would like the first link to already be highlighted (having the class "selected") on loading the page.
I tried giving the link an id, say xxxx, and then: body onload="CngClass('xxxx');"
This works in IE, Chrome, and Safari; but FF gives an error: xxxx is not defined.

Apparently it's wrong, but I don't know how to fix it: how to define xxxx? Any alternative solution to highlighting the first link is welcome.

Thanks
Eyal

Jeremy Geerdes

unread,
Jul 31, 2012, 9:33:13 AM7/31/12
to webmaste...@googlegroups.com
Try onload="CngClass(document.getElementById('xxxx'));"


Jeremy R. Geerdes, Pastor
Debra Heights Wesleyan Church
4025 Lower Beaver Rd
Des Moines, IA 50310



AIM/iChat: jgee...@mac.com
Google Talk/MSN Messenger: jrge...@gmail.com
Yahoo! Messenger: jeremy....@yahoo.com
IRC: jgeerdes on Freenode and Geekshed



--
You received this message because you are subscribed to the Google Groups "Webmasters Helping Webmasters" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webmaster-support/-/bvGauzTN0zwJ.
To post to this group, send email to webmaste...@googlegroups.com.
To unsubscribe from this group, send email to webmaster-supp...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webmaster-support?hl=en.




Jeremy R. Geerdes
Generally Cool Guy
Des Moines, IA

For more information or a project quote:

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!

Eyal

unread,
Jul 31, 2012, 10:20:40 AM7/31/12
to webmaste...@googlegroups.com
Thank you very much sir, this was the solution!

Eyal
Reply all
Reply to author
Forward
0 new messages