dynamically add listener to ajax created content in jQuery
- by davidP
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>