0

I have two buttons on a form. Both the buttons and the form are created dynamically:

      container.html(........
                     ........
                     <input type='button' value='Send' id='btSend' />"+
                    "       <input type='button' value='Save' id='btSave' />"+
                     ................
                     ...............)

And here the two functions should collect keystrokes:

       $("#btSend").click(function(){
        ..........
        ............
        }

        $("#btSave").click(function(){
        ..........
        ............
        }

1 Answers1

4

You can use .on() to delegate click event to the dynamically created elements. see below code -

$(document).on("click","#btSend",function(){
        ..........
        ............
        }

 $(document).on("click","#btSave",function(){
        ..........
        ............
 }
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57