In my application I have for loop to change background image of two divs. The code is :
for (var i = 0; i < length; i++) {
$("div_" + (i + 1)).css("background-image", "../imageFile.png");
}
works on internet explorer, edge, Firefox but not on Google Chrome. On Google Chrome, changes only the last image.
Thanks.
Hi again, Thanks for your quick responses Chiristian and Nascheez! I apologize, I didn't write the all the code. In the original code, I put the right structure. And it works perfectly in other browsers. But on Google Chrome and Opera, it shows only the image of the last div.
The original code is :
function testFunction() {
$.ajax({
type: 'post',
url: '@Url.Action("SomeAction", "SomeController")',
data: {
},
async:false,
dataType: 'json',
success: function(dataPieces) {
//I get all pieces whitout any error!
config.allPieces = dataPieces;
for (var i = 0; i < dataPieces.length; i++) {
$("#div_" + (i + 1)).css("background-image", dataPieces[i].ImagePath);
}
},
error: function(error) {
alert("9- La transaction a rencontré une erreur. \n" + error.message);
}
});
}