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']+">");
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'
});
<?php echo data['img_name']; ?>. Replace it with a value. You can't run PHP in a .js file (or test the script in a .php file)'url("assets/images/"'+data['img_name']+'")'html(). That's what css() is for.