jQuery: delegating clicks to elements that contain other elements

Posted by Master Morality on Stack Overflow See other posts from Stack Overflow or by Master Morality
Published on 2010-04-01T15:13:37Z Indexed on 2010/04/01 15:33 UTC
Read the original article Hit count: 297

Filed under:

So i get the gist of $.delegate and I know why it's doing what it's doing, but I'm wondering if there is a work around.

I have link elements that contain spans like so:

<a href='#'>
    <span>Person Name</span>
    <span>Person Info</span>
</a>

I use the following code in jQuery for event delegation:

containerElement.delegate('click','a',function(){...});

The trouble is that this only triggers when I click on white space not occupied by a span. I know it does this because delegate simply compares the event target to 'a' to check if it should fire the delegate, however I want to include the spans as well, pretty much anything inside the <a>...</a>

what do?

© Stack Overflow or respective owner

Related posts about jQuery