开发者

jQueryfy custom event creation code

开发者 https://www.devze.com 2023-03-04 18:36 出处:网络
Out of curiosity, how can I jQueryfy the below event generat开发者_运维问答ion code var newevent = document.createEvent(\"Event\");

Out of curiosity, how can I jQueryfy the below event generat开发者_运维问答ion code

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

where this points to the element currently selected.

Note: there is something wrong with my SO editor right now, as I cannot see the tools to format, or preview. Will format once it is working.


You would 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 triggers event handlers that are not bound via jQuery.

0

精彩评论

暂无评论...
验证码 换一张
取 消