DOM / pure JavaScript solution to jQuery.closest() implementation?

后端 未结 8 1880
感动是毒
感动是毒 2020-12-06 00:26

Here\'s the markup i\'m trying to query. So given the markup:

8条回答
  •  没有蜡笔的小新
    2020-12-06 01:04

    To add an updated answer, there is now Element.closest() available.

    https://developer.mozilla.org/en-US/docs/Web/API/Element/closest

    This isn't supported on IE, but that mozilla doc page includes code for a polyfill for IE8 and IE9+.

提交回复
热议问题