element-on
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

element-on

Detect when element got some event

Install

$ npm install element-on

or if you use yarn

$ yarn add element-on

Usage

const elementOn = require('element-on')


(async () => {
	const { element, event } = await elementOn('#pandaDescription', 'DOMContentLoaded')

	console.log(element.textContent)
  // => Giant pandas have a distinctive black and white coat, ...

  console.log(event.type)
  // => DOMContentLoaded
})()

API

elementOn(target, eventName)

Returns a promise for a matching element with targeted event.

elementOn.elementOnLoad(target)

Wrapper function of elementOn that pass "load" event as "eventName".

const { elementOnLoad } = require('element-on')


(async () => {
	await elementOnLoad(window)

	// Do some stuff
})()

elementOn.elementOnDOMContentLoaded(target)

Wrapper function of elementOn that pass "DOMContentLoaded" event as "eventName".

target

Type: string | Element | Window

CSS selector.

eventName

Type: string

Event reference

element

Type: Element

The element that's expected to contain a match.

event

Type: Event

The event that was got.

License

MIT © Vladimir Skvortsov

Package Sidebar

Install

npm i element-on

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

50.7 kB

Total Files

8

Last publish

Collaborators

  • northernwhale