0

I have a button:

<td class="rigaconto">
  <a class="btn btn-default separa_conto" data-conto="2" data-toggle="tooltip" data-original-title="NewAccount"><i class="fa fa-sitemap"></i></a>
</td>

and jQuery code:

$(function(){
  $(".separa_conto").click(function() {
    var conto = $(this).data('conto');
    var nuovoConto = conto + 1;
    alert(conto);
    $('#showAddeb_conto_'+ conto).removeClass('hidden').show('slow');
    $('#showAddeb_conto_'+ conto).append('<tr><td></td><td>Sogg</td><td>1000</td><td></td></tr>');
    $('.rigaconto').append('<a class="btn btn-default separa_conto" data-conto="'+ nuovoConto +'" data-toggle="tooltip" data-original-title="Separa conto"><i class="fa fa-sitemap"></i></a>');

    var table = $('<table></table>').attr('id','showAddeb_conto_'+ nuovoConto).addClass('table table-hover table-bordered hidden');
    var row = $('<tr><th></th><th>Further account</th><th></th><th></th></tr>');
    table.append(row);

    $('#tabelle_conti').append(table);

  });
});

but if I click twice class "NewAccount" doesn't appear second table. What is my mistake?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Daniele
  • 11
  • 2

1 Answers1

0

It looks like you are trying to click a button that was added after event binding. You can instead attach the event to a parent element (like <body>), but only fire when triggered by buttons with the special class. Then buttons added later will also trigger the event. Change your binding like so:

$("body").on("click", ".separa_conto",function() 
    {
        ...

    })
Malk
  • 11,855
  • 4
  • 33
  • 32