Aidan Young
Aidan Young

Reputation: 614

A-frame object onclick function

I have an object in my scene and I would like it so that when I click on the object, a function called myFunction occurs. How can this be done? I have also assigned an id of #plane1 to my object in case that could help with the function. How can I have it so when I click on the object #plane1, a function called myFunction occurs?

Upvotes: 3

Views: 1107

Answers (1)

Dang Khoa Chiem
Dang Khoa Chiem

Reputation: 105

Well you can use the onclick event on an HTML element. So for example:

<div id="plane1" onclick="myFunction()">Click me</div> 

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click

OR

You use addEventListener() if you want to add the event using JavaScript. So for example:

const plane = document.getElementById("plane1");
plane.addEventListener("click", myFunction);

https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

Upvotes: 1

Related Questions