8000 GitHub - blewisio/if-element-exists: execute a function iff the element exists · GitHub
[go: up one dir, main page]

Skip to content

About

execute a function iff the element exists

Resources

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

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. 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.

About

execute a function iff the element exists

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0