bigskysoftware / _hyperscript

a small scripting language for the web
BSD 2-Clause "Simplified" License
3.17k stars 150 forks source link

How to trigger a click on a child element? #592

Open aalexei opened 1 week ago

aalexei commented 1 week ago

Hi, I'm trying to add keybindings to a UI, and would like to simulated a mouse click on a child element from the keyboard. Something line _="on keyup[key=='a'] trigger click on the first <button.yes/> in me"

but this doesn't work. To test, "on keyup[key=='a'] toggle .bg-orange-300 on the first <button.yes/> in me" works fine to change the attribute of the target element, but I want to simulate a click on the element that triggers the existing event handlers exactly like the user had used a mouse. Is this possible?

aalexei commented 1 week ago

I can get the effect with on keyup[key=='a'] get the first <button.yes/> in me then call it.click()