1.

Explain The Use Of The $.fn.bind And $.fn.trigger?

Answer»

Both the $.fn.bind and $.fn.triggers are two important jquery METHODS. They are primarily used with CUSTOM events.

  • $.fn.bind: This method accepts an event type and an event handling FUNCTION as an argument for itself. This method can also accept event-related data as a second argument.
  • $.fn.trigger: This method can accept an event type as an argument. It can also take an array of values.

Example: depicting the usage of $.fn.bind and $.fn.triggers using custom data in both the cases:

$(DOCUMENT).bind('myCustomEvent',{foo:'bar'}, function(e, arg1, ARG2) { console.log(e.data.foo); // 'bar' console.log(arg1); // 'bim' console.log(arg2); // 'baz' }); $(document).trigger('myCustomEvent',['bim','baz']);

Both the $.fn.bind and $.fn.triggers are two important jquery methods. They are primarily used with custom events.

Example: depicting the usage of $.fn.bind and $.fn.triggers using custom data in both the cases:



Discussion

No Comment Found