I'm selecting data from an API which i then make into Objects with document.createElement but how can i style them?
Here's my Js code:
fetch('https://randomuser.me/api/?results=5&nat=us').then(response =>{
return response.json();
}).then(responseJson=>{
responseJson.results
console.log(responseJson);
for(const user of responseJson.results){
const img = document.createElement ("IMG");
img.innertext = user.picture.medium;
img.setAttribute("src", user.picture.medium)
img.setAttribute("width", "50");
img.setAttribute("height", "50");
img.setAttribute("alt", "");
document.body.appendChild(img)
const name = document.createElement("SPAN");
name.innerText = user.name.first;
document.body.appendChild(name);
const phone = document.createElement("SPAN");
phone.innerText = user.phone;
document.body.appendChild(phone);
console.log(user);
}
})
I've tried to refer to the name.innerText But that didn't work either. However i can refer to them all by calling, Example:
span {
color: blue;
}
And when i inspect the code it shows that the span it creates has no id what so ever, May that be the problem?
classNameand define that CSS class?