javascript - Add class to LI element depending on data-size attributes -


i using gridster wordpress control arrangement of masonry style grid layout. gidster allows site admins reorder / resize posts in realtime (see screenshot)

example of gridster

now rule use number of grid sizes (1x1, 1x2, 2x2). markup grid output following:

1x1: <li data-sizex="1" data-sizey="1" class="gs_w">

1x2: <li data-sizex="1" data-sizey="2" class="gs_w">

2x2: <li data-sizex="2" data-sizey="2" class="gs_w">

you can see grid size determined html 5 data attributes 'data-sizex' , 'data-sizey'. use jquery check these attributes on page load , add classes respectively..

for example element grid size of 1x1 (data-sizex="1" data-sizey="1") have class of '1x1'

i believe need use attribute selector little unsure how proceed.

$("li[data-sizex='1']") 

you can use each parse , data elements make class

$('li').each(function(){     $(this).addclass($(this).data('sizex') + "x" + $(this).data('sizey')); }); 

edit limit add class specific li e.g descendant of particular element mentioned op in comment can extend selector.

$('.gridster li').each(function(){... 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -