Search code examples
javascriptjquerycssbackground-position

Can't change background-position with jQuery


I have a body element:

<body id="body" class="watermark">

Css class "watermark" is:

.watermark { background-image: url('/assets/images/watermark.png');
             background-repeat: repeat; 
             background-position: -250px 850px; }

I need change background position under some circuumstances:

<script>   
   $( document ).ready(function() {
       $("#body").css = ('backgroundPosition','-250px 50px');
   });      
</script>

But this doesn't work. I've tryed both backgroundPosition and background-position but body element is still keeping orginial background-position values defined in css. No error in console. What I'm doing wrong?


Solution

  • You need to use:

    $('#body').css('background-position', '-250px 50px');
    

    or

    $('#body').css('backgroundPosition', '-250px 50px');