0

I want to set page backgroudImage using jQuery.
I wrote this code but it is not work.
What is the problem?
Image is exist
Image

var Page = $(this);
$(function () {
    SetBackgroundImage();
});


function SetBackgroundImage() {
    //Todo read ImagePath from server

    var ImageUrl;
    ImageUrl ="../Images/BackgroudImage.jpg";

    try {

        Page.css('background-image', 'url(' + ImageUrl + ')');
    } catch (e) {
        //LogError
        alert(e.Description);
    }

} 

1 Answer 1

1

The variable Page currently holds a reference to a jQuery object which is wrappend around the window element. You'll want the jQuery object to wrap around the body tag.

To retrieve the body element you'll have to adjust your code a bit, like so:

$(function() {
    $('body').css('background-image', 'url(' + ImageUrl + ')');
});

I suggest you take a look at the jQuery API for some more information about jQuery.

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

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.