A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/en-US/docs/Web/API/CustomEvent/CustomEvent below:

CustomEvent: CustomEvent() constructor - Web APIs

CustomEvent: CustomEvent() constructor

Baseline Widely available

Note: This feature is available in Web Workers.

The CustomEvent() constructor creates a new CustomEvent object.

Syntax
new CustomEvent(type)
new CustomEvent(type, options)
Parameters
type

A string providing the name of the event. Event names are case-sensitive.

options Optional

An object that, in addition of the properties defined in Event(), can have the following properties:

detail Optional

An event-dependent value associated with the event. This value is then available to the handler using the CustomEvent.detail property. It defaults to null.

Return value

A new CustomEvent object.

Example
// create custom events
const catFound = new CustomEvent("animalfound", {
  detail: {
    name: "cat",
  },
});
const dogFound = new CustomEvent("animalfound", {
  detail: {
    name: "dog",
  },
});

const element = document.createElement("div"); // create a <div> element

// add an appropriate event listener
element.addEventListener("animalfound", (e) => console.log(e.detail.name));

// dispatch the events
element.dispatchEvent(catFound);
element.dispatchEvent(dogFound);

// "cat" and "dog" logged in the console

Additional examples can be found at Creating and dispatching events.

Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4