I'm trying to trigger a JavaScript event when an AJAX-enabled ImageField submit button is clicked.

I've tried variations on delegate(), submit(), and click(), but no joy.

This is something similar to what I'm trying:

$('#edit-field-image-und-0-upload-button').mousedown(function () {

I read the documentation I could find on Drupal's AJAX forms, but haven't found what I'm looking for yet.


I agree with DeeZone that .click() should work.

Try putting that code in a $(document).ready();

Drupal ajaxifies it's stuff on document ready so your code might be executing BEFORE the form gets ajaxified by Drupal.

$(document).ready(function() {
  $('#edit-field-image-und-0-upload-button').click(function () {

I'd check your selector #edit-field-image-und-0-upload-button to make sure it's valid, "und" seems kind of odd but I'm not sure. The event handler .click() should do the trick.

  • I'm not sure what you mean by 'valid'. The characters 'und' are valid in jQuery, and a click() handler on the div selector #edit-field-image-und-0-upload on the same page works just fine. As stated in the question, click() does not work on this selector.
    – g_thom
    Sep 26 '11 at 0:41
  • "Valid" as in is it really a selector that's working and can be referenced. Perhaps "und" in the ID name is fine, just seems odd to me considering all the other terms in the name are human readable such as "edit" and "field", etc. I just was wondering if it was a typo. If you in fact have two different elements on the page with the same ID then that too can be an issue as an ID must be unique but perhaps you were just testing on different elements. Sorry, that's all I have to offer without seeing the code for the whole page.
    – DeeZone
    Sep 26 '11 at 5:12
  • 1
    und is the language indicator and is perfectly fine.
    – Berdir
    Oct 4 '11 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.