Reputation: 7805
How to apply and getback the background-size using plain javascript?
I tried:
var element = document.createElement('div');
element.style.backgroundPosition = '40px 50px';
console.log(element.style.backgroundPosition);
// logs correct
element.style.backgroundPosition = '40px auto';
console.log(element.style.backgroundPosition);
// logs empty, expected '40px auto'
Upvotes: 0
Views: 102
Reputation: 12864
The property css background-position
not support this syntaxes.
Documentation W3C.org
Maybe the solution is :
element.style.backgroundPosition = '40px 0%';
Upvotes: 1
Reputation: 26160
Unfortunately, background-position doesn't support auto
. I suspect, however, that you are looking for it to center - so what I believe you are looking for is this:
element.style.backgroundPosition = '40px center';
console.log(element.style.backgroundPosition);
// logs "40px center"
Upvotes: 2