Skip to content

mboughaba/element-matches-polyfill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

element-matches-polyfill

Polyfill for Element.matches

Provides a polyfill for Element.forEach() to all Browsers.

Native support

See MDN for more information.

Reduced scope

I personally use: https://github.com/jelmerdemaat/element-matches as I don't need to support all browsers.

Import

// CommonJS
require('element-matches-polyfill');

// ES6 Modules import / Typescript import
import 'element-matches-polyfill';

Install

npm install --save element-matches-polyfill

Usage

<ul id="birds">
  <li>Orange-winged parrot</li>
  <li class="endangered">Philippine eagle</li>
  <li>Great white pelican</li>
</ul>

<script type="text/javascript">
  var birds = document.getElementsByTagName('li');

  for (var i = 0; i < birds.length; i++) {
    if (birds[i].matches('.endangered')) {
      console.log('The ' + birds[i].textContent + ' is endangered!');
    }
  }
</script>

About

Polyfill for Element.matches

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published