Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jschulbach

macrumors newbie
Original poster
Jun 29, 2010
15
0
Is it possible to have an onClick on a div that has multiple children then query the onclick event to see which child was clicked? I could just put an onclick on each child div but it seemed redundant if I could get away with just one. I tried sending the event as an argument to my function. When I alert the target I get the id of the parent if it is clicked but the alert when I click a child is blank.
 
It's called bubbling, or event propagation, or event delegation. Those terms should help you find articles and tutorials for this. I've used them myself and are very handy.
 
It's called bubbling, or event propagation, or event delegation. Those terms should help you find articles and tutorials for this. I've used them myself and are very handy.

I knew about the basic concept of bubbling and propagation but couldn't seem to find what I was looking for searching for those. Searching for event delegation brought me to this http://cherny.com/webdev/70/javascript-event-delegation-and-event-hanlders which is exactly what I needed. Thanks for the help!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.