Test name | Executions per second |
---|---|
Array.prototype.forEach | 269440.0 Ops/sec |
querySelectorAll | 214985.6 Ops/sec |
<ul><li class="nolink"><a href="#" rel="next">A link with class .nolink</a></li><li class="nolink"><a href="#" rel="next">Another link with class .nolink</a></li><li><a href="#" rel="next">A link with no classes</a></li></ul>
const noLinks = document.getElementsByClassName('nolink');
Array.prototype.forEach.call(noLinks, function(noLink) {
const matches = noLink.getElementsByTagName('a')[0];
matches.setAttribute('role', 'link');
matches.setAttribute('aria-disabled', 'true');
matches.removeAttribute('href');
matches.removeAttribute('rel');
});
document
.querySelectorAll('.nolink a')
.forEach(noLink => {
noLink.setAttribute('role', 'link');
noLink.setAttribute('aria-disabled', 'true');
noLink.removeAttribute('href');
noLink.removeAttribute('rel');
});