On Sat, Nov 21, 2009 at 4:09 PM, Patrick Wiseman <[email protected]> wrote: > On Sat, Nov 21, 2009 at 3:57 PM, cc <[email protected]> wrote: >> On 2009-11-21 10:26, Patrick Wiseman wrote: >>> Hello GM'ers: >>> >>> I'm having a funny problem with this.getAttribute. Here's a couple of >>> code snippets: >>> >>> function doWhatever() { >>> def=this.getAttribute('id'); >>> } >>> >>> This, as expected, assigns the value of 'id' to def. >>> >>> function doWhatever(abc) { >>> abc ? def=abc : def=this.getAttribute('id'); >>> } >>> >>> If abc is present, this assigns abc to def; but if abc is absent, it >>> assigns [objectXPCNativeWrapper[objectMouseEvent]] to def (the >>> this.getAttribute comes from a mouse click on the element with the >>> 'id' attribute). >> Is this function an event handler, registered with addEventListener? If >> so, then I suspect that abc is not actually absent, but is being >> populated with the event parameter. Try adding an additional (first) >> parameter to catch the event and do whatever with it -- e.g. >> >> function doWhatever(evt, abc) { >> >> For example, you could use evt.target.id instead of this.getAttribute, I >> think. > > I bet you're right. I'll mess around with it some more and see if I > can fix it. Thanks.
cc was indeed correct; function doWhatever(e,abc) assigns the click event to 'e', so that I can call it as doWhatever(null,abc) and pass abc to the function as intended. Thanks cc! pw -- You received this message because you are subscribed to the Google Groups "greasemonkey-users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=.
