dynamically add listener to ajax created content in jQuery

Posted by davidP on Stack Overflow See other posts from Stack Overflow or by davidP
Published on 2010-03-31T12:14:36Z Indexed on 2010/03/31 12:23 UTC
Read the original article Hit count: 351

Filed under:
|
|
|

I am trying to get the html value of a linked clicked. The links are created dynamically with Ajax so I don't think .bind will work and I don't have latest version with .live

$('div#message').click(function() {
  var valueSelected = $(this).html();  // picks up the whole id. I juust want single href!          
  alert(valueSelected);
  return false;
});



<div id="message">
<br/>
<a class="doYouMean" href="#">location A</a>
<br/>
<a class="doYouMean" href="#">location B</a>
<br/>
<a class="doYouMean" href="#">location C</a>
<br/>
<a class="doYouMean" href="#">location D</a>
<br/>
<a class="doYouMean" href="#">location E</a>
<br/>
</div>

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about bind