I am using the example from here: How to add a button dynamically using jquery
What I would like to know, is how can I add jquery function on the new buttons that are created after I clicked on insert after?
Let's say I have clicked twice the button, insert after and so I have these new two buttons. How can I add functions on the buttons?
What I would like to recreate is: `
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<button id = "btn_add> Add </button>
<div id= "container">
<div id = "under_container">
</div>
</div>
</body>
</html>`
JS
$(document).ready(function () {
$("#btn_add").click(() => {
$('#container').append(`<div id="text">\
<div id="title" >\
Trial
</div> \
<button id="btn_addOther"> Add Other </button>
</div>`);
})
$("#btn_addOther").click(() => {
$('#under_container').append(`<div id="card"> \
<textarea placeholder="Title" type="text" >Title</textarea> \
</div>`
);
});
});
So, I would like to create a button that adds other buttons and when the new buttons are created, they should be able to create other things on the page.