Find position of multiple elements in a list (jQuery) -



Find position of multiple elements in a list (jQuery) -

i have list of several images, portrait class, , others landscape class:

<img src="/images/fullsize/007.jpg" class="portrait"> <img src="/images/fullsize/008.jpg" class="landscape"> <img src="/images/fullsize/047.jpg" class="landscape"> <img src="/images/fullsize/048.jpg" class="landscape"> <img src="/images/fullsize/049.jpg" class="landscape"> <img src="/images/fullsize/050.jpg" class="portrait"> <img src="/images/fullsize/051.jpg" class="portrait"> <img src="/images/fullsize/052.jpg" class="landscape"> <img src="/images/fullsize/053.jpg" class="landscape"> <img src="/images/fullsize/054.jpg" class="landscape">

how identify position (within list) of .portrait images , store in variable array? (i.e. illustration need output '1, 6, 7' or '0, 5, 6'.). looked using .index() appears homecoming single result.

take on example:

$(function() { var p_ind =[], l_ind=[]; $('img').each(function(i, data) { if( $(data).hasclass('portrait') ) p_ind.push(i); else l_ind.push(i); }); // portrait console.log(p_ind); // landscape console.log(l_ind); });

demo

jquery

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -