Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
How to read specific value from button in js function

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.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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>

about 4 years ago · Juan Pablo Isaza Report

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.???
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!