Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

197
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda