I'm trying to dynamically add input fields based on an input field value. After adding fields, I want to add events on these dynamically added input fields, and this's what I did, but I'm not getting the result I want. Here's what I tried using jquery.
html file :
<input class='cls1' id='num' />
<div id="samp"></div>
script file
function add() {
var num = $("#num").val()
data = ""
for (i = 0; i<num; i++) {
var id_name = "input_" + i
data += "<input class='cls2' id='" + id_name + "' /><br>"
}
$("#samp").show().html(data)
}
$(".cls1").on("change keyup paste", function (event) {
console.log("chng1")
// this's logging
add() // this adds input fields
})
$(".cls2").on("change keyup paste", function (event) {
console.log("chng2") // not logging
})
$("input[id^='input_']").on("change keyup paste", function (event) {
console.log("chng2") // not logging
})
Any help would be appreciated.