shared
utils
string
object
is
extension
js
tracking
string
dom
when
selection
position
iframe
event
scroll
console
node
string
project
fs
console
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
- $from*-HTMLElement
The element from which to start the search
- $elements*-NodeListOf<HTMLElement>|HTMLElement[]
The elements list to search in
- settings{}TNearestElementSettings
Some settings to configure your search
Return
- -HTMLElement
The nearest element found
Example
import { nearestElement } from '@blackbyte/sugar/dom'
nearestElement($elm, document.querySelectorAll('.my-cool-elements'), {
direction: 'top'
});Settings
- [direction]*-‘top’ | ‘right’ | ‘bottom’ | ‘left’
The direction to search in. Can be “top”, “right”, “bottom”, “left”
Todo
- testsnormal
Author
- Olivier Bosselolivier.bossel@gmail.comhttps://olivier.bossel@gmail.com