handling events in webcomponents with handleEvent

last updated: Oct 01, 2024

https://gomakethings.com/the-handleevent-method-is-the-absolute-best-way-to-handle-events-in-web-components/

basically, this:

customElements.define('awesome-sauce', class extends HTMLElement {

	// Instantiate the component
	constructor () {
		super();
	}

	// Handle events
	handleEvent (event) {
		// ...
	}

	// Listen for events
	connectedCallback () {
		this.addEventListener('click', this);
		this.addEventListener('input', this);
		this.addEventListener('close', this);
	}

});
↑ up