NewCod3r NewCod3r - 2 months ago 23
HTML Question

Delegate function not work in jquery 2.1.1

I have This code for load content in

for pagination using jQuery

JS :

<script type="text/javascript">
$('#comment-list .pagination a').delegate('click', function() {



return false;

$('#comment-list').load('index.php?route=simple_blog/article/comment&simple_blog_article_id=<?php echo $simple_blog_article_id; ?>');



<div id="comment-list">
<div class="pagination">
<div class="links">
<a href="http://localhost/oc/index.php?route=simple_blog/article/comment&amp;simple_blog_article_id=5&amp;page=2">2</a>
<a href="http://localhost/oc/index.php?route=simple_blog/article/comment&amp;simple_blog_article_id=5&amp;page=3">3</a>
<a href="http://localhost/oc/index.php?route=simple_blog/article/comment&amp;simple_blog_article_id=5&amp;page=2">&gt;</a>
<a href="http://localhost/oc/index.php?route=simple_blog/article/comment&amp;simple_blog_article_id=5&amp;page=3">&gt;|</a> </div><div class="results">Showing 1 to 5 of 11 (3 Pages)

But In action My code not work and not load content in
. after click in pagination link, I see open new window and load my content. I test my code in
jQuery 2.1.1
Version and I think
not work in
jQuery 2.1.1

How do fix my problem?


As of jQuery 3.0, .delegate() has been deprecated. It was superseded by the .on() method since jQuery 1.7, so its use was already discouraged.

For earlier versions, however, it remains the most effective means to use event delegation. More information on event binding and delegation is in the on() method.

Use event delegation on() instead :

$('body').on('click', '#comment-list .pagination a', function() {

Hope this helps.