question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

el.closest not supported in IE11

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What’s the current behavior?

el.closest is called from Content.isInEditor (among a number of places). It seems like this method is not supported in IE11, and it throws an error.

What’s the expected behavior?

The error should not occur. One possible solution (based on mdn web docs) is just to polyfill the method.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Opty1712commented, Apr 24, 2020

Two polyfills for IE11, that made Slate working in IE 11

/**
 * closest
 */
(function () {
  if (!Element.prototype.closest) {
    Element.prototype.closest = function (css) {
      var node = this;

      while (node) {
        if (node.matches(css)) return node;
        else node = node.parentElement;
      }

      return null;
    };
  }
})();

/**
 * matches
 */
(function () {
  if (!Element.prototype.matches) {
    Element.prototype.matches =
      Element.prototype.matchesSelector ||
      Element.prototype.webkitMatchesSelector ||
      Element.prototype.mozMatchesSelector ||
      Element.prototype.msMatchesSelector;
  }
})();
1reaction
ianstormtaylorcommented, Jul 3, 2018

Feel free to submit a pull request mentioning that older browsers will need to use polyfills for things like el.closest.

I realize that IE is the latest Internet Explorer, but seeing as it’s superseded by Edge, and doesn’t have tons of the functionality that is considered baseline these days, it’s not something that we’re going to support without polyfills. Otherwise every single library starts re-bundling the same polyfills over and over and everyone else suffers from bloat.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to support .closest in IE11 - javascript - Stack Overflow
I'm thinking of just replacing . closest with one IE11 supports. The . closest() method of the DOM traversal has nothing to do...
Read more >
Element.closest() - Web APIs - MDN Web Docs
The closest() method of the Element interface traverses the element and its parents (heading toward the document root) until it finds a node ......
Read more >
Quote reply not working in IE 11 - bug - Discourse Meta
When using IE 11 highlighting text does not reveal the “quote” pop up. It works fine in chrome and I confirmed myself that...
Read more >
Practical Use Cases for JavaScript's closest() Method
Element.closest() allows us to traverse up the DOM until we get an element that matches the given selector. The awesomeness is that we...
Read more >
Browser Support - jQuery
Unsupported Browsers. While jQuery might run without major issues in older browser versions, we do not actively test jQuery in them and generally...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found