Add 4 new browser snippets
triggerEvent - trigger an event on an element, insertAfter & insertBefore - parse and insert HTML after or before an element respectively, elementContains - checks if an element contains another element
This commit is contained in:
13
snippets/insertBefore.md
Normal file
13
snippets/insertBefore.md
Normal file
@ -0,0 +1,13 @@
|
||||
### insertBefore
|
||||
|
||||
Inserts an HTML string before the start of the specified element.
|
||||
|
||||
Use `el.insertAdjacentHTML()` with a position of `'beforebegin'` to parse `htmlString` and insert it before the start of `el`.
|
||||
|
||||
```js
|
||||
const insertBefore = (el, htmlString) => el.insertAdjacentHTML('beforebegin', htmlString);
|
||||
```
|
||||
|
||||
```js
|
||||
insertBefore(document.getElementById('myId'),'<p>before</p>'); // <p>before</p> <div id="myId">...</div>
|
||||
```
|
||||
Reference in New Issue
Block a user