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 remove duplicates in js array 
Javascript :: react string to integer 
Javascript :: react aos animation 
Javascript :: javascript indexof 
Javascript :: js how to reverse a string 
Javascript :: to lowercase js 
Javascript :: start date and end date validation antd 
Javascript :: how to read breakline in html 
Javascript :: StatusBar 
Javascript :: how to delete file from firebase storage on web 
Javascript :: first repeated character in a string javascript 
Javascript :: how to get array from number length 
Javascript :: jquery on wheel event 
Javascript :: handlerbar console log 
Javascript :: why is my mongoose middleware not working 
Javascript :: jquery map 
Javascript :: mongodb group by several fields 
Javascript :: js password generator 
Javascript :: fix footer 
Javascript :: jquery dropdown select 
Javascript :: jquery display modal bs4 
Javascript :: nodejs event 
Javascript :: javascript join list of string 
Javascript :: remove id attribute javascript 
Javascript :: js click on button 
Javascript :: difference between let and var in javascript 
Javascript :: js get first element of array 
Javascript :: change root color js 
Javascript :: express js url with id 
Javascript :: javascript convert object to querystring 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =