Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
closest() vs parent().parent() + hasClass()
Checking if double parent() + hasClass() validation is really faster than just going for closest().
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0
Browser:
Firefox 142
Operating system:
Windows
Device Platform:
Desktop
Date tested:
8 months ago
Test name
Executions per second
closest
9195675.0 Ops/sec
parents + hasClass
2711164.5 Ops/sec
HTML Preparation code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="tuttifrutti" > <div class="gasodas"> <div class="banga"> <div class="dayum"> <div class="dada"> <div id="phew" class="potat">boop</div> </div> </div> </div> </div> </div>
Script Preparation code:
var yes = $('phew');
Tests:
closest
yes.closest('.my-fancy-class');
parents + hasClass
yes.parent().parent().hasClass('my-fancy-class');