JSFiddle - React, Tailwind, and code Playground

HTML

<img src="http://placehold.it/150x50"><img src="http://placehold.it/150x50"><img src="http://placehold.it/150x50"><img src="http://placehold.it/150x50"><img src="http://placehold.it/150x50"><img src="http://placehold.it/150x50"><img src="http://placehold.it/150x50"><img src="http://placehold.it/150x50"><img src="http://placehold.it/150x50"><img src="http://placehold.it/150x50"><img src="http://placehold.it/150x50">

<ul></ul>

JavaScript

var ps = $('img');
    var offset = 4;
    for (var i = 0; i < ps.size(); i += offset) {
        var container = $('<li></li>');
        var content = ps.slice(i, i + offset);
        content.replaceWith(container);
         container.html(content).appendTo('ul');
    }