Last Updated: February 25, 2016
· devatotech

jQuery Delegation on a Select Element

We were having some issues with a Bootstrap Modal that was not behaving normally after it was closed and reopened. (Dynamically generated via remote).

We switched the change function to use delegate and listened for any changes under the parent element, and it solved the problem:

$('#suspendModal').delegate('select.suspension_type', 'change', function(){
  // Code goes here

You basically grab a parent element, and it will listen for changes on any select with the class "suspension_type" under it. This is a raw explanation of delegation, but I hope it helps somebody having similar issues.