Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click on element via Javascript console

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

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

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

like image 941
user3719693 Avatar asked Jul 26 '14 10:07

user3719693


People also ask

How do you click a element in console?

Open your page. Right-click on any element and click Inspect or Inspect element, depending on the browser you're using. Right-click on the element's source code and choose Copy > Copy XPath or Copy > XPath, depending on the browser you're using.

How do you click an element in JavaScript?

The click() method simulates a mouse-click on an element. This method can be used to execute a click on an element as if the user manually clicked on it.

How do you trigger a click element?

The HTMLElement. click() method simulates a mouse click on an element. When click() is used with supported elements (such as an <input> ), it fires the element's click event. This event then bubbles up to elements higher in the document tree (or event chain) and fires their click events.

How do I click elements in developer tools?

Apart from clicking on "More tools-> Developer Tools", we can also open the element box using the following options: Clicking the F12 key. Using keyboard shortcut, "Ctrl + Shift + i" or "Ctrl + Shift + c" on Windows Operating System.


1 Answers

You can trigger click functio like bellow

Using JQuery

$('#button1').click()

using simple JS

document.getElementById('button1').click();
like image 137
Mritunjay Avatar answered Oct 05 '22 07:10

Mritunjay