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 :: angular component 
Javascript :: sintax arrow function in javascript 
Javascript :: Send Data Using Express With Post 
Javascript :: multilone input react 
Javascript :: strict equality operator 
Javascript :: react without using jsx create element 
Javascript :: set state using object 
Javascript :: react native radio buttons 
Javascript :: js get location params 
Javascript :: form- text area react 
Javascript :: jquery dialog modal on modal 
Javascript :: check variable value and do something 
Javascript :: react footer component 
Javascript :: how to get form value 
Javascript :: Showing a custom toast function for react-toastify - Toast show 
Javascript :: list of dictionaries javascript 
Javascript :: documentelement javascript 
Javascript :: defined variables if null javascript 
Javascript :: recordrtc 
Javascript :: aws lambda send json 
Javascript :: dynamodb count items node 
Javascript :: This function is used to store items in local storage 
Javascript :: clear input value with javascript 
Javascript :: jq break line 
Javascript :: NodeJS Content-Type 
Javascript :: javascript ternary operator syntax 
Javascript :: Uncaught TypeError: $(...).datatables is not a function 
Javascript :: angular set time 
Javascript :: js function run one another 
Javascript :: react children length 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =