If you're trying to add class
and background
to the new inner div
element then it would be more like:
for (i = 0; i < store.image().length; i++) {
$('#carousel-inner').append(
$("<div />").addClass("shop-image item")
.css('background-image', 'url(' + store.image()[i] + ')')
);
}
As is in your question, it's adding the class and bg image to #carousel-inner, not to the div inside.
Also, have you console logged store.image()[i]
to make sure you're getting the link
expected? If not, just inside your for statement, add console.log("image["+i+"]:", store.image()[i])
and check developer console to see what you get.
You can also add multiple items in an append, each with it's own properties simply by adding ,
between each one, and even append to inner elements!
for (i = 0; i < store.image().length; i++) {
$('#carousel-inner').append(
$("<div />").addClass("shop-image item")
.css('background-image', 'url(' + store.image()[i] + ')'), // <-- see the pretty comma!
$("<div />").addClass("shop-image item")
.css('background-image bg-copy', 'url(' + store.image()[i] + ')'), // <-- see the pretty comma!
$("<span />", { text: "I'm a Silly String!" }).addClass("silly-string")
.append( // here i add an inner element to this span!
$("<span />", { text: " I'm inside this silly string!" })
)
);
}