Answers for "custom event js"

3

trigger event javascript

// Simple trigger event
document.querySelector(theElem).dispatchEvent(new Event('mouseover'))
Posted by: Guest on July-03-2020
9

javascript custom events with data

//Listen for the event
window.addEventListener("MyEventType", function(evt) {
    alert(evt.detail);
}, false);

//Dispatch an event
var evt = new CustomEvent("MyEventType", {detail: "Any Object Here"});
window.dispatchEvent(evt);
Posted by: Guest on May-05-2020
2

custom event js

const eventDetails = {
  'id': elemId
}
document.dispatchEvent (
  new CustomEvent('myCustomEvent', {'detail': eventDetails})
)
Posted by: Guest on July-08-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language