Reputation: 1852
i want to apply background image with no repeat using javascript..
#img_name{
background-image:
background-repeat:
}
how to convert this accordingly
$("#img_name").html("<img src=assets/\images\/"+data['img_name']+">");
Upvotes: 1
Views: 59
Reputation: 6836
Try this:
$('#img_name').css('background-image', 'url("assets/images/"'+data['img_name']+'")');
$('#img_name').css('background-repeat', 'no-repeat');
Or, setting both in one go:
$('#img_name').css({
'background-image' : 'url("/assets/images/'+data['img_name']+'")',
'background-repeat': 'no-repeat'
});
Upvotes: 2