Fake “click” to activate an onclick method

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

    Once you have selected an element you can call click()

    document.getElementById('link').click();
    

    see: https://developer.mozilla.org/En/DOM/Element.click

    I don't remember if this works on IE, but it should. I don't have a windows machine nearby.

提交回复
热议问题