You cannot think of modifying the DOM as if you were editing the source HTML file. After the browser has parsed the HTML file, it still does not exist. The only thing that matters is the representation of the DOM.
With that in mind, let's look at the bit of code that you posted ...
.after('</ul><ul>')
You imagine editing this existing HTML and adding a closing tag and an opening tag. This is not true. It creates a piece of the document from this code, and then adds it as a sibling in the original selection. Since </ul> not a valid beginning of an HTML string, it is discarded. All you have left is a <ul> , which is parsed as an entire element (imagine an HTML document that passed <div><ul></div> and you get this idea). Thus, the empty ul element is inserted into the list as a child of the element you selected: it is presented as <ul></ul> , since this is a way to serialize the ul element in HTML.
To do what you want to do, you need to use a different approach that recognizes what the DOM is.
$('.container ul').each(function(){ var total = $(this).children().length; var half = Math.ceil(total / 2) - 1; $(this).children(':gt('+half+')').detach().wrapAll('<ul></ul>').parent().insertAfter(this); });
This says: "Get the children after half ( :gt ), detach them from the current ul , wrap them in the new ul , select ul with parent and insert after the current ul ( this )."
JsFiddle work
source share