In vanilla JS, if you want to manipulate a collection of elements, you have to get all the elements and then iterate over the collection:

const paragraphs = [...document.querySelectorAll('p')];

paragraphs.forEach(function(paragraph) {

So, you might reasonably assume that you need to do something similar in jQuery, using the .each() method:

const $paragraphs = $('p');

$paragraphs.each(function(index, paragraph) {

But this is actually superfluous!

Instead, you should rely on implicit iteration:

const $paragraphs = $('p');


This is something jQuery does internally. Most methods that return a jQuery collection also iterate over the collection, meaning you don't have to.

For more information, check out Iterating over jQuery and non-jQuery Objects in the jQuery Learning Center.