Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function keepElement(selector, fatherSelector, elementToAdd) {
- setInterval(() => {
- const element = document.querySelector(selector);
- if (!element) {
- const father = document.querySelector(fatherSelector);
- if (!father) return;
- father.insertBefore(elementToAdd, father.firstChild);
- }
- }, 100)
- }
- function htmlToNode(html) {
- const template = document.createElement('template');
- template.innerHTML = html;
- const nNodes = template.content.childNodes.length;
- if (nNodes !== 1) {
- throw new Error(
- `html parameter must represent a single node; got ${nNodes}. ` +
- 'Note that leading or trailing spaces around an element in your ' +
- 'HTML, like " <img/> ", get parsed as text nodes neighbouring ' +
- 'the element; call .trim() on your input to avoid this.'
- );
- }
- return template.content.firstChild;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement