0

When i click on Reject Button

I am calling/ triggering next button click event .

Is it possible to know from the in the next event function if the request has come by calling reject ??

This is my jsfiddle http://jsfiddle.net/6xskkzjh/9/

This is my code

  <input type="button" id="next" value="Next">

   <input type="button" id="prev" value="Prev">

 <div id="countdiv">
     <Span>Showing  </Span> Of <span>Items</span>
</div>

        <input type="button" value="Reject One Item" id ="reject">



var totalcount = 10;
var current_count = 0;



$(document).on('click', '#prev', function (event) {
    if (current_count > 1) {
        current_count--;
        updateDiv();
    }
});

$(document).on('click', '#next', function (event) {
    if (current_count < totalcount) {
        current_count++;
        updateDiv();
    }
});

function updateDiv() {
    $('#countdiv').html('Showing ' + current_count + ' of' + totalcount + ' items');

}


$(document).on('click', '#reject', function (event) {
    totalcount--;
    $("#next").click();

});
Pawan
  • 31,545
  • 102
  • 256
  • 434

1 Answers1

2

You can check for originalEvent if it is undefined, then its triggered via trigger:

$(document).on('click', '#next', function (event) {
if(event.originalEvent=== undefined){
   //triggered....not clicked
}
if (current_count < totalcount) {
    current_count++;
    updateDiv();
}
});

Working Demo

Community
  • 1
  • 1
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125