Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate a mouse click in Javascript

Tags:

javascript

I have the following elements:

<input type="submit" name="add" value="add item" class="btn btn-add" onclick="addItem('add');return false;">

I want to write a Javascript to simulate a click of a mouse to add item to my shopping basket I know you can use document.getElementById('add').click() but there's no Id here

I am very new to this and any help would be much appreciated

like image 503
Mirko Avatar asked Aug 22 '26 11:08

Mirko


1 Answers

If you only have on element with name "add" you can also use:

document.getElementsByName('add')[0].click() 
like image 128
Jens Avatar answered Aug 24 '26 01:08

Jens