JavaScript get parent element and write holder div for siblings

前端 未结 3 1772
小蘑菇
小蘑菇 2020-12-16 13:08

I have the following structure:

Content here
Content here&l
3条回答
  •  失恋的感觉
    2020-12-16 13:48

    i wrote a litte-snipped to travel through DOM to find the first matching parentNode.

    Hope this helps someone, sometime.

    (/¯◡ ‿ ◡)⊃━☆゚. * ・ 。゚,

    function getFirstParentMatch(element, selector) {
      if (!element) {return element};
      element.matches(selector) || (element = (element.nodeName.toLowerCase() === 'html' ? false : getFirstParent(element.parentNode, selector)));
      return element;    
    }
    

提交回复
热议问题