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

222
Views
How to append elements of array to DOM?

I am having trouble with adding elements to my HTML. I think my issue lies in my understanding of HTML but I'm not really sure. Here is my Javascript:

<div class="console">
    <div id="console_data">
        <p class="console_text"> </p>
    </div>
</div>

Let me explain what this is doing, or at least what I'm trying to do. The console class creates just a black rectangle, and it's gonna have some white text in it, which is what console_text is for. Here is my javascript to append things to console_data:

var consoleData = ["Hello World"]
var consoleInfo = document.getElementById('console_data')

for (var i = 0; i < consoleData; i++) {
    var anchor = document.createElement('a')
    var value = consoleData[i]
    anchor.href = value
    consoleInfo.appendChild(anchor)
}

I was under the impression this would append the text Hello World inside of the black box I created, but it's just showing the empty black box. Is my console_data tag even necessary? Where should I be trying to append my data to?

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

0

You should be checking whether i is smaller than consoleData's length, since you are iterating through it:

var consoleData = ["Hello World"]
var consoleInfo = document.getElementById('console_data')

for (var i = 0; i < consoleData.length; i++) {
    var anchor = document.createElement('a')
    var value = consoleData[i]
    anchor.href = value
    anchor.innerHTML = value
    consoleInfo.appendChild(anchor)
}
<div class="console">
    <div id="console_data">
        <p class="console_text"> </p>
    </div>
</div>

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!