javascript - jQuery element add event doesn't response to certain syntax -


I have a jQuery problem, jQuery does not respond to some syntax:

  $. ("#itemid") change (function (e) {....});  

It does not work at all. But when I use it:

  $ (document) .on ("change", "#itemid", function (e) {....});  

It works well, I've read the jQuery manual and I did not get any answers. My test browser is Chrome version 36.

OK because the event is connected before the DOM is presented on this page.

- If the elements are not dynamically added, then you need to wrap the document preparation process:

  $ (document) .ready (function () {// or $ (function () {$ ("#itid"). Change (function (e) {....});});  

- If element dynamic If you are adding the form then you need to use Event Delegation:

  $ (document) .on ("change", "#itemid", function (e) {.. ..});  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -