1

I have a list (when the page is loaded):

<ul class="pagination" id="pagination">
//content load with ajax
</ul>

The dynamic content is loaded from an Ajax request :

success: function(data){
        if(data.status == "success"){
          $('#pagination').html(data.pagination);
        }
      }

and then the ul element with "id pagination" become per example (can be more than only 2 page):

<ul class="pagination" id="pagination">
    <li class="active" value="1"><a href="#">1</a></li>
    <li value="2"><a href="#">2</a></li>
    <li class="next"><a href="#" class="mdi mdi-chevron-right"</a</li>
</ul>

I want then to get the "li" clicked and get his value, so far I have done this but it doesn't work.

$(document).ready(function() {
    $('#pagination li').on('click', function(e) {
      console.log("Page : "+$(this).val());
    });
  });

Thanks in advance

2
  • Please share the Ajax call function so I can give you the full code Commented Sep 22, 2016 at 1:31
  • But actually my Ajax function set the pagination as: success: function(data){ if(data.status == "success"){ $('#pagination').html(data.pagination); } } Then I want to handle click on the "li" element that I just set. Commented Sep 22, 2016 at 1:42

1 Answer 1

1

Move this code

$('#pagination li').on('click', function(e) {
  console.log("Page : "+$(this).val());
});

to the success function of the ajax call,
because it is now excute just after the page load and before the ajax request done, so you have to do after your ajax request and rendering the new html code

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.