I have created an array of objects and a function that loops over this array while creating a component, I am trying to append the component to a div in the HTML but I keep getting the following error: app.js:722 Uncaught TypeError: Cannot read property 'append' of null
Also is there a way to append the 'method' component to a different div?
Can anyone help? I would like to know how to do this in vanilla Javascript.
let internationalCountries = [
{
name: "Hermes",
method: "Standard Delivery",
timmeScale: "Delivery within 5 to 7 working days",
},
{
name: "USP",
method: "Standard Delivery",
timmeScale: "Delivery within 1 to 2 working days",
},
{
name: "DPD",
method: "Standard Delivery",
timmeScale: "Delivery within 11 to 21 working days",
},
]
let renderCountryList = () => {
let itemName = "";
let method = "";
for (let i = 0; i < internationalCountries.length; i++){
itemName += '<li class="country">'+ internationalCountries[i].name +'</li>';
method += '<div class="delivery-info"> <p>' + internationalCountries[i].method + '</p> <p>' + internationalCountries[i].timmeScale + '</p> </div>';
}
return itemName, method;
}
renderCountryList()
let list = document.querySelector('.country-list')
let countryList = renderCountryList();
console.log(countryList)
list.append(countryList)
<div>
<ul class="country-list">
</ul>
</div>