I am loading mobile number field dynamically using jquery ajax.
<form role="form" id="loginFrm">
<div class="form-signup pb40">
<label>Enter Mobile Number</label>
<input class="form-signup-input validate mobnum required" maxlength="10" type="text"id="icon_prefix">
</div>
</form>
Javascript
Then, handling keypress event using on(),
$(document).on('keypress','.mobnum',function (e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
}
});
But i am searching the target using 'document'. Is this approach is correct? if not, please suggest a best approach.