468,133 Members | 1,420 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

accessing target's parent's id

Hello,

I am trying to access a certain id, but I don't know exactly how.
In my HTML I have the following.
....
<div id="abc123">
<input type="button" id="xyz789" />
</div>
....

Now I catch all the clicks with JS:
....
document.onclick = function(e) {
if (e.target.id == 'xyz789') {
// do something to 'parent' div so 'abc123'
...
}
}
....

This is my problem: How do I access the id name of the div containing
the target that was clicked?
I tried using the .parent.id properties, but that did not work. I tried
googleing, but I couldn't find anything relevant.
Can anyone give me a tip?

Thanks
C.
Oct 26 '06 #1
2 13852
Casper Feldmann wrote:
Hello,

I am trying to access a certain id, but I don't know exactly how.
In my HTML I have the following.
....
<div id="abc123">
<input type="button" id="xyz789" />
</div>
....

Now I catch all the clicks with JS:
....
document.onclick = function(e) {
if (e.target.id == 'xyz789') {
// do something to 'parent' div so 'abc123'
...
}
}
....

This is my problem: How do I access the id name of the div containing
the target that was clicked?
I tried using the .parent.id properties, but that did not work. I tried
parentNode.id

--
Ian Collins.
Oct 26 '06 #2
Thanks!
>

parentNode.id
Oct 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by RWD | last post: by
1 post views Thread by nets | last post: by
11 posts views Thread by john woo | last post: by
36 posts views Thread by randau | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.