Fake “click” to activate an onclick method

前端 未结 11 963
醉话见心
醉话见心 2020-11-28 10:11

I have an element with an onclick method.

I would like to activate that method (or: fake a click on this element) within another function.

I

11条回答
  •  执念已碎
    2020-11-28 10:44

    If you're using jQuery, you need to use the .trigger function, so it would be something like:

    element.trigger('click');
    

    http://api.jquery.com/trigger/

提交回复
热议问题