# if-element-exists

> execute a function iff the element exists

Latest version **1.0.1** (published 2019-12-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install if-element-exists
pnpm add if-element-exists
yarn add if-element-exists
bun add if-element-exists
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-12-17 |
| First published | 2019-12-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | blewisio |

## Links

- npm: https://www.npmjs.com/package/if-element-exists
- Repository: https://github.com/blewisio/if-element-exists
- Homepage: https://github.com/blewisio/if-element-exists#readme
- Issues: https://github.com/blewisio/if-element-exists/issues
- npm.io page: https://npm.io/package/if-element-exists

## Recent versions

- 1.0.1 (latest) — 2019-12-17
- 1.0.0 — 2019-12-15

## README

# if-element-exists

Execute a function only if the DOM element exists.

## Install

```sh
npm install if-element-exists
```

## Usage

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

---
_Source: https://npm.io/package/if-element-exists · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
