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.
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.