Fix dispatchEvent for IE9/10/11
dispatchEvent doesn't work if element is not in the dom This is not the silverbullet since an element can have a parent that is not in the dom too, but to avoid dom update all the time, it should be enough for very particular use cases (eg in my case unit test). Maybe this should be moved into the test directly to be sure there is a parent, we will see that later.
This commit is contained in:
@@ -10,7 +10,17 @@ module.exports = function(els, events) {
|
||||
event.eventName = e
|
||||
|
||||
forEachEls(els, function(el) {
|
||||
var domFix = false
|
||||
if (!el.parentNode) {
|
||||
// THANKS YOU IE (9/10//11 concerned)
|
||||
// dispatchEvent doesn't work if element is not in the dom
|
||||
domFix = true
|
||||
document.body.appendChild(el)
|
||||
}
|
||||
el.dispatchEvent(event)
|
||||
if (domFix) {
|
||||
el.parentNode.removeChild(el)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user