Skip to content

EZ Web Audio / preventEventDefaults

Function: preventEventDefaults()

preventEventDefaults(key): () => void

Defined in: packages/core/src/index.ts:1426

Prevent default behavior for common interaction events on an element.

Useful for piano keys or other interactive audio controls where you want to prevent text selection, context menus, and drag-and-drop behaviors.

Parameters

key

HTMLElement

HTML element to attach event prevention to

Returns

(): void

Returns

void

Remarks

This is a plain DOM convenience — a thin addEventListener/removeEventListener wrapper around an HTMLElement — not a framework hook, despite living in the root package namespace alongside factory functions (R1#7). Safe to call from vanilla JS, React, Vue, or any other framework. May move under a /dom subpath at a future major version for clarity; kept in the root namespace for now (churn not worth it pre-1.0).

Example

typescript
import { preventEventDefaults } from 'ez-web-audio'

const pianoKey = document.getElementById('key-c4')
preventEventDefaults(pianoKey)