Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js custom event

// create a custom event
const custom_event = new CustomEvent("custom_event_name", {
	// whether or not the event 'bubbles' up the DOM tree
	bubbles: true,
	// special property allowing you to provide additional information
	detail: {
		
	}
});

// to add an event listener
element.addEventListener("custom_event_name", function() {
	// event handler
});

// to trigger an event
element.dispatchEvent(custom_event);
 
PREVIOUS NEXT
Tagged: #js #custom #event
ADD COMMENT
Topic
Name
4+1 =