Tomas Turan
Tomas Turan

Reputation: 1255

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?

Upvotes: 2

Views: 699

Answers (2)

Milind Anantwar
Milind Anantwar

Reputation: 82231

You need to use:

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

or

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

Upvotes: 2

Dileep
Dileep

Reputation: 515

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

Upvotes: 0

Related Questions