I would not worry about this if you did not repeat hundreds of them.
Cycle
for usually used with a regular DOM (aka without jQuery), for example ...
var elements = document.getElementById('something').getElementsByTagName('a'); var elementsLength = elements.length; for (var i = 0; i < elementsLength; i++) { elements[i].style.color = 'red'; }
Caching elementsLength is a good idea, so it doesn't count on every iteration. Thanks to the CMS for this suggestion in the comments.
Just adapt this for your jQuery object if you want to do this with jQuery.
Replace the elements variable with your jQuery collection, for example $('#something a') . I think you may need to reinstall the object if you need to do something else with jQuery.
source share