Test name | Executions per second |
---|---|
parentElement | 582327616.0 Ops/sec |
closest tag | 7855647.5 Ops/sec |
closest class | 7588724.0 Ops/sec |
closest tag class | 7421380.5 Ops/sec |
parentNode | 688549376.0 Ops/sec |
<span class="span">
<div>
<div id='it'>
</div>
</div>
</span>
var it = document.getElementById("it");
while (it !== null && it.className.indexOf("span") === -1) {
it = it.parentElement;
}
it.closest('span')
it.closest('.span')
it.closest('span.span')
while (it.className.indexOf("span") === -1) {
it = it.parentNode;
if(it === document) {
it = null
break
}
}