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

103
Visualizações
JavaScript onclick event retrieve attribute?

I have some 3D shapes on a page (X3DOM) that I would like to identify when clicked with the mouse. My HTML looks like this :

<Transform translation='0 0 0'> 
                    <shape id="Roger1" number="54 -15 -34" onclick="changeColor();"> 
                        <appearance> 
                            <material diffuseColor='1 0 0'></material> 
                        </appearance> 
                        <sphere>radius='1' </sphere> 
                    </shape> 
                </Transform>

Then, in JavaScript, I have the corresponding function set up this way :

function changeColor() {
    window.alert('clicked');
}

This works great. But I don't see how I could recover the information contained in the "number" tag, number="54 -15 -34"? Any help is appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can pass the element itself as a parameter to the function:

function changeColor(element) {
    window.alert(element.getAttribute('number'));
}
<Transform translation='0 0 0'>
  <shape id="Roger1" number="54 -15 -34" onclick="changeColor(this);">
    <appearance>
      <material diffuseColor='1 0 0'></material>
    </appearance>
    <sphere>radius='1' </sphere>
  </shape>
</Transform>

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