2

In a main.js-File I have the following function

function fireCustomEvent(element, event) {
if (document.createEventObject) {
    // dispatch for IE
    var evt = document.createEventObject();
    return element.fireEvent('on' + event, evt);
}
else {
    // dispatch for firefox + others
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent(event, true, true); // event type,bubbling,cancelable
    console.log("dispatch");
    return !element.dispatchEvent(evt);
}

}

On one page, this code works just fine, but at another page, I get the "event.dispatchEvent is not a function" - Error. I've read that "jQuery.noConflict()" would do the Job but since i have no jQuery (or any js-Framework) in my project I wonder, how that can be. I've tried it anyway, but then I only get (logically) the "jQuery is not defined" - Error.

Does anyone have an idea?

Niklas Hantke
  • 353
  • 1
  • 5
  • 20
  • 1
    what is element here? if it works in one page but not another, it's possible that the 2nd page is passing an invalid parameter – Robert Levy Jun 17 '14 at 16:33
  • 1
    `dispatchEvent` has nothing to do with jQuery, so `jQuery.noConflict()` is irrelevant. – Barmar Jun 17 '14 at 16:34
  • Robert: ouch, you're right, I should take a break... but thank you!!! – Niklas Hantke Jun 17 '14 at 16:34
  • @NiklasHantke if you want him to see your comment, you need to use `@handle`. Type `@r` and then use TAB for name completion. – Barmar Jun 17 '14 at 16:36
  • @Barmar: Thank you for the tip but unfortunately the edit-time has expired :( – Niklas Hantke Jun 17 '14 at 16:40
  • @Barmar it's because all the SO questions regarding 'element.dispatchEvent is not a function' have answers stating that it's a result of a conflict between jQuery and some other JS framework like Prototype. I've been searching for ages and can't find any solution except 'jQuery.noConflict()' (which as you've rightly pointed out is completely irrelevant). – Luke Jul 23 '19 at 07:55

0 Answers0