Link to home
Start Free TrialLog in
Avatar of plq
plqFlag for United Kingdom of Great Britain and Northern Ireland

asked on

jQuery - how to assign an event to a group of controls with a common parent

Hi Folks.

I've got a html structure like this:

<div id="topdiv">
<table><tr>
<asp:placeholder id="content">
</tr>
</table>
</div>

The placeholder is populated with <td> elements and each one of those contains a structure in order of td > div > table > tr > td > div.

At that lowest level div, I want to assign a jquery click event. How could I do this in jquery code ?

I can of course lose the table elements and move to semantic html, but conceptually I just need to know how to assign an event to a group of elements, all with different ids, where they have a common parent.

thanks

ASKER CERTIFIED SOLUTION
Avatar of jorge_toriz
jorge_toriz
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of plq

ASKER

I extended what you said to this

$('#topdiv table tr td div table tr td div').onclick(function(event){var target = $(event.target); alert('You clicked a div element ' + target.attr("id"));});

target gives me the element that was clicked. So instead of adding an event to every element, I can capture it at the top level and it still gives me the lowest level element which is pretty cool..