accessing target's parent's id

C

Casper Feldmann

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.
 
I

Ian Collins

Casper said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top