javascript - How to apply validation to cloned elements in Jquery? -


there textbox label; having validation of isnumeric.

money: <input type="text" id="dollar" name="dollar" data-require-numeric="true" value="">  //textbox id dollar0  

at run time, have created clone of above; clicking on button named add; , created textbox different id , other attributes same; say.

money: <input type="text" id="dollar1" name="dollar1" data-require-numeric="true" value=""> //cloned textbox; cloned clicking on button named clone 

on both textboxes data-require-numeric true.

issue: default textbox jquery validation getting executed. new clone; jquery not running.

following jquery:

var economy= {  init: function () { $('input[type="text"][data-require-numeric]').on("change keyup paste", function () {         check isnumeric; if yes border red     }); }}; $(economy.init); 

how resolve this?

try : need register click event handler using .on() in following way registering click handler document delegate event 'input[type="text"][data-require-numeric]'. way can handle events dynamically added elements.

var economy= {  init: function () { $(document).on("change keyup paste",'input[type="text"][data-require-numeric]',      function () {         check isnumeric; if yes border red     }); }}; $(economy.init); 

Comments