I have the following code which works fine on most browsers. Unfortunately MS’s Edge and IE11 report a problem:
Object doesn’t support property or method ‘matches’
Is there a way I can get my function to work on Edge and IE11 or alternatively a way to detect if it’s an MS browser so I can revert to the non-JS fallback?
document
.getElementById('clients')
.addEventListener('click', function(event) {
const target = event.target;
if (!target.matches('[data-show]')) return; //here be the error
hideAllA();
recolorAllA();
document
.querySelector(target.dataset.show)
.style
.display = 'block';
target.style.color = '#D74022';
});
I can post a (non-)working page if necessary but I’d prefer not to unless it’s necessary…
Yeah. I thought I would try your first suggestion (if I understood you correctly) and try matchesSelector() in place of matches() but it fails in Chrome, although webkitMatchesSelector() works, so it looks like a job for the polyfill.
It’s safest just to say it wasn’t like that!!! I’ve been looking at the polyfill page and scratching my head, so many thanks for showing how to use it…