How to simplify this code using jquery
FIddle
$('#tableclick').click(function(){
if($('#tr_second').length == 0){ var adppend =$('#append_tr').append; } else { var adppend =$('#tr_second').append; }
adppend('<tr><td>test1</td><td>test2</td><td>test3</td></tr>');
});
This way you can use your condition. Here's a jsFiddle
$('#tableclick').click(function() {
var html = '<tr><td>test1</td><td>test2</td><td>test3</td></tr>';
if (!$('#tr_second').length) {
$('#append_tr').append(html);
} else {
$(html).insertAfter($('#tr_second'));
}
});