How to simulate a click with JavaScript?

前端 未结 8 2000
说谎
说谎 2020-11-22 01:49

I\'m just wondering how I can use JavaScript to simulate a click on an element.

Currently I have:



        
8条回答
  •  情话喂你
    2020-11-22 02:14

    document.getElementById('elementId').dispatchEvent(new MouseEvent("click",{bubbles: true, cancellable: true}));
    

    Follow this link to know about the mouse events using Javascript and browser compatibility for the same

    https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent#Browser_compatibility

提交回复
热议问题