ajax - Read dynamically created elements data attribute in jquery? -
this code http://jsfiddle.net/amolw/6kdhg/
buttons created dynamically (usually data buttons come through ajax request). simplicity i've hard coded values.
problem when execute thishotel = $(this).data('hname'); undefined in variable thishotel.
same thing happens if replace buttons anchor tag.
this in example div id=hotels. have worked if have gone div , selected button. propose solution though.
you can use target of event information want.
$("[id^='hotel']").on('click', function (e) { thishotel = $(e.target).data('hname'); $("#selected").html("selected hotel " + thishotel); }); e event got triggered , access it's target.
Comments
Post a Comment