0

I have a click event for an a pagination list

Its not firing.

$(".pagination-page").click(function()
{
    //event.preventDefault();

    var page = $(this).val();

    $('#search-results-display').load('includes/search.php?query=<? echo $_SESSION['search_term']; ?>&page=' + page);
});

PHP While loop generating the pagination (only the generation of the pagination not the rest of it. The SQL query is working, that has been tested

while ($tmpPageCnt > 0) 
{
    $retvar .= '<li class="active"><a href="#" class="pagination-page">'.$tmpPage.'</a></li>';
}

return $retvar;

Please could you shed some light as to why it's not

Zach Ross-Clyne
  • 779
  • 3
  • 10
  • 35

2 Answers2

1

Since you're dynamically creating it, I suppose you need to use event-delegation

$(document).on('click', ".pagination-page", function() {
    var page = $(this).text();
    $('#search-results-display').load('includes/search.php?query=<? echo $_SESSION['search_term']; ?>&page=' + page);
});

And since it is <a> you should be using .text() as anchors don't have values.

Amit Joki
  • 58,320
  • 7
  • 77
  • 95
-1

Changing .val(); to .html(); should solve the problem

chopper
  • 6,649
  • 7
  • 36
  • 53
msimmons
  • 146
  • 1
  • 3
  • 15
  • 2
    The actual event itself is not getting fired, so this, at this stage, is not an issue (will keep in mind though) – Zach Ross-Clyne Oct 13 '14 at 15:17
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – IdeaHat Oct 13 '14 at 15:37
  • @ZachRoss-Clyne - my apologies, as I was making a mock-up on my end, it appeared to not be fireing either. However it was just a case of nothing being returned by the .val(). I [wrongly] assumed that what corrected things in my mock-up was the entirety of your issue. – msimmons Oct 13 '14 at 21:20
  • @MadScienceDreams - I thought it was the answer to the question (see my reply to Zach), however it seems I was mistaken. – msimmons Oct 13 '14 at 21:21