Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 246
seaBass Avatar asked Sep 09 '26 22:09

seaBass


1 Answers

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.

like image 170
Rich O'Kelly Avatar answered Sep 12 '26 12:09

Rich O'Kelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!