VienDinhCom / with-elements

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

Home Page:https://www.npmjs.com/package/with-elements

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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);
});

About

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

https://www.npmjs.com/package/with-elements

License:MIT License


Languages

Language:TypeScript 100.0%