1

I have several buttons contain some values:

<button class="Hotspot" onclick="ChangeView()" slot="hotspot-1" camera.Orbit='2.895deg 85deg 27.92m' ;>

and I need to create function that read camera.Orbit value from button's container after click on it:

function ChangeView() {
    const modelViewer = document.querySelector('#orbit-demo');
    modelViewer.cameraOrbit = camera.Orbit ???
}

I have no idea how to solve this. I do not use getElementbyId because it has to work for all buttons (not specific one). I barely can JS.

Thank you for help.

2 Answers 2

2

You can use Element.getAttribute:

function ChangeView() {
  const modelViewer = document.querySelector('#orbit-demo');
  let orbit = modelViewer.getAttribute('camera.Orbit')
  console.log(orbit)
}
<button class="Hotspot" onclick="ChangeView()" slot="hotspot-1" camera.Orbit='2.895deg 85deg 27.92m' id="orbit-demo">Click</button>

Sign up to request clarification or add additional context in comments.

Comments

0

The onclick function passes the click event to the method. You can take the target of this event (the button element) and acquire tha attribute like that.

onclick(e => changeView(e))
ChangeView(e) {
    // do things with e.target.???
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.