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

184
Views
My Javascript document.createElement("li") is not working

My Javascript code is not rendering the createElement("li") bit of my program. I have tried to debug it but it seems like there is something that I am still missing. This is my code.

var state = {
    balance : 32,
    income: 0,
    expense: 220,
    transactions :[
        {name:'Salary', amount: 5000, type: 'income'},
        {name:'Groceries', amount: 30, type: 'expense'},
        {name:'Buy Guitar', amount: 300, type: 'expense'}
    ]
}

var balanceEl = document.querySelector('#balance');
var incomeEl = document.querySelector('#income');
var expenseEl = document.querySelector('#expense');
var transactionsEl = document.querySelector('#transactions');

function init() {

    balanceEl.innerHTML = `$${state.balance}`;
    incomeEl.innerHTML = `$${state.income}`;
    expenseEl.innerHTML = `$${state.expense}`;

    var transactionsEl;

    for (var i = 0; i < state.transactions.length; i++) {
        transactionsEl = document.createElement("li");
        transactionsEl.append(state.transactions[i].name);
        transactionsEl.appendChild(transactionsEl);
    }
}
init();
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

AppendChild is used on the parent

var state = {
    balance : 32,
    income: 0,
    expense: 220,
    transactions :[
        {name:'Salary', amount: 5000, type: 'income'},
        {name:'Groceries', amount: 30, type: 'expense'},
        {name:'Buy Guitar', amount: 300, type: 'expense'}
    ]
}

var list = document.querySelector('#list');

function init() {

    var transactionsEl;

    for (var i = 0; i < state.transactions.length; i++) {
      transactionsEl = document.createElement("li");
      transactionsEl.append(state.transactions[i].name);
      list.appendChild(transactionsEl);
    }

}
init();
<ul id='list'></ul>

about 4 years ago · Santiago Gelvez 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!