So I'm creating a simple javascript program that allows me to add text boxes and a remove button that when clicked removes the button and the text box next to it:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<div id="space">
<div>
<input type="text" class="in"/>
<button class="btn" id="1">Remove</button>
</div>
</div>
<button id="add">Add</button>
<br/>
<button id="cacl">Calculate</button>
<br/>
<div id="container">
</div>
</body>
</html>
And here is the script
$(function () {
var i=2;
$("#add").click(function () {
$("#space").append('<div><input type="text" class="in"/> <button class="btn" id="'+i+'">Remove</button> <br/></div>');
i++;
});
$(".btn").on('click', function () {
console.log("OK");
$(this).parent().remove();
})
});
However when I click on the remove button nothing happens it doesn't even log "OK".
Any ideas?