0

I have a button "Confirm" that is being printed by Javascript, i want to do something after user click this button (for example an alert), but when i try to use on click event nothing happens. How can i do?

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    document.getElementById("par_2").innerHTML = '<button id="btn" type="submit">Confirm</button>'
  });
  
  $("#btn").on('click',function(e){
        alert("Hello");
  });
});
</script>
</head>
<body>

<h2>This is a heading</h2>

<p>This is a paragraph.</p>
<p id="par_2">This is another paragraph.</p>

<button>Click me</button>

</body>
</html>

I simplified my problem. My real problem is to submit a printed form...

0 Answers0