I have created several elements dynamically in javascript. These are, among others, range inputs. I want on "input change" event to show the value. Each of these inputs have id like 'probabilitate'+number. The number is a global variable, and is incremented on click event of a button.
When I create dynamically these inputs, the input change event does not work anymore. There is a question on stackoverflow, in which the solution is live event, not on event, and it works, partially. The code is:
$(document).on('change','#probabilitate'+nrBoli, function(){
//something
})
You need to use 'class' instead 'id' to get all elements. Using 'id' you get only the first element in the DOM:
Append elements:
Set change event:
The change event must be set whenever new elements is appended.
Example:
Hope this helps.