Difference between $.each and .each

In jQuery there are 2 versions of each() method1. .each()2. $.each() or jQuery.each()

Please note : $ is shortcut for jQuery.

What is the difference.each is used to iterate over the items in a jQuery collection

Example : In this example, the jQuery selector $('li') returns a jQuery object collection. So to loop thru the objects in the jQuery collection we are using .each() method. Notice this method is called on the jQuery object collection, that the selector returns, so the .each() method knows the items it has to iterate over.

The callback method has 2 parameters1) index - The index of the element 2) element - The DOM element that we are currently iterating over

Since the element is a raw DOM object, to use use jQuery methods you have to wrap it using the jQuery wrapper $ as shown below.$(element)

Instead of using element parameter, you can also use this keyword, which also refers to the raw DOM element that we are currently iterating over. To use jQuery methods you have to wrap it using the jQuery wrapper $ as shown below.$(this)