[Javascript] Problem w/Javascript, interpolation, functions, onclick

Matt Warden mwarden at gmail.com
Wed Oct 25 12:44:24 CDT 2006


On 10/25/06, Paul Novitski <paul at juniperwebcraft.com> wrote:
>                  // now act on the object whose behavior triggered
> this function
>                  var sClass = this.tagName;       // etc.

This is incorrect. In IE, events are executed in the window scope, so
when you do this.tagName, it is equivalent to doing window.tagName.
You must get the target element from the event itself, as I suggest
here:

http://mwarden.f2o.org/sandbox/getidfromeventhandler.js

You can alternatively specify the scope in which the handler should
run. YUI does this. You can see how they are doing it in their source:

doc:
http://developer.yahoo.com/yui/docs/event/YAHOO.util.Event.html#addListener

source:
http://developer.yahoo.com/yui/docs/event/overview-summary-Event.js.html

-- 
Matt Warden
Cleveland, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the Javascript mailing list