Select existing HTML elements and run the callback with each element.
npm install --save with-elements
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);
});
import { withElementsSync } from 'with-elements';
withElementsSync('.article', element => {
const title = element.querySelector('.title')?.innerHTML;
alert(title);
});