Rodrigo Dias Rodrigo Dias - 2 months ago 16
HTML Question

How can I carry li 's a ul and put in another ul with jQuery

I have a problem that boils down to transport the li's of a 'UL' to another 'UL' order to plug the holes of a removal of the previous read. Here is an example of the problem: JSFIDDLE

var listaPrateleiras = $(".prateleira.n3colunas > ul > li");
if ($(listaPrateleiras).has(".flag").length) {
$(listaPrateleiras).not(':has(".flag")').remove();
}


enter image description here
enter image description here

Answer

NOTE that i added two class upperul and lowerul to ul element and here is working example https://jsfiddle.net/wnv3moLr/1/

var listaPrateleiras = $(".prateleira.n3colunas > ul > li");
if ($(listaPrateleiras).has(".flag").length) {
    $(listaPrateleiras).not(':has(".flag")').remove();

  $(".upperul").append($(".lowerul").html()); //Copy all html left from lowerul to upperul

  $(".lowerul").html(""); //Now remove all html inside lowerul
}