Trigger onmouseover event programmatically in JavaScript

前端 未结 8 672
庸人自扰
庸人自扰 2020-11-27 18:58

Is there a way to programmatically trigger the onmouseover event in plain JavaScript? or \"extract\" the method from the onmouseover event to call

相关标签:
8条回答
  • 2020-11-27 19:35

    I needed to do something similar, but I'm using jQuery, and I found this to be a better solution:

    Use jQuery's trigger function.

    $j('#top-div' ).trigger( 'mouseenter' );
    

    You can also add parameters to it if you need to. See the jQuery documentation on .trigger.

    0 讨论(0)
  • 2020-11-27 19:42

    You would do it something like this:

    document.getElementById('top-div').onmouseover();
    

    However, as mentioned in the comments, it would be worth testing before being considered an issue.

    0 讨论(0)
提交回复
热议问题