JQuery click() on a div button won't fire

前端 未结 5 1206
栀梦
栀梦 2020-12-16 21:36

I am trying to emulate a user\'s click on a site who\'s code I do not control. The element I am trying to engage with a div acting as button.

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 22:33

    I actually tried on the link you gave and it works. There's no jquery on the page, so have to go by native methods.

    var click= document.createEvent("MouseEvents");
    click.initMouseEvent("click", true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
    
    document.getElementsByClassName('c-T-S a-b a-b-B')[0].dispatchEvent(click)
    

提交回复
热议问题