0

I programmed a jquery function which creates dynamically a button with an id ("#btn_sendStudentAnswer"):

$("#btn_getAnswers").one("click",function(){

  $.ajax({type :"POST",
          url: "DBCOMANSWERS.php",
          dataType:"json",
          data:{input:$("#input").val()},
          success: function(result){ //Performs an async AJAX request
              if(result){
                  result.forEach(function(i,v){
                      $("#output").append("<br><input type='checkbox' id='" + i[1]+ "'>" + i[0] + "</input>"); //create checkboxes representative for the 3 answers
                  })
                  $("#output").append("<br><button id='btn_sendStudentAnswer'>" + "Prüfen" + "</button>"); //create button to check if students answer is correct.
              }
          }
  });
});

So far thats working fine. What I want is, to do some action when the created button(#btn_sendStudentAnswer) gets clicked. I programmed the click-event as followed:

$("#btn_sendStudentAnswer").click(function(){
      debugger;
     $.ajax({type:"POST",
             url: "DBCOMCHECKANSWERS.php",
             dataType:"json",
             success: function(result){

             //if answer were right/wrong mark them

             }
     });
});

But it never reaches the debugger;. The "Web-Developer-Tool" of Chrome doesn't show any error or something unusual. Is there a programming mistake I made or is another way of reacting on clicking on a dynamically created button needed?

Rusty
  • 7,112
  • 10
  • 46
  • 69
flohdieter
  • 130
  • 3
  • 15

0 Answers0