0

I have an input the with a live class "btnForget", I tried this code

 $("document").on('keydown', '.btnForget', function() {
         alert("keydown...");
});

But it doesn't work if the class is not there from the beginning.

rodboc
  • 175
  • 1
  • 2
  • 10

1 Answers1

2

You should not use quotes with document

<!-- works  -->
$(document).on('keydown', '.btnForget', function() {
         alert("without");
});


<!-- does not work  -->
$("document").on('keydown', '.btnForget', function() {
         alert("with");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button type="button" class="btnForget">Click</button>
epascarello
  • 204,599
  • 20
  • 195
  • 236