JQueryfy custom event creation code

Out of curiosity, how can I jQueryfy below event code

var newevent = document.createEvent("Event");
newevent.initEvent("fly", true, true);
this.dispatchEvent(newevent);

where thisindicates the selected item.

Note: something is wrong with my SO editor now, because I donโ€™t see any formatting or preview tools. It will be formatted as soon as it works.

+3
source share
1 answer

Would you use : .trigger()

$(this).trigger('fly');
// or since jQuery 1.6 you can pass an object to `jQuery.Event` to set 
// properties
$(this).trigger(jQuery.Event('fly', {/* options here */}));

But I'm not sure if it also fires event handlers that are not connected via jQuery.

+1
source

All Articles