1
#footer {
    height: 70px;
    background:url('../image/footerImg.gif'); 

}

My jQuery code:

$(document).ready(function(){
    var h=$(window).height();  
    var w=$(window).width();  
}); 

Now I want to assign the width of background:url('../image/footerImg.gif'); as 'w'(var w=$(window).width();). How can do this?

2 Answers 2

2

Try this:

var h = $(window).height();
$('#footer').height(h);
Sign up to request clarification or add additional context in comments.

Comments

1

Since you have mentioned about css property on background image, i assume you are looking at background-size

You can do this:-

$(document).ready(function(){
   var h=$(window).height() + "px";  
    var w=$(window).width() + "px";  
    $('#footer').css({"background-size":  w + " " + h });
});

Comments

Your Answer

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