0

I am trying to append elements with multiple values from my array, but i am doing something wrong. This is my code:

for(var i=0; i < pricesArray.length; i++) {
      var ulList = document.getElementById('season-prices');

      ulList.append(`
        <div class="flex"> <input type="checkbox"></input> <span>` + pricesArray[i].start_date `</span> <span>` + pricesArray[i].end_date `</span> 
        <span>` + pricesArray[i].currency `</span> <span>` + pricesArray[i].price `</span>  </div>
      `)
    }

The error I get is:

pricesArray[i].start_date is not a function

Is there another way, or a better way to do this? I used to do something like this in jQuery but cannot remember where and how exactly..

2
  • please show what pricesArray contains Commented Aug 28, 2018 at 12:06
  • @YoukouleleY It contains these properties I wrote in the code, start_date, end_date.. Commented Aug 28, 2018 at 12:08

1 Answer 1

3

you are missing '+' after pricesArray[i].start_date. also after every property. you need to put plus symbol in front and back.

for(var i=0; i < pricesArray.length; i++) {
          var ulList = document.getElementById('season-prices');

          ulList.append(`
            <div class="flex"> <input type="checkbox"></input> <span>` + pricesArray[i].start_date + `</span> <span>` + pricesArray[i].end_date + `</span> 
            <span>` + pricesArray[i].currency +`</span> <span>` + pricesArray[i].price + `</span>  </div>
          `)
        }
Sign up to request clarification or add additional context in comments.

3 Comments

To clarify for everybody: before the back-tick without an operator, a tag function was expected.
Ah, jesus... but there is another issue now, it is appending these elements as string, not as HTML elements, what should I change for that?
try to use : ulList.innerHTML += {your string}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.