Jquery Create Css Rule at Runtime

Today I’ve started a project where I use Masonry by Desandro. Having to change some list items dynamically, where the height changes, the method “layout()”, repositions all the items for me. Though, using .style() and setting the height dynamically Masonry won’t really know about the height change and because the height is not predictable and relying in pre-written classes won’t do, I found that we can actually create CSS rules in runtime. Follows a jquery example of it:

var style = { height : '1000px' };
$('#foo').css(style);

Hope this helps!

comments powered by Disqus