php - JQuery calling .click() on an autogenerated img inside -
i'm using this
xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("pichint").innerhtml=xmlhttp.responsetext; } } xmlhttp.open("get","getpic.php?q="+str+"&t=" + math.random(),true); xmlhttp.send();
to pass in data , generate undefined amount of pictures echo php code in getpic.php
while($row = mysql_fetch_array($result)){ echo "<div id=" . $num . "><img src=qr/" . $row['img']".png></div>"; }
so these pictures come out generated, however, i'm trying use
$("#img").click(function () { alert("hi"); });
but nothing gets alerted. top function posts stuff in can't seem call inside id? how can call div or img inside outer div?
if you're generating content asynchronously, $.click()
won't work unless manually attach each new element. try using $.live()
instead:
// applies <img /> tags. $("img").live("click",function(){ alert("hi"); });
be sure check id
s well, , note using integers id not practice. if wish use numerical id of image id, preface type of alpha-value, such #image19
.
Comments
Post a Comment