nearestElement

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

Get the nearest element from the passed one from the passed elements list. You can pass a direction like “top”, “right”, “bottom”, “left” to specify the direction you want to search the nearest element.

Params

  1. $from*-HTMLElement

    The element from which to start the search

  2. $elements*-NodeListOf<HTMLElement>|HTMLElement[]

    The elements list to search in

  3. settings{}TNearestElementSettings

    Some settings to configure your search

Return

  1. -HTMLElement

    The nearest element found

Example

import { nearestElement } from '@blackbyte/sugar/dom'
nearestElement($elm, document.querySelectorAll('.my-cool-elements'), {
  direction: 'top'
});

Settings

  1. [direction]*-‘top’ | ‘right’ | ‘bottom’ | ‘left’

    The direction to search in. Can be “top”, “right”, “bottom”, “left”

Todo

  • testsnormal