Pure JS vs jQuery
document.getElementByClassName vs the jQuery selector. Here are the results for Chrome 25:
$('.class') - 4355 operations per second
getElementsByClassName('class') - 94636 operations per second
Pure JS implementation
I've left the jQuery
click event in as it looks like you already have a dependency on jQuery so no point changing the way you're hooking up your events.
var items = document.getElementsByClassName('class');
for (var i = 0; i < items.length; i++)
Also note that I used
getElementsByClassName. It is pretty important to choose the ideal selector if you care about performance. Since we care about all elements with a certain class we can immediately dismiss the others like
querySelectorAll and opt for the function that was built for finding elements of a particular class.
This would be my implementation using jQuery, notice that I didn't bother getting the jQuery object for