Search code examples
javascriptaframedom-events

How to get click event with javascript from an A-frame element


UPDATE: You can use onclick= function();in the HTML.

For example: <a-box onclick="myFunction()"></a-box>

I want to get click event of cursor with javascript from an A-frame element, like a box for example, how can I do it?


Solution

  • If you are using the cursor component:

    box.addEventListener('click', function (evt) { // ... });

    If you want to use the mouse cursor, try https://www.npmjs.com/package/aframe-mouse-cursor-component