jonathantneal / closest

Return the closest element matching a selector up the DOM tree

Home Page:http://caniuse.com/#feat=element-closest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

3.0.0+ not working in IE 11

joebochill opened this issue · comments

Version 3.0.0+ is not working with IE 11.

Object doesn't support property or method 'closest'

I'm using it as follows:

_action(evt) {
  if (!condition) { return; }
  else if (!evt.target.closest('.class')) {
    this._doSomething();
  }
}

logging evt.target.closest is undefined.

The error log also spits out:
Object doesn't support property or method 'repeat', which is not coming from my code.

If I drop back down to version 2.0.2, everything works fine.

Same issue here - 2.0.2 is working fine

commented

There is a breaking change between versions
For Node usage, run closest with your window object:
const elementClosest = require('element-closest');
elementClosest(window); // this is used to reference window.Element

const elementClosest = require('element-closest');
elementClosest(window); // this is used to reference window.Element

While confusing, this actually does the job. I think the docu and description are quite confusing and one might think import 'element-closest' would do the trick. Sadly this isn't the case.

You need to initialize the plugin using elementClosest(window); in a node context (eg. webpack, gulp etc.)

It does work in browser/IE11 context, but for me it meant importing import 'element-closest/browser'.

@wouterkroes would be great to have it in README.

Yeah I agree! But I am not a owner/contributor of this repo. Maybe @jonathantneal could add it himself?

Ups totally forgot to open the PR 🤦‍♂😅
Here we go :D #30