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

197
Views
Change a string text if another contains a certain value

I got this html code:

<p class="day-left">
   <span style="color: #000" id="countdown2"></span> 
   <span id="days">days</span> to <strong>the EVENT</strong>!
</p> 

The output is:

3 days to the EVENT.

The countdown 2 is running a function that calculate the days left.

I want when the span countdown2 is = 1, the text of span days change to "day", not "days".

I tryed this code, but not worked:

if ($('span#countdown2:contains("<span style="color: #000" id="countdown2">1</span>")').length > 0) {
            $("#days").write("day");
        }

Any idea?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

do you want something like this?

const countdown2 = document.getElementById("countdown2");
const days = document.getElementById("days");
const btn = document.querySelector("button");

btn.addEventListener("click", () => {
  countdown2.textContent = +countdown2.textContent - 1;
  
  // you need these codes
  if (+countdown2.textContent < 2) {
    days.textContent = "day";
  }
  //
  
});
<button>decrease</button>

<p class="day-left">
   <span style="color: #000" id="countdown2">4</span> 
   <span id="days">days</span> to <strong>the EVENT</strong>!
</p> 

about 4 years ago · Santiago Trujillo Report

0

This helps ?

const days = document.getElementById("days")
const counter = document.getElementById("countdown2")
let count = 10

window.onload = () => {
  counter.innerText = count

  this.interval =
    setInterval(() => {
      count--
      counter.innerText = count
      days.innerText = count === 1 ? "day" : "days"
      if (count <= 0) clearInterval(this.interval)
    }, 1000)

}
<p class="day-left">
  <span style="color: #000" id="countdown2"></span>
  <span id="days">days</span> to <strong>the EVENT</strong>!
</p>

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!