Skip to content

addEvent

Add event listener (cross-browser compatible).

Usage

js
import { addEvent } from 'js-cool'

Signature

typescript
function addEvent(
  element: any,
  type: string,
  handler: Function
): void

Parameters

ParameterTypeDescription
elementanyDOM element
typestringEvent type (no 'on')
handlerFunctionEvent handler

Examples

js
const btn = document.getElementById('btn')
addEvent(btn, 'click', (e) => {
  console.log('Button clicked!')
})

// Multiple events
addEvent(input, 'focus', onFocus)
addEvent(input, 'blur', onBlur)

Released under the MIT License.