0

I have below div:

<div id="MyDiv" style="background-image: " + '@Url.Content("~/images/MyImave.gif")'></div>

and I am try to set the background image dynamically by performing:

$('#MyDiv').prop("background-image", '@Url.Content("~/images/ongoing.gif")');

but it is not working, no image is found...

Any ideas?

2 Answers 2

1

use .css()

$('#MyDiv').css("background-image", '@Url.Content("~/images/ongoing.gif")');

.css() is used to set CSS properties in jQuery.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use .css() method here like:-

$('#MyDiv').css("background-image", '@Url.Content("~/images/ongoing.gif")');

as .css( propertyName, value ) is used to set one or more CSS properties for elements.

while .prop( propertyName, value ) is used to set one or more DOM properties for the elements like selectedIndex, tagName, nodeName, nodeType, etc.

Comments

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.