Skip to content
Advertisement

Changing the class of divs in a pattern using jQuery

I have a blog layout I’m working on (bootstrap) and I’ve hit a snag.

I need the first two divs to be col-md-3 (NORMAL), then the following 2 divs col-md-6 (WIDE), then it needs to make the next 4 divs as col-md-3 (NORMAL), then the next 2 divs col-md-6(WIDE) and so on, so forth.

I’ve tried [this method in codepen][1], which works (code below) but is obviously not the most efficient way to do it – I’m fairly new to jQuery, so would appreciate any help you can offer!

HTML:

JavaScript

jQuery used:

JavaScript

Advertisement

Answer

You can do it using .not() and .filter()

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement