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

139
Views
Quiero obtener la ID de la primera entrada con un color verde dentro de la matriz de entradas y luego cambiar el color de esa entrada por su ID

Quiero obtener la identificación de entrada aquí y usarla para cambiar el color de entrada para que sea gris. Luego repita el proceso para otras entradas con color verde

 var getGreenColor = document.getElementsByClassName("my_inputs")[0].style.color; if (getGreenColor == "green") { console.log("green") } else console.log(getGreenColor)
 <input type="text" style="color: green;" id="1" class="my_inputs" value="stuff"> <input type="text" style="color: green;" id="2" class="my_inputs" value="stuff"> <input type="text" style="color: green;" id="3" class="my_inputs" value="stuff"> <input type="text" style="color: green;" id="4" class="my_inputs" value="stuff">

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Entonces, por lo que entiendo, desea cambiar todas las entradas con texto de color verde a gris. Si ese fuera el caso, desearía obtener los elementos en cuestión haciendo lo siguiente:

 var greenInputsArray = document.getElementsByClassName("my_inputs");

Y luego podría recorrer la matriz y, si el color es verde, puede cambiar el color a gris de la siguiente manera:

 for (var i = 0; i < greenInputsArray.length; i++) { if(greenInputsArray[i].style.color == "green") { greenInputsArray[i].style.color = "grey"; } }
about 4 years ago · Juan Pablo Isaza Report

0

Necesita el estilo.color o getComputedStyle

El estilo.color no está definido si no está en línea

 const getColor = ele => ele.style.color || window.getComputedStyle(ele).color; document.querySelectorAll(".my_inputs").forEach((ele,i) => { const color = getColor(ele); console.log(i,color) if (color === "green" || color === "rgb(0, 128, 0)") { ele.style.color = "grey" } })
 #id1 { color: green; }
 <input type="text" style="color: green;" id="id2" class="my_inputs" value="stuff" /> <input type="text" id="id1" class="my_inputs" value="stuff"> <input type="text" style="color: green;" id="id3" class="my_inputs" value="stuff"> <input type="text" style="color: red;" id="id4" class="my_inputs" value="stuff"> <input type="text" style="color: green;" id="id5" class="my_inputs" value="stuff">

about 4 years ago · Juan Pablo Isaza Report

0

Solo usa

 var elements = document.getElementsByClassName('my_inputs'); for (let a=0; a < elements.length; a++) { if (elements[a].style.color == 'green') { elements[a].style.color = 'grey'; } }

Esto recorrerá los elementos y, si es verde, lo cambiará a gris.

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!