How to use jquery trigger anchor's default click event?

前端 未结 5 1826
醉话见心
醉话见心 2021-01-06 12:57

Suppose I have an anchor in my page like :turn to header then I also set a button in my page

5条回答
  •  逝去的感伤
    2021-01-06 13:18

    jQuery does not have a way to trigger the native DOM event directly.

    To do that, you can use the plain old standard DOM methods:

    var evt = document.createEvent("Event");
    evt.initEvent("click", true, true);
    $('#anchor').get(0).dispatchEvent(evt);
    

    For support of IE8 or earlier, you need to use the IE-specific event methods createEventObject and fireEvent.

提交回复
热议问题