Search code examples
jqueryappendto

jQuery appendTo all elements except last one


I am trying to append all elements of the same class "td.top" except last one to another place, but I can't figure out how is this possible.. Any ideas are welcomed, I am kind of stuck.. Thank you for any input. This is the code I have now:

$(document).ready(function() {
if ( $(window).width() < 960) {

$("td.top").appendTo("ul.sub");

} else {

//something else

}
});

Solution

  • How about:

    $("td.top").not(":last").appendTo("ul.sub");