Question

My jQuery:

$(function() {
$("#change-background").on('submit', function(e) {
    var src = $(this).find("input").val();
    $.cookie("_usci",src);
    //NOT HERE$("body").css("background-image", 'url($.cookie("_usci"))';
});
    //BUT HERE!! otherwise it will not work
});

The url need to be within these ' or these " but then the cookie will not be used good, how can I solve this?

Was it helpful?

Solution 2

Use a string concatenation inside of the css argument

$("body").css("background-image", 'url('+$.cookie("_usci")+')');
//don't forget to close your css call as Jonathan notes       ^

OTHER TIPS

Have you tried this?:

$("body").css("background-image", 'url(' + $.cookie("_usci") + ')';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top