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

105
Views
Cómo mostrar HTML de getElementsByClassName con JSON.parse()

¿Cómo ajusto este código para mostrar el valor o comida favorita? Funciona con getElementById pero no con getElementsByClassName pero quiero usar una clase:

archivo del servidor - ProcesssingFileOnServer.php:

 <?php $myObj = new stdClass(); $myObj->name = "John"; $myObj->favFood = "Pizza"; $myJSON = json_encode($myObj); echo $myJSON; ?>

archivo de cliente:

 <!DOCTYPE html> <html> <head> </head> <body> <p id="theName"></p> <div class="bla"></div> <script> const xmlhttp = new XMLHttpRequest(); xmlhttp.onload = function() { const myObj = JSON.parse(this.responseText); document.getElementById("theName").innerHTML = myObj.name; document.getElementsByClassName("bla") = myObj.favFood; } xmlhttp.open("GET", "ProcesssingFileOnServer.php"); xmlhttp.send(); </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Cuando usan la clase, el resultado es una matriz.

 var el = document.getElementsByClassName("bla") for (let i = 0; i < el.length; i++) { el[i].innerHTML = 'asdsadas'; }
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!