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

204
Views
How to run three similar (number counter) scripts beneath each other (Only the first works)?

I would like to have three number counters on my Wordpress website beneath each other.

I was able to make the code work fine with the first number counter, but when I add two more counters beneath ("counter1", "counter2", "conter3"), they do not show any numbers.

Help would be appreciated!

THIS WORKED FINE ALL BY ITSELF:

up to <a id="counter1"></a><!-- counts --> times lower cost

<script>
        let counts=setInterval(updated);
        let upto=0;
        function updated(){
            var count= document.getElementById("counter1");
            count.innerHTML=++upto;
            if(upto===1000)
            {
                clearInterval(counts);
            }
        }
    </script>

BUT THIS DOESNT WORK (just multiplied the above code):

up to <a id="counter1"></a><!-- counts --> times lower cost

<script>
        let counts=setInterval(updated);
        let upto=0;
        function updated(){
            var count= document.getElementById("counter1");
            count.innerHTML=++upto;
            if(upto===1000)
            {
                clearInterval(counts);
            }
        }
    </script>

up to <a id="counter2"></a><!-- counts --> times better quality

<script>
        let counts=setInterval(updated);
        let upto=0;
        function updated(){
            var count= document.getElementById("counter2");
            count.innerHTML=++upto;
            if(upto===1000)
            {
                clearInterval(counts);
            }
        }
    </script>

up to <a id="counter3"></a><!-- counts --> times less time

<script>
        let counts=setInterval(updated);
        let upto=0;
        function updated(){
            var count= document.getElementById("counter3");
            count.innerHTML=++upto;
            if(upto===1000)
            {
                clearInterval(counts);
            }
        }
    </script>

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

when you define a <script> tag in your file, every variable are shared between them! so by changing the name of varables you can achive what you want.

up to <a id="counter1"></a><!-- counts --> times lower cost
<br />
<script>
        let counts1=setInterval(updated);
        let upto1=0;
        function updated(){
            var count= document.getElementById("counter1");
            count.innerHTML=++upto1;
            if(upto1===1000)
            {
                clearInterval(counts1);
            }
        }
    </script>

up to <a id="counter2"></a><!-- counts --> times better quality
<br />
<script>
        let counts2=setInterval(updated);
        let upto2=0;
        function updated(){
            var count= document.getElementById("counter2");
            count.innerHTML=++upto2;
            if(upto2===1000)
            {
                clearInterval(counts2);
            }
        }
    </script>

up to <a id="counter3"></a><!-- counts --> times less time

<script>
        let counts3=setInterval(updated);
        let upto3=0;
        function updated(){
            var count= document.getElementById("counter3");
            count.innerHTML=++upto3;
            if(upto3===1000)
            {
                clearInterval(counts3);
            }
        }
    </script>
enter code here

about 4 years ago · Santiago Trujillo 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!