programmatically trigger click event in svg rect element

前端 未结 2 1625
广开言路
广开言路 2021-01-03 04:45

How to programmatically trigger click event in svg rectangle element element? like :$(\"#targetElm\").triger(\"click\");

     

        
2条回答
  •  一生所求
    2021-01-03 05:14

    How about this

    document.getElementById("targetElm").dispatchEvent(new Event('click'));
    

    Here's a working example...

    document.getElementById("targetElm").dispatchEvent(new Event('click'));
    
        
    

    i.e. create a click event and dispatch it to the element. Although you don't seem to have any handler for the click event in your question.

提交回复
热议问题