I have dynamic input text in my page that contains a attribute clientid=1 , clientid=2 etc..
Is is possible to associate a keypress event for any textbox containing this clientid? how?
note:
not all text box have the attribute which means they shouldn’t have keypress
Yes, you can use the has-attribute selector with
.on()for event delegation:Event delegation will react to elements that are added after the page has loaded (and the code has executed). Ideally, rather than using
document, you’d specify a selector for an element that does exist when the page loads, will always exist, and that will contain all of the elements you want to react to thekeypressevent.