开发者

How to trigger events on all elements

开发者 https://www.devze.com 2023-04-02 07:52 出处:网络
I want to use custom events in my J-Query website. Now I\'m not sure which one is the best way to trigger a custom event on all elements attached to this event.

I want to use custom events in my J-Query website. Now I'm not sure which one is the best way to trigger a custom event on all elements attached to this event.

An example could be more clarifying here: Basically I could use

$('#id').trigger('customevent');

I don't want the triggering element to have to know all elements attached to the event. So I could use

$('*').trigger('customevent');

which would hopefully do what I want. But I'm afraid that this way has some performance issues.

Another way I was thinking about is using a class. All elements attached to the event could a开发者_运维百科dd this class to themselves. Then I can use this class as selector. However, all this smells like workaround.

I really hope that somebody knows an usual way to solve my problem.


Just found the answer by myself (which is now deprecated, see comment below):

$.event.trigger('customevent');
0

精彩评论

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