简体   繁体   中英

How do you remove a custom event in javascript?

Here is my code to create a custom event that is working:

var evt = document.createEvent("Event"); //creat custom event
evt.initEvent("fac_sel", true, true); //initialize the event
evt.objIndex = "some test data"; //add custom data
document.dispatchEvent(evt); //fire event!

For some reason the following code results in "undefined"

document.removeEventListener("Event","fac_sel", true);

The addEventListener and removeEventListener methods do not return anything. Hence the call document.removeEventListener("Event", "fac_sel", true) will display as undefined in a debugger or assign undefined to a variable.

Check out the removeEventListener method on MDN for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM