jquery - Remove all child elements from table except for first? -


my html:

<table id="user-table">       <tr><td>1</td></tr>       <tr><td>2</td></tr>       <tr><td>3</td></tr>      </table> 

how can remove child elements of user-table except first <tr> using jquery?

what i've tried:

$("#user-table").children().remove(); 

however removes child <tr> elements want first row not removed.

here's jquery far:

$('#add-form').submit(function(e) {     e.preventdefault();     $.post("../lib/ajax/add-user.php", $("#add-form").serialize(),     function(data){      javascript:jquery.fancybox.close();      $("#user-table").children().remove();     //$('#list-box').fadeto(800,1,function(){      //$(this).empty();     //$(this)..append(data);                                  //}); }); 

slice() far the fastest way you're going able this:

$('#user-table tr').slice(1).remove(); 

jsfiddle here.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -