SVG - click is not a function

前端 未结 2 1215
故里飘歌
故里飘歌 2020-12-21 01:32

I have an element like this.



        
2条回答
  •  难免孤独
    2020-12-21 02:02

    click() is a function that's only defined on HTML elements. Fortunately it's a convenience function and we can implement it ourselves pretty easily i.e.

    document.getElementById('box_w').dispatchEvent(new Event('click'));
    

    That's all the click() function does underneath the hood anyway.

    Here's an example:

    document.getElementById('box_w').dispatchEvent(new Event('click'));
     
         
    

提交回复
热议问题