[jQuery] Binding function not working after several elements loaded
I am binding a ajax call to an image tag for a script that displays blog comments hierchichally. The ajax call executes a PHP script that marks a comment to be deleted afterwards.
The binded function does not work when there are too many comments on a page. Although the problem appears randomly, I found out that it occurs consistently on pages that have lots of comments (it will work for, say, the first 20 comments only).
Here is the <span style="font-style: italic;">ready <span style="font-style: italic;"><span style="font-style: italic;"><span style="font-style: italic;"></span></span></span></span>code:
<script language="javascript">
$(document).ready(function(){
// Your code here
$("#docs div").find("img").click(function(){$.get("/ajx_incr_docvista.php?id="+this.title);}); // incrementar vista a imagen
$("#comentarios2 div").find("img.basurerito").click(function(){$.get("/ajx_del_comment.php?id="+this.title, function(){alert("Comentario marcado para borrar"); return;});});
//$("#docs div").find("img").click(function(){alert("<a href="http://www.dealante.com/ajx_incr_docvista.php?id=">http://www.dealante.com/ajx_incr_docvista.php?id=</a>"+this.title); return false;});
});
</script>
The HTML for the "delete" image is:
<pre id="line2591"><<span class="start-tag">a</span><span class="attribute-name"> href</span>=<span class="attribute-value">
"#478162"</span>><<span class="start-tag">img</span><span class="attribute-name"> title</span>=<span class="attribute-value">'478162' </span><span class="attribute-name">class</span>=<span class="attribute-value">
'basurerito' </span><span class="attribute-name">alt</span>=<span class="attribute-value">'Borrar comentario' </span><span class="attribute-name">src</span>=<span class="attribute-value">'delete_message.gif'</span><span class="attribute-name">
/</span>></<span class="end-tag">a</span>> </pre>
THanks in advance.<br clear="all">
--
**** Ivan Quintero
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/