0

so, using pure Javascript and DOM:

const select = document.querySelector('#my-select')

select.addEventListener('change', function(){
  console.log('changed', this.value)
})

select.value = 'some value from an existing option'
// this changes the select correctly, but it doesn't trigger the event

Is there any way to correctly do this, without jQuery?

André Alçada Padez
  • 10,987
  • 24
  • 67
  • 120

1 Answers1

0

You can force triggering the change event this way:

select.dispatchEvent(new Event('change'));
GrafiCode
  • 3,307
  • 3
  • 26
  • 31