[thelist] Bit of javascript help

Dan Parry dan at virtuawebtech.co.uk
Tue Jan 22 09:52:33 CST 2008


Hi all

Got a bit of a problem that I just can't figure out... I'm calling an
initialise function (for [largely] unobtrusive JS) that grabs all the A tags
on the page then attaches an onmouseover/onmouseout event for each tag that
matches a certain class name... Here is the code:

for(var i=0; as[i]; i++) {
	if(as[i].className == 'snipHelp') {
		var t = as[i].id; // scope resolution
		addDiv = true; // ignore me, I don't affect this portion of
the script
		as[i].onmouseover = function () {  xhr.showHelp(t, true); }
		as[i].onmouseout = function () { xhr.hideHelp(); }
	}
}

The function works but if there is more than one link on the page that has
the class name I'm looking for only the last  ID (var t = as[i].id) is
applied to every (intended) link

So if I have 2 links, 1 with the ID of test and the second with the ID of
anothertest, anothertest is sent to the function for each onmouseover

Does that make sense?

Thanks in advance

Dan

PS I sent this earlier but it didn't seem to turn up... I hope I haven't
invaded peoples inboxes twice

-- 
Dan Parry

No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.516 / Virus Database: 269.19.8/1236 - Release Date: 21/01/2008
20:23
 




More information about the thelist mailing list