Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery change event callback

How to call a function once after change() event complete?

for example, something like this: ( I know jQuery Doesn't have callback method as default )

$('#element').change( function(){
                     // do something on change
                     // $('#milestonesSelect').multiselect({ minWidth: 120 , height : '200px' ,selectedList: 4  }).multiselectfilter();
                      // some animation calls ...
                      // ...
                     }, function(){
                     // do something after complete
                      alert('another codes has completed when i called');
                     }
                   );

Is it possible to call a single callback after all the codes on change method done, except call a complete callback for every functions on it?

I need to do something after the change event has completed

Shall I need to set order to methods in change handler?

like image 747
Alireza41 Avatar asked Apr 04 '13 07:04

Alireza41


People also ask

Does jQuery Val trigger change event?

When you dynamically set a value in a textfield using jQuery . val(), you have to manually trigger the . change event if you want to add extra code that trigger when the value of the field change.

How can set click event in jQuery?

To trigger the onclick function in jQuery, click() method is used. For example, on clicking a paragraph on a document, a click event will be triggered by the $(“p”). click() method. The user can attach a function to a click method whenever an event of a click occurs to run the function.

How do I set the value of a element in jQuery?

The val() method returns or sets the value attribute of the selected elements. When used to return value: This method returns the value of the value attribute of the FIRST matched element.


1 Answers

You can probably make use of event bubbling and register a callback in the document.

$(document).on('change', '#element', function(){
    console.log('after all callbacks')
});

Demo: Fiddle

like image 143
Arun P Johny Avatar answered Oct 13 '22 22:10

Arun P Johny