with-elements
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

With Elements

Select existing HTML elements and run the callback with each element.

Installation

npm install --save with-elements

Usage

Asynchronous

import { withElements } from 'with-elements';

await withElements('.article', async element => {
  const title = element.querySelector('.title')?.innerHTML;

  const article = await fetch('/edit', {
    body: JSON.stringify([{ search: title }, { title: 'New Title' }]),
  }).then(res => res.json());

  console.log(article);
});

Synchronous

import { withElementsSync } from 'with-elements';

withElementsSync('.article', element => {
  const title = element.querySelector('.title')?.innerHTML;

  alert(title);
});

Readme

Keywords

none

Package Sidebar

Install

npm i with-elements

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

197 kB

Total Files

12

Last publish

Collaborators

  • viendinh