0

I am able to load image in div but I want load as background image using jQuery.

Here is my code:

src = 'image.jpg';

$(".imagePreview").html(src ? "<img src='" + ImagePath + src + "'>" : "");

Any help?

1 Answer 1

4

hope this will help you

$('.imagePreview').css('background-image', 'url(' + imageUrl + ')');
Sign up to request clarification or add additional context in comments.

1 Comment

The OP tried something like ternary operator this should be also not a right answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.