Reputation: 37
I'm trying to not repeat background.
Here is my code
$("body").css({background : "url(../img/bgr.png)", backgroundRepeat: 'none'});
The problem is that the background repeats. How to fix that ?
Upvotes: 0
Views: 5607
Reputation: 653
Have you tried:
$("body").css({background : "url(../img/bgr.png) no-repeat" });
for dynamically,
$("body").css({background : 'url('+imageUrl+') no-repeat' })
Upvotes: 0
Reputation: 318548
Your problem is that background
sets all background-related options while background-repeat
is just a single one - which is overridden by background
.
The best solution is using backgroundImage
for the background image and backgroundRepeat
for the repetition since that will not touch other background options which might already exist.
Another solution would be setting background
to url(...) no-repeat
Upvotes: 0
Reputation: 518
Try this:
$("body").css({background : "url(../img/bgr.png)", background-repeat: 'no-repeat'});
Upvotes: 0
Reputation: 543
Maybe you should give backgroundRepeat: 'no-repeat'
a chance.
Upvotes: 1
Reputation: 8768
use css class:
css:
.bg {background:url(../img/bgr.png) no-repeat;}
js:
$('body').addClass('bg');
Upvotes: 0