0

When i click button, i want to add new note to my db.So when i click add_note button, a textbox and save button appears. When i click save button nothing change. I check the web concole but there is no error . What should i do ?

jquery

$("#add_note").each(function() {
    $(this).on("click", function() {
        $("#not").html('<input type="text" id="note" />');
        $("#buton").html('<button  class="btn btn-primary btn-sm " id="save">Save</button>');

    });
});


$("#save").each(function() {
    $(this).on("click", function() {
        alert("dsfasdfasdfasd");
    });
});

html

<td id="not"></td>
<td id="buton">
    <button class="btn btn-primary btn-sm " id="add_note"> Add New Note</button>
</td>
Tushar
  • 85,780
  • 21
  • 159
  • 179
Aysu Vural
  • 73
  • 8

1 Answers1

1

Id be unique in HTML. Use event delegation for dynamically added elemnets in the DOM

 $("#buton").on('click', '#save', function(){
   alert("dsfasdfasdfasd");
 });
Sudharsan S
  • 15,336
  • 3
  • 31
  • 49