Problems trapping AJAX'ed form input click event Using Drupal 7.x w/ jQuery 1.4x, I'm trying to trap the click event when I click on a submit input of an AJAX form generated from this Commerce AJAX Cart module.

In my custom.js behaviors file, I have the following code.

$(".form-submit").click(function(){
    alert('test');
});


The alert doesn't get displayed and I have no clue as to why. I load my custom.js file from template.php using the following code.

drupal_add_js(path_to_theme() . '/scripts/global.js', array('weight' =&gt; 200));


I tried lowering 200 down to insanely low levels just to test if weight had anything to do with any of this, but nothing I tried helped.

Any ideas as to why this click event isn't working would be helpful.
Because the form is being loaded via ajax, your click handler is not binding at the right time. You need to use Drupal.behaviors, the context argument, and possibly the one() method to attach this.

Or a less drupally (but better jQuery) solution would be to use delegated events like

$(document).click(function(event)) {
  if ($(event.target).is(".form-submit") {
    alert('test');
  }
});


Note: delegated events are way more elegant in modern jQuery, the on() method is great for this. But the above is probably the best you can do in jQuery 1.4.