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

134
Views
¿Cómo puedo hacer que el tercer elemento ingresado en un cuadro de entrada tenga un color diferente? (JS, HTML, CSS)

Tengo un cuadro de entrada en el que puedo ingresar texto, presiono enter y devuelve ese texto en una lista. Sin embargo, quiero que devuelva cada tercer elemento azul. ¿Cómo puedo hacer esto? Ahora mismo solo tengo:

 if(document.getElementById('item').value % 3 == 0) { color: red; }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Usando CSS:

 #item:nth-child(3) { color: #ccc; }

Aplíquelo a cada tercer elemento:

 #item:nth-child(3n) { color: #ccc; }

Considere usar clases en lugar de id.

about 4 years ago · Juan Pablo Isaza Report

0

Suponiendo que su lista es un elemento UL, puede filtrar todos los elementos y extraer solo cada tercer elemento y cambiar su color:

 const every_nth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1); every_nth([...document.getElementById("items").children], 3).map((e)=> e.style.color = 'blue');
 li { color: red; }
 <ul id="items"> <li>a</li> <li>b</li> <li>c</li> <li>d</li> <li>e</li> <li>f</li> <li>g</li> <li>h</li> <li>i</li> </ul>

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!