Skip to content Skip to sidebar Skip to footer

Javascript - Efficiently Insert Multiple HTML Elements

I'd like to create a select element with a list of a user's Facebook friends (obtained as a JSON object). I hardcode into my HTML, then

Solution 1:

Try this in your for loop instead:

var o = document.createElement('option');
o.setAttribute('value', response.data[i].id);
o.appendChild(document.createTextNode(response.data[i].name));
msgContainer.appendChild(o);

Post a Comment for "Javascript - Efficiently Insert Multiple HTML Elements"