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

279
Views
Ajax: cambie el color del texto según el valor de retorno

Estoy tratando de mostrar un valor de sensor usando html/ajax. Esto funciona como se esperaba hasta ahora, sin embargo, quiero que el color del texto cambie según el valor. por ejemplo

 if value < 50 then fontcolor= blue if value >49 then fontcolor = red

¿Es eso posible?

 <p style="color:blue; position: absolute; top: 810px; width: 100px; padding-left: 340px;" id="ofen_VL">0</p> <script> setInterval(function() { // Call a function repetatively with 10 Second interval getData(); }, 10000); //10sec function getData() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("ofen_VL").innerHTML = this.responseText; } }; xhttp.open("GET", "ofen_VL.txt", true); xhttp.send(); } </script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Agregue a la respuesta su condición. Algo como:

 if (this.readyState == 4 && this.status == 200) { document.getElementById("ofen_VL").innerHTML = this.responseText; if (Number(this.responseText) > 50) { document.getElementById("ofen_VL").setAttribute('style', 'color: blue;'); } else { document.getElementById("ofen_VL").setAttribute('style', 'color: red;'); } }
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!