Fake “click” to activate an onclick method

前端 未结 11 955
醉话见心
醉话见心 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:46

    You can also try getting the element's onclick attribute and then passing into eval. This should work despite the big taboo over eval. I put a sample below

    eval(document.getElementById('elementId').getAttribute('onclick'));
    

提交回复
热议问题