Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

jquery not capturing all input value changes

After my document loads I have an event handler that captures changes to input values and updates an icons color to signal changes have occurred.

$(':input').on('input', stateChanged)

It’s not capturing every inputs changes though, especially some that are nested in child divs or that have been dynamically created. However if I inject it from the developer console it recognises every input and all their changes.

Any thoughts on why it’s not capturing some input changes and how to fix?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The on function only attaches listeners to elements that exist when it is called, not elements added later. But since events bubble, you can simply attach the listener to the entire document or some high-level element that is an ancestor of all your input elements.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading