Skip to content

Instantly share code, notes, and snippets.

@fczbkk
Created April 20, 2020 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fczbkk/9a036f9ecf2cafab8c89c75bbf20ca39 to your computer and use it in GitHub Desktop.
Save fczbkk/9a036f9ecf2cafab8c89c75bbf20ca39 to your computer and use it in GitHub Desktop.
const BrowserEvent = (eventName = '') => {
let event
if (typeof Event === 'function') {
event = new Event(eventName)
} else {
event = document.createEvent('Event')
event.initEvent(eventName, true, true)
}
return event
}
function updateInputValue (element, newValue) {
element.value = newValue
element.dispatchEvent(BrowserEvent('input'))
element.dispatchEvent(BrowserEvent('change'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment