/    Sign up×
Community /Pin to ProfileBookmark

Question concerning event.srcElement.parentNode

Is there an equivalent epression for the below that will work in FireFox?

[code]
var element=event.srcElement.parentNode;
[/code]

Thanks…

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterNov 03.2005 — In Firefox you'd use target in place of srcElement and you'll need to refer to the function's first argument to get the event object.
<i>
</i>var element=arguments[0].target.parentNode;
Copy linkTweet thisAlerts:
@UltimaterNov 03.2005 — A cross-browser approach, depending on what event is used, would look like this:
<i>
</i>function whatever(e){
if(!e)e=window.event;
var t;
if(e.srcElement)
t=e.srcElement.parentNode
else if(e.target)
t=e.target.parentNode
else
return true;

//alright, var "t" contains the parentNode
//what now!?
alert(t?1:0);

}


This chart should prove quite useful:

http://www.quirksmode.org/dom/w3c_events.html
Copy linkTweet thisAlerts:
@Mike_BurdickauthorNov 03.2005 — Ultimater,

Thanks for the help!

I tried your code and it works just fine in IE but when I try it in Firefox it doesn't work at all!

Attached is a simple page that works fine in IE but when I run it in Firefox I get nothing. It won't even to to the alert. Do you know what the problem is?

<i>
</i>&lt;html&gt;

&lt;head&gt;
&lt;script type="text/javascript"&gt;

function whatever(e){
if(!e)e=window.event;
var t;
if(e.srcElement)t=e.srcElement.parentNode;
else if(e.target)t=e.target.parentNode;
alert(t);
return true;
}


&lt;/script&gt;
&lt;/head&gt;
&lt;body onmousedown="whatever()"&gt;

This is a test

&lt;/body&gt;
&lt;/html&gt;

Copy linkTweet thisAlerts:
@UltimaterNov 03.2005 — Almost, just one little addition:
<i>
</i>onmousedown="whatever([color=blue]event[/color])"
Copy linkTweet thisAlerts:
@UltimaterNov 03.2005 — Why not just use [i]this[/i]?
<i>
</i>&lt;body onmousedown="whatever(this)"&gt;

<i>
</i>&lt;script type="text/javascript"&gt;
function whatever(t){
t=t.parentNode;
alert(t);
return true;
}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@Mike_BurdickauthorNov 03.2005 — Ultimater,

Thanks!

I really do appreciate your help and examples!!! ?

Mike
Copy linkTweet thisAlerts:
@Mike_BurdickauthorNov 03.2005 — Ultmater,

Oops...one more question.

For the code I'm actually using I get the value for "t" to be [object HMTLdivElement]. How do I get the name of that element?
Copy linkTweet thisAlerts:
@UltimaterNov 03.2005 — "t" is an element similar to that which is returned from the DOM document.getElementById method.
alert(t.getAttribute("name"));
// alerts "null" if the tag's name attribute is not set.
×

Success!

Help @Mike_Burdick spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...