Create an Event
object and pass it to the dispatchEvent
method of the element:
var element = document.getElementById('just_an_example');
var event = new Event('change');
element.dispatchEvent(event);
This will trigger event listeners regardless of whether they were registered by calling the addEventListener
method or by setting the onchange
property of the element.
If you want the event to bubble, you need to pass a second argument to the Event
constructor:
var event = new Event('change', { bubbles: true });
Information about browser compability:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…