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

95
Views
JavaScript onClick on embedded elements

I have the following JavaScript:

<div>
    <tr onClick="click1()">
        <td>
            click 1
        </td>
        <td onClick="click2()">
            click 2
        </td>
    </tr>
</div>

function click1() {
  alert(1);
}

function click2() {
  alert(2);
}
<table border="1">
  <tr onClick="click1()">
    <td>
      click 1
    </td>
    <td onClick="click2()">
      click 2
    </td>
  </tr>
</table>

If I click 'click 1', the click1() function is called as expected. If I click 'click 2', the click1() & click2() functions are both called.

Question

How do I make the click on 'click 2' only call the click2() function, and not call the click1() function?

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

0

Well, the easiest way is just to move your 'click 1' trigger to the button itself:

<div>
    <tr>
        <td onClick="click1()">
            click 1
        </td>
        <td onClick="click2();">
            click 2
        </td>
    </tr>
</div>

However, I'm assuming you want to keep the click 1 trigger where it is, in which case you can add event.stopPropagation() to the event:

<div>
   <tr onClick="click1();">
       <td>
           click 1
       </td>
       <td onClick="click2(); event.stopPropagation();">
           click 2
       </td>
   </tr>
</div>
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!