function RemoveGroup(event)
{
alert(event.target.id) //event.target is the clicked
element, this
will alert 'foo'
}
var anchor=document.getElementById('foo'); // get a
refernence to the a
anchor.addEventListener('click', RemoveGroup, true);
In conclusion: the object passed to the handler
(RemoveGroup) is an
event object. Most intresting property of the event object
is target,
which is the node that fired the event.
On 8/4/06, IndaUK <indauk gmail.com> wrote:
>
> Thanks again but one problem leads to another...
>
>
> I have injected many elements into the webpage, each
with a different ID.
>
> e.g. "<span
id='group_" + foo[i] +
"'>[-]</span>"
>
> I later add the event listeners by:
>
> var a =
document.getElementById("group_" + foo[i]);
>
a.addEventListener("click",
RemoveGroup, true);
>
>
>
> I need to pass a string (or the element ID or the
element object) to my
> original function.
>
> "a.addEventListener('click', RemoveGroup,
true);" seems to pass an object to
> my function but I don't know what to do with it.
>
> function RemoveGroup(sGroupName)
> {
>
alert(sGroupName) &am
p;nbsp; //r
eturns
> "[object XPCNativeWrapper [object
MouseEvent]]"
>
alert(typeof(sGroupName)) &
nbsp; //returns
> "object"
> }
>
>
> The docs on XPCNativeWrapper confuse me. How can I
reference the element
> that was clicked?
>
> Any ideas?
> --
> View this message in context: http://www.nabble.com/C
alling-a-function-in-GM-from-injected-HTML-tf2052532.html#a5
657879
> Sent from the MozDev - greasemonkey forum at
Nabble.com.
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey mozdev.org
> http:
//mozdev.org/mailman/listinfo/greasemonkey
>
_______________________________________________
Greasemonkey mailing list
Greasemonkey mozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
|