I'm trying to prepend a div for every element that I have in an array. I currently have elem1 and elem2 stored in the appendedElements array. Using a for loop, I am looping through the array and attempting to display two divs, one with "elem1" as the text, and the other with "elem2".
Currently what is happening is that it is correctly prepending the number of divs that it should but it displaying elem2 twice!
var appendedElements = ["elem1","elem2"];
for(var x in appendedElements) {
var appendedFirst = '<div class="media"><p>'+ appendedElements[x] +'</p></div>'
}
$.each(appendedElements,function() {
$('.statusfeed').prepend(appendedFirst);
});
Help me out here guys!
Does this do what you're trying to accomplish because it's not very clear.
var appendedElements = ["elem1","elem2"];
$.each(appendedElements, function(i, v) {
var addThis = '<div class="media"><p>'+ v +'</p></div>'
$('.statusfeed').prepend(addThis);
});