JQuery Toggle Class Test

Benchmark created by Kalina on


Description

Prove that both methods has similar performance

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<div class="a classForToggle">
<div id="id">
<div class="doesntmatter2">Hoho</div>
<p>Hoho</p>
</div>

<div>

Test runner

Ready to run.

Testing in
TestOps/sec
toggleClass
$(".a").toggleClass("classForToggle");
ready
manually toggle

($(".a").hasClass("classForToggle") ?
    $(".a").removeClass("classForToggle") :
    $(".a").addClass("classForToggle"));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.