How to only reference one element when using .live("click" with elements within each other?

Posted by think123 on Stack Overflow See other posts from Stack Overflow or by think123
Published on 2012-09-01T09:27:47Z Indexed on 2012/09/01 9:38 UTC
Read the original article Hit count: 154

Filed under:
|
|
|
|

Suppose I have the following code:

<div id="outerrt">
  <div id="rt" style="width: 200px; height: 200px; border: 1px solid black;">
    <span id="rt2">content</span>
  </div>
</div>

And I use the following:

$("#outerrt *").live("click", function () {
  alert($(this).attr('id'));
});

What it would give me when I click on the content text is three alert windows, in the following order:

rt2

rt

outerrt

What I actually want it to give me is only one id: rt2. How do I accomplish that?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery