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

102
Views
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 answers
Answer question

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 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!