here i am giving the code to preload image by jquery.
var _images = ['/images/ajax-loader.gif'];
$.each(_images, function (e) {
$(new Image()).load(function () {
//alert($(this).attr('src') + 'has loaded!');
}).attr('src', this);
});
the above code works fine because here we hard code the image path but when image path is stored in variable then it is not working.
here i am giving the code which gives error.
var _images = '[' + data.d[0].LabelImagePath + ']';
$.each(_images, function (e) {
$(new Image()).load(function () {
$('#imgHolder').html("<img src='" + data.d[0].LabelImagePath + "' border=0/>");
$("#btnPrint").show();
}).attr('src', this);
});
this line return image path like /images/1Z520777777779.gif.
so please guide me how to preload images when image path is stored in variable with jquery by the above code. thanks