2

I have a issue with click event. I am using jPList plugin and I have a click function for each result set. The first page click function is working correctly, but when I select second or third page and click the button it doesn't get fired.

HTML

<!-- demo -->
<div id="demo">

<!-- panel -->
<div class="jplist-panel">

<!-- pagination control -->
<div class="jplist-pagination" data-control-type="pagination" data-control-name="paging" data-control-action="paging" data-items-per-page="2">
</div>

</div>

<!-- HTML data -->
<div class="list">

<!-- item 1 -->
<div class="list-item">
  <p>
    first result
  </p>
  <p class="hitme">
    click me
  </p>
  <hr>
</div>

<!-- item 2 -->
<div class="list-item">
  <p>
    second result
  </p>
  <hr>
</div>

<!-- item 3 -->
<div class="list-item">
  <p>
    thrid result
  </p>
  <button class="hitme">
    click me
  </button>
  <hr>
</div>

<!-- item 4 -->
<div class="list-item">
  <p>
    fourth result
  </p>
  <hr>
 </div>
 <hr>

 <!-- item 5 -->
 <div class="list-item">
  <p>
    fifth result
  </p>
  <button class="hitme">
    click me
  </button>
  <hr>

 </div>

 <!-- item 6 -->
 <div class="list-item">
  <p>
    sixth result
  </p>
   </div>
 </div>
 </div>

jQuery

$('document').ready(function() {

$('#demo').jplist({
itemsBox: '.list',
itemPath: '.list-item',
panelPath: '.jplist-panel'
});

$('.hitme').on('click', function() {
 alert('clicked');
})

});

Can anyone help me with this please.

See the JSfiddle

Arulkumar
  • 12,966
  • 14
  • 47
  • 68

2 Answers2

2

Try this code

$('document').ready(function() {
      $('#demo').jplist({
         itemsBox: '.list',
         itemPath: '.list-item',
         panelPath: '.jplist-panel'
      });
      $("body").on('click', '.hitme', function(){
         alert('clicked');
      });
   });
Amit Kumar
  • 467
  • 2
  • 14
0

Since the element is not yet generated hence the click event is not bind. Delegate the event from some element which is already loaded, I changed the 'click' event to as shown below:

$(document).on('click', '.hitme' , function() {
    alert('clicked');
  })

Demo

Cheers,

Ashok