| title | JavaScript DOM |
|---|---|
| titleTemplate | Snippet Collection | massCode |
| description | Collection of JavaScript DOM snippets |
This snippet checks whether the parent element contains the child.
const elementContains = (parent, child) =>
parent !== child && parent.contains(child)const head = document.querySelector('head')
const body = document.querySelector('body')
elementContains(head, body) // falseThis snippet checks whether an element has a particular class.
const hasClass = (el, className) => el.classList.contains(className)hasClass(document.querySelector('p'), 'some-class') // true