Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to build a team score increment button, but only the second button works, the first one doesn't count.

JavaScript
<pre><table>
                <tr>
                    <td>team 1</td>
                    <td>team 2</td>
                </tr>
                <tr>
                    <td id="score1">0</td>
                    <td id="score2">0</td>
                </tr>
                <tr>
                    <td><button id="team1" onclick="click()">+</button></td>
                    <td><button id="team2" onclick="clicksec()">+</button></td>
                </tr>
            </table>

            <script>


      let news = 0;
                function click() {

                    news ++;

                    document.getElementById("score1").innerHTML = news;
                    console.log(news);
                }

   let newss = 0;

                function clicksec() {
                    newss++;
                    document.getElementById("score2").innerHTML = newss;
                    console.log(newss);
                    }

            </script>


What I have tried:

changed id name, and function name. still nothing
Posted

1 solution

It doesn't work because you named your function "click", which is a function that already exists. Rename the function to "clickone" and it'll work.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900