parent() vs parentNode simple

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

<div id="outer" class="myClass" data-id="23">
<div>
<span class="c-tab" onclick="switchWhpTab(this)"><span class="c-tab-a">All</span><span class="c-tab-x" onclick="$('#chattabs').html('');"></span></span>
<span class="c-tab" onclick="switchWhpTab(this)" data-id="1"><span class="c-tab-n">Hi</span><span class="c-tab-x" onclick="closeWhpTab(event,this)"></span></span>
<span class="c-tab" onclick="switchWhpTab(this)" data-id="2"><span class="c-tab-n">Hit</span><span class="c-tab-x" onclick="closeWhpTab(event,this)"></span></span>
<span class="c-tab" onclick="switchWhpTab(this)" data-id="3"><span class="c-tab-n">Hite</span><span class="c-tab-x" onclick="closeWhpTab(event,this)"></span></span>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

Preparation code output

All Hi Hit Hite

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
parent()
$(function() {
$('.c-tab-n').each(function(){
alert($(this).parent().attr('data-id'));    
});
});
pending…
parentNode
$(function() {
$('.c-tab-n').each(function(){
alert(this.parentNode.getAttribute("data-id"));    
});
});
pending…
better parent()
$(function() {
$('.c-tab-n').each(function(){
alert($(this.parentNode).attr('data-id'));    
});
});
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment