php - Jquery on click event not working after infinitescroll -


i'm using cakephp framework , jquery infinitescroll plugin loading content dynamically. , each post has link ajax action.

when load page there 5 posts , ajax links working fine. when load 5 other posts infitescroll (ajax) ajax link not working.

it looks ajax function cannot find id of link don't find solution.

 <a href="/questions" onclick="return false"><i class="glyphicon glyphicon-circle-arrow-right" id="581617"></i></a>  <script type="text/javascript">  $(document).on("click","#581617",function(){         $.ajax({url: "the_url",                      type:'post',            })   });     </script> 

update: after making changes based on @zacharykniebel's solution, trying write selector attach links id using below, not working. can tell me why?

"a > i.glyphicon.<?php echo $linkid;?>" 

it looks delegating handler element id #581617. instead, try delegating handler more broadly a > i.glyphicon.glyphicon-circle-arrow-right elements:

$(document).on("click","a > i.glyphicon.glyphicon-circle-arrow-right",function(){     $.ajax({         url: "the_url",          type:'post'     });    }); 

as side-note, in above removed trailing comma after type:'post' sake of ie functionality. although keeping trailing comma technically valid, ie doesn't much.


update:

with regards selector trying use, note can't have selector work newly loaded links if selecting them id. there workarounds technically this, they're incredible dirty , have awful performance. because ids unique , binding handler id trying bind each link individually, instead of binding of links @ once. (technically, since delegated handler, you're not binding links, listening them).

in short, selector gave you, above, want use make event handler listen of them.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -