Click on element via Javascript console

前端 未结 5 975
青春惊慌失措
青春惊慌失措 2021-02-07 06:28

Imagine there is an element #button1 on website which is watched by jQuery:

$(\'#button1\').click(function(){
   console.log(\"you clicked\");
};
<         


        
相关标签:
5条回答
  • 2021-02-07 07:08

    You can not click, but simulate or trigger click. Please refer Creating and triggering events

    0 讨论(0)
  • 2021-02-07 07:22

    You can trigger click functio like bellow

    Using JQuery

    $('#button1').click()
    

    using simple JS

    document.getElementById('button1').click();
    
    0 讨论(0)
  • 2021-02-07 07:22

    You can also use this apart from the answers mentioned already:

    $( "#button1" ).trigger( "click" );
    
    0 讨论(0)
  • 2021-02-07 07:22

    You can achieve this without jQuery:

    document.getElementById("button1").click(); // clicks the button
    
    0 讨论(0)
  • 2021-02-07 07:24

    You can trigger a click by omitting the callback function:

    $('#button1').click();
    
    0 讨论(0)
提交回复
热议问题