Adding a class to all images with a parent of a tag

JavaScript performance comparison

Test case created by James C

Preparation code

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

    

Preparation code output

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Vanilla JS - using for loop to search through images with 'a' parent
var images = document.getElementsByTagName('img');
    var imagesArray = [];
    for (var i=0; i<images.length; i++) {                               
        var elements = images[i];
        if (elements.parentNode="a") {
                elements.parentNode.className += " hide-link";
            }          
        imagesArray.push(elements);
    };
pending…
jQuery - using has class method and adding class
$('img').has('a').addClass('hide-link');
pending…

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

0 Comments