querySelectorUp

Type:Function
Status:stable
Since:1.0.0
Platform:js
@blackbyte.sugar.js.dom.query

Go up the dom three to find the first element that matches the passed selector

Params

  1. $from*-HTMLElement

    The element to start from

  2. selector*-String|Function

    A css selector to search for or a check function that will be used

Return

  1. -HTMLElement

    The element found or null

Example

import { querySelectorUp } from '@blackbyte/sugar/dom'
const closestElm =  querySelectorUp($elm, '.my-cool-class');
if (closestElm) {
  // we have found en element that matches the selector
}
// the selector param can be a function that need to return either true or false like so:
querySelectorUp($elm, (elm) => {
  return elm.hasAttribute('my-cool-attribute')
})

Todo

  • testsnormal