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.

http://jsfiddle.net/6kdhg/3/

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

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -