1. dom-closest
For a given DOM element, find the first ancestor that matches a given CSS selector.
dom-closest
Package: dom-closest
Created by: necolas
Last modified: Wed, 15 Jun 2022 21:05:57 GMT
Version: 0.2.0
License: MIT
Downloads: 415,114
Repository: https://github.com/necolas/dom-closest

Install

npm install dom-closest
yarn add dom-closest

dom-closest

Build Status

For a given DOM element, find the first ancestor that matches a given CSS
selector.

Installation

npm install dom-closest

API

closest(elem, selector[, context])

  • element (Element): a starting DOM Element.
  • selector (String): the CSS selector of the ancestor to find.
  • context (Element): a DOM node to use as search context (optional).
 var closest = require('dom-closest');

var photo = document.querySelector('.photo');
var timeline = document.querySelector('.timeline');

closest(photo, '.tweet');
// => Element

closest(photo, '.tweet', timeline);
// => Element

Browser support

  • Google Chrome
  • Firefox 4+
  • Internet Explorer 8+
  • Safari 5+
  • Opera

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin