JavaScript On change not working for dynamically added select2

Use event delegation for dynamically added elements.

$(document).on("change",".docType", function() {

Answer:1

Us the 'on' method to delegate events. This will add a handler to dynamically generated elements.

$(document).on("change",".classnameyouarewatching", function() {

 //Your code
}

on method definition

Answer:2

If your elements are being dynamically loaded, you'll need to use something more like what's below. For instance, say you're dynamically generating via AJAX or something similar the following input element:

<input type="text" class="text_element" value="some value">

To add event handlers to that element try using JS like this:

<script type="text/javascript">
$(document).on('change', '.text_element', function() {
    console.log('Element with class "text_element" has changed');
    console.log('New value is: ' + $(this).val());
});
</script>

The answer above is correct, but it is not just the 'on' handler that delegates the handling of dynamically generated DOM elements. The actual trick here is to place the handler on the document as it will always exist rather than the element or element class as you have above. It is the handler on document, looking for elements of a class (2nd param of the on event) that gets the job done you're looking for.

Answer:3

I am adding footables to a table but the table has to have a tbody for each row. This is because I am adding footable sorting and filtering to an existing system that generates the html this way. It ...

I am adding footables to a table but the table has to have a tbody for each row. This is because I am adding footable sorting and filtering to an existing system that generates the html this way. It ...

  1. footable column sorting

The backend is developed by Spring MVC and hosted in tomcat. When I use postman dev tool in Chrome to test the endpoint (Restful), everything is working fine. The "Access-Control-Allow-Origin", "*" ...

The backend is developed by Spring MVC and hosted in tomcat. When I use postman dev tool in Chrome to test the endpoint (Restful), everything is working fine. The "Access-Control-Allow-Origin", "*" ...

  1. cors issue java
  2. cors issue java spring
  3. cors problem java
  4. cors issue fix in java
  5. cors issue in web api java

Is there a way to find all the child elements of a div that has id like:- child_*_of_parent HTML <div id="parent"> <div id=child_1_of_parent>...</div> <div id=...

Is there a way to find all the child elements of a div that has id like:- child_*_of_parent HTML <div id="parent"> <div id=child_1_of_parent>...</div> <div id=...

I'm using Angular(UI)-Google-Maps (2.1.5) and AngularJS (1.3.13) I want a marker that is always in the center of the map. The problem is that the marker only updates its position when I stop dragging....

I'm using Angular(UI)-Google-Maps (2.1.5) and AngularJS (1.3.13) I want a marker that is always in the center of the map. The problem is that the marker only updates its position when I stop dragging....

  1. angular google maps api
  2. angular google maps component
  3. angular google maps example
  4. angular google maps autocomplete
  5. angular google maps npm
  6. angular google maps geocoding
  7. angular google maps heatmap
  8. angular google maps directions
  9. angular google maps marker
  10. angular google maps types
  11. angular google maps add marker
  12. angular google maps not showing
  13. angular google maps documentation
  14. angular google maps search box example
  15. angular google maps cluster example
  16. angular google maps change marker icon
  17. angular google maps directions example
  18. angular google maps get current location
  19. angular google maps tutorial
  20. angular google maps github