When I run both codes in the console, eventTarget.click() returns undefined but actually clicks the target element whereas eventTarget.dispatchEvent(new Event("click")) returns true but doesnt click the target element. I am trying to understand but I cant figure out why there are 2 different outcomes. Can you please explain why and how they are different? Arent both of them supposed to click the element on the page?
document.getElementById("button").click()
and
document.getElementById("button").dispatchEvent(new Event("click"))