Home > Blockchain >  Simulate mouse click reactjs
Simulate mouse click reactjs

Time:11-18

I have a project of mine where a click should happen (click first one from collapsed list item), but it should happen automatically without user taking mouse on it(cursor) and clicking it.

that list item collapse comes from material ui.

any idea is appreciated.

my code to try : enter image description here

CodePudding user response:

Add an ID to the element you want to click, then you can do something like

document.getElementById("elementYouWantToClick").click();

CodePudding user response:

This answer could be what you are looking for: Simulate click event on react element

tldr: You can't just fire .click() on the element, you have to simulate mousedown and mouseup events.

  • Related