Maria Jane Maria Jane - 1 year ago 74
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download