php - How get content of a dynamically appended <div> on click? -
this question has answer here:
i have php file:
$sql = mysql_query("select id, name table") or die(mysql_error()); if (mysql_num_rows($sql) > 0){ while($row = mysql_fetch_array($sql)){ echo "<div class=\"content-row\"> <div class=\"row-1\">".$row['id']."</div> <div class=\"row-2\">".$row['name']."</div> </div>; } }
in js file:
success: funxction(data){ $(".content").html(data); }
in html file have:
<div class="content"> // here ajax put divs </div>
how can content of <div class="row-1"></div> or <div class="row-2"></div>
when click on button? button situated out of .content
area. clicked on row, lighted , click on button. when clicked on button, want id , name div content row lighted.
............................................. update: have js code: http://pastebin.com/bju8kp3l
when click on button, check if row selected; if not selected receive notification, if row selected want receive div content :)
you have use event-delegation dynamic created elements,
bind click-handler on static element, , delegate event dynamic ones:
$('.content').on('click', '.content-row > div', function(){ $(this).text(); //or $(this).html(); });