Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

custom event handler javascript

const event = new Event('build');

// Listen for the event.
elem.addEventListener('build', (e) => { /* … */ }, false);

// Dispatch the event.
elem.dispatchEvent(event);
Comment

custom event js

const eventDetails = {
  'id': elemId
}
document.dispatchEvent (
  new CustomEvent('myCustomEvent', {'detail': eventDetails})
)
Comment

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);
Comment

Custom Event Example

		 const btn1 = document.getElementById('btn1');

			   btn1.addEventListener('boo', function () {
			          alert('Button1 said Boo');
			   });
			   
			   
  			 const btn2 = document.getElementById('btn2');

  			   btn2.addEventListener('boo', function () {
  			          alert('Button 2 said Boo');
  			   });
			   			  const clickEvent = new Event('boo');
			   btn1.dispatchEvent(clickEvent);

			  btn2.dispatchEvent(clickEvent);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to hide component in react 
Javascript :: vue v-on:click 
Javascript :: angularjs download xml file 
Javascript :: file picker electron 
Javascript :: libraries like html-react-parser 
Javascript :: method to look for objects in arrays by id 
Javascript :: Angular ion-search 
Javascript :: check if js property exists in class 
Javascript :: How to Perform Date Comparison With the Date Object in JavaScript 
Javascript :: capitalise first letter js 
Javascript :: react-phone-number-input retur message in react hook form 
Javascript :: submit a form on enter angular 
Javascript :: TypeError: sequelize.import is not a function 
Javascript :: next js material ui typescript 
Javascript :: nodejs https server 
Javascript :: javascript fill array from 0 to n 
Javascript :: adding numbers in an array javascript 
Javascript :: read json file into object javascript 
Javascript :: change file name in node.js 
Javascript :: sequelize update column type 
Javascript :: next js back to previous page 
Javascript :: react font-awesome 
Javascript :: rror: btoa is not defined 
Javascript :: split url javascript 
Javascript :: javascript check if variable is object 
Javascript :: chrome storage onchanged 
Javascript :: javascript array reorder elements 
Javascript :: angular set content type 
Javascript :: embed example discord.js 
Javascript :: Nodemailer gmail new configuration 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =