开发者

jQueryfy custom event creation code

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜