Maria Jane Maria Jane - 6 months ago 22
Javascript Question

$.each doesn't work with jquery selector?

I have DOM like this

<div data-id="1" class="box_album_item"></div>
<div data-id="2" class="box_album_item"></div>
<div data-id="3" class="box_album_item"></div>

and I uses $.each


but I got error of

Uncaught TypeError: Cannot use 'in' operator to search for 'length' in .box_album_item


You need to use it as a jQuery collection's function:

$('.box_album_item').each(function(i, val) {

Always please make sure you read the documentation and examples before asking.