0

I've a select box and I've attached an event listener like below

$('#select').on('change', function(){
  console.log("Changed")
})

This callback function will triggered if I manually change the select box and through jQuery using trigger method

$('#select').trigger('change');

So my requirement comes here, is there any way to check inside the change event listener whether the event is triggered manually or through .trigger('change') method

what I need exactly is,

$('#select').on('change', function(){
  if(eventtriggeredmanually){
    console.log("Changed");   // need to do some logics if it is triggered manually not through .trigger('change') method
  }
})
Raja Sekar
  • 2,062
  • 16
  • 23

1 Answers1

0

Not any easy fixes.

My recommendation is to make two event handlers:

$('#select').on('changeProg', function(){
  console.log("Changed through code")
  toDo()
})
$('#select').on('change', function(){
  console.log("Changed manually")
  toDo()
})
function toDo(){ ... }

where you then use the first when you want to trigger through code

$('#select').trigger('changeProg');
Mads Buch
  • 344
  • 2
  • 10