In terms of performance, @Jaykishan Mehta is one the best, then the for loop comes.
for (var i = 0, spans = document.querySelectorAll('#mydiv span.page'), len = spans.length; i < len; i += 1) { spans[i].style.zIndex = parseInt(spans[i].style.zIndex, 10) + 1; }
Using jQuery is massive, i.e. for each iteration, etc., can slow down globally.
I mean, jQuery can perform individual tasks pretty quickly, but the amount can cause a general slowdown.
It all depends on your application / website.
source share