It isn't possible to insert tags, or partial tags, into the DOM. All you can insert into the DOM is DOM nodes, which by definition always follow the proper tree structure.
'<ul></ul>' is a complete tag with begin and end, and $('<ul></ul>') results in a UL element which you can insert into the DOM. '</ul><ul>' is fragments of two different tags. There is no way to represent this as a DOM element, but the browser will do its best to turn it into one - and it will certainly not do what you expect. Do you have any control over the HTML code that you're operating on? It sounds like you may not - otherwise you would do this on the server. To do this on the client, you basically need to rebuild the series of UL/LI elements that you want, and then replace the original UL with that. You could do that either with DOM manipulation or by building up a string of HTML as Kit mentioned. (String manipulation can be much faster than DOM manipulation - but if you have event handlers on the UL or LI items they would be lost.) -Mike > I have a rather long unordered list with about hundred items inside. > each is wrapped in <li>...</li> > I want to split this list into several small lists, with, > say, 10 items each. > to do that I have this code: > > checkvar = 1; > $('#right ul li').each(function(){ > if( checkvar%10 == 0){ > $(this).after('</ul><ul>'); > } > checkvar++; > }); > > basically this works, but somehow jQuery fixes the order of > the inserted '</ul><ul>' to '<ul></ul>'. > interestingly, if I try to put 'zzz aaa', I get 'zzz aaa' as expected. > The moment tag-brackets are used (even with '<zzz> <aaa>' I > will get '<aaa> <zzz>' in the result. > > Any suggestions whats happening here?