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 :: Random Integer 1-10 
Javascript :: offsetheight javascript 
Javascript :: javascript toisostring without milliseconds 
Javascript :: csv to json python 
Javascript :: if we run 9119 through the function, 811181 will come out, because 92 is 81 and 12 is 1. 
Javascript :: javascript check if object 
Javascript :: change datetime format in js 
Javascript :: laravel link custom javascript file 
Javascript :: javascript hours minutes seconds 
Javascript :: bootstrap programmatically change tab 
Javascript :: Use Destructuring Assignment with the Rest Operator to Reassign Array Elements 
Javascript :: how to clear state in react hooks 
Javascript :: react js date ago 
Javascript :: js test if array 
Javascript :: js list of objects 
Javascript :: material ui outlined input with icon 
Javascript :: create app with a specific react version 
Javascript :: string concatenation in js 
Javascript :: duplicate numbers in an array javascript 
Javascript :: get window width 
Javascript :: nodejs dotenv path how to set 
Javascript :: string to json js 
Javascript :: number is prime or not in javascript 
Javascript :: i18n vue cli 
Javascript :: javascript object array contains 
Javascript :: javascript convert array to object 
Javascript :: javascript keyup event enter key 
Javascript :: nodejs redis setex 
Javascript :: preloader 
Javascript :: javascript onclick button 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =