Click an item through the Javascript console

Imagine that the website has the #button1 element that jQuery is viewing:

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

So how do I push this element #button1 through the JavaScript console? Is there a command like click("#button1") ? Thanks.

+7
javascript jquery console
source share
5 answers

You can call the functio function as shown below.

Using jQuery

 $('#button1').click() 

using plain js

 document.getElementById('button1').click(); 
+17
source share

You can trigger a click by disabling the callback function:

 $('#button1').click(); 
+4
source share

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

 $( "#button1" ).trigger( "click" ); 
+4
source share

You cannot click, but simulate or run click . Please refer to Creating and Running Events

+3
source share

You can achieve this without jQuery:

 document.getElementById("button1").click(); // clicks the button 
+3
source share

All Articles