1

How can I change not only background image but also set additional properties?

Meaning, I have this code, that works fine:

document.getElementById(id).style.backgroundImage = "url('image.png')";

But this fails:

document.getElementById(id).style.backgroundImage = "url('image.png') no-repeat center center";

How can I add the additional properties to it?

Thanks in advance.

2

2 Answers 2

3

the additional properties are part of a short cut in CSS, which are applied using the background property so your js should be

document.getElementById(id).style.background = "url('image.png') no-repeat center center";
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, I new there was some short change needed to get it working right.
2

document.getElementById("div3").style.backgroundPosition = "20% 50%"; - for position

document.getElementById("div3").style.backgroundRepeat = "repeat-y"; - for repeat

This will work for you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.