Child element being passed to handler?

0 views
Skip to first unread message

Jon

unread,
Jun 22, 2006, 10:34:56 AM6/22/06
to event:Selectors
I have something like this on my page :
<div id="container">
<h1 id="innertext">HELLO!</h1>
</div>

and this event-selector rule:

'#container:mouseover' : function(element) {
new Insertion.After($('container'), "Mouse over "+element.id+"<br/>")
}

I would expect the element that gets passed into that function to
always be $('container'), but it's not - I usually get the child
element ( $('innertext') )


Is there any way of getting the element that the rule was originally
applied to?

Sam

unread,
Jun 22, 2006, 11:20:21 AM6/22/06
to eventse...@googlegroups.com
Here's a modification I made to Event Selectors that solves this problem:

Change:

observer = function(event) {
var element = Event.element(event);
if (element.nodeType == 3) // Safari Bug (Fixed in Webkit)
element = element.parentNode;
rule.value($(element), event);
}

To:

observer = function(event) {
var eventElement = Event.element(event);
if (eventElement.nodeType == 3) // Safari Bug (Fixed in
Webkit)
eventElement = eventElement.parentNode;
rule.value($(element), event, element);
}

This change adds an optional 3rd parameter "element" which will always be
the element selected by your selector.

Sam

Sam

unread,
Jun 22, 2006, 11:24:27 AM6/22/06
to eventse...@googlegroups.com
My mistake. The last line should be

rule.value($(eventElement), event, element);

Sam

SCREECH

unread,
Jun 30, 2006, 12:09:19 PM6/30/06
to event:Selectors
SAM,

thank you ...
you saved my day...

please put this into the normal event:selectors release...
otherwise it is not useable for complex web design...

best regards,
Screech

Jeff

unread,
Jul 9, 2006, 9:26:06 AM7/9/06
to event:Selectors
Simply commenting out the line

var element = Event.element(event);

worked great for me. It doesn't appear that it's necessary.

Ben Schwarz

unread,
Jul 10, 2006, 12:09:51 AM7/10/06
to event:Selectors
This also worked for me.
I haven't checked cross browser yet - I'll post any issues I find.
Reply all
Reply to author
Forward
0 new messages