I trying to implement keyup function for dynamically added input fields, but it is not working
html code
<table border="1" id="table">
<colgroup>
<col width="100"/>
<col width="100"/>
</colgroup>
<tr>
<td style="text-align:center;">Activity</td>
<td style="text-align:center;">Time</td>
</tr>
<tr>
<td style="text-align:center;">
<select id="activity[]">
<option value="Working">Working</option>
<option value="Leave">Leave</option>
</select>
</td>
<td style="text-align:center;"><input style="width:35px;" type="text" class="text" maxlength="3" id="day1[]"/></td>
</tr>
</table>
<br><br>
<input type="button" value="+" id="plus" />
jquery code
$("#plus").click(function(e){
$("#table").append("<tr><td style='text-align:center;'><select id='activity[]'><option value='Working'>Working</option><option value='Leave'>Leave</option></select></td><td style='text-align:center;'><input style='width:35px;' type='text' class='text' maxlength='3' name='day1' id='day1[]'/></td></tr>");
e.preventDefault();
});
$.each($('[id^=day1]'), function (i, item) {
$("[id*='day1']").keyup(function () {
if (this.value.match(/[^a-zA-Z.]/g)) {
this.value = this.value.replace(/[^a-zA-Z.]/g, '');
}
});
});
see demo here
i tried the soln here also it was also not working.
Try this
DEMO