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

1.0.1 • Public • Published

if-element-exists

Execute a function only if the DOM element exists.

Install

npm install if-element-exists

Usage

import ifElementExists from 'if-element-exists';
 
ifElementExists('.foo', x => x.classList.add('bar'));

API

ifElementExists(elementOrSelector, func)

Calls func if and only if the element is not null. the Returns the result of func.

elementOrSelector

Type: HTMLElement | string

DOM element, or query selector to get an element

func

Type: function

Receives the element as the first argument, if the element is not null. Return value of the function will be returned from ifElementExists.

Readme

Keywords

none

Package Sidebar

Install

npm i if-element-exists

Weekly Downloads

9

Version

1.0.1

License

ISC

Unpacked Size

2.13 kB

Total Files

5

Last publish

Collaborators

  • blewisio