Adding css styles to dynamically generated items (jquery , css)

I have a problem with styling dynamically generated items. here is the example of grid items.

i need to add different classes (styles) to grid rows, in specific sequence. first row is grey, next two rows are blue, next two grey again and so on. i have no idea how to do that. maybe there are some jquery selectors?


Try some thing like

var classes = ['grey', 'blue', 'blue', 'green', 'red'];

var els = $('<div />').text(4).appendTo('#x');

$(els).addClass(function(index, cl){
    return classes[ $(this).index() % classes.length ]

Demo: Fiddle

Need Your Help

Changing background colour with jQuery. Reset to default

jquery css jquery-ui sortable jquery-ui-sortable

I have a &lt;ul&gt;, in which I am using jQuery UI Sortable to allow the sorting of the contained &lt;li&gt;s.

One-off rendering of an angular template string

angularjs client-side-templating

I am writing a directive to integrate SlickGrid with my angular app. I want to be able to configure SlickGrid columns with an angular template (instead of a formatter function). To achieve this, I ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.