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:
14
snippets/elementContains.md
Normal file
14
snippets/elementContains.md
Normal file
@ -0,0 +1,14 @@
|
||||
### elementContains
|
||||
|
||||
Returns `true` if the `parent` element contains the `child` element, `false` otherwise.
|
||||
|
||||
Check that `parent` is not the same element as `child`, use `parent.contains(child)` to check if the `parent` element contains the `child` element.
|
||||
|
||||
```js
|
||||
const elementContains = (parent, child) => parent !== child && parent.contains(child);
|
||||
```
|
||||
|
||||
```js
|
||||
elementContains(document.querySelector('head'), document.querySelector('title')); // true
|
||||
elementContains(document.querySelector('body'), document.querySelector('body')); // false
|
||||
```
|
||||
Reference in New Issue
Block a user