Question User Question User - 4 years ago 100
jQuery Question

how to use append and after using if condition in jquery

How to simplify this code using jquery



if($('#tr_second').length == 0){ var adppend =$('#append_tr').append; } else { var adppend =$('#tr_second').append; }


Answer Source

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) {
  } else {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download