Jquery delegate release and change event

I would like to use the delegate function with my file change event, but I'm out of luck. Here is what I am trying to do:

$("#file").delegate("change", function() {    
    $("#submit_form").trigger('click');
});

My change event is not triggered ... Am I missing something or cannot use the delegate with the change event?

+5
source share
1 answer

.delegate() a selector representing the target element is required.

$("#file").delegate('.selector_of_element_to_watch', "change", function() {    
    $("#submit_form").trigger('click');
});

If the item #fileis the one that should trigger the change event, then do not use .delegate.

$("#file").bind("change", function() {    
    $("#submit_form").trigger('click');
});

The reason for this is that the delegate handler is placed on the ancestor of the element that should trigger the event. Then you provide a selector for this element.

. , , , window, .

, , , , , , . , . , .


jQuery 1.7 - on.

.

, :

$("#file").on( "change", '.selector_of_element_to_watch', function() {
      // Run if a descendant of '#file' that matches the selector
      //    '.selector_of_element_to_watch' triggered the event
    $("#submit_form").trigger('click');
});

:

$("#file").on( "change", function() {
      // Run if '#file' itself, or ANY of its descendants triggered the event
    $("#submit_form").trigger('click');
});

( , #file , , / . , , , .)

API- bind/live/delegate, , .

+14

All Articles