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

190
Views
Cambiar un texto de cadena si otro contiene un valor determinado

Tengo este código html:

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

La salida es:

 3 days to the EVENT.

La cuenta regresiva 2 está ejecutando una función que calcula los días restantes.

Quiero que cuando la cuenta regresiva2 del intervalo sea = 1, el texto de los días del intervalo cambie a "día", no a "días".

Intenté este código, pero no funcionó:

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

¿Alguna idea?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

¿Quieres algo como esto?

 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

Esto ayuda ?

 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!