Search code examples
jquerycssbackground-size

Jquery not changing background-size attribute


I am pretty new to this and having difficulty figuring out by my code will not execute the following

var h = $( window ).height();

$('.bg').css({

    'height' : h,
    'background-size' : "auto" + h

})

More specifically the background-size is not being changed. The height works great however I want the background-size to look as follow background-size: auto 900px (assuming it gathered 900px as the height).

Am I missing something?

Thank you in advanced.


Seems like the below answer worked however did need to add the px as follows;

"background-size" : "auto " + h + "px"

Thank you!!!


Solution

  • Add space after auto:

    'background-size' : "auto " + h