0

I have a problem and don't know the solution. Here is my HTML

<div id="thumb">
</div>

CSS:

#thumb {
  width: 100%;
  position: relative;
  height: 557px;
  background-image: linear-gradient(
      rgba(252, 191, 73, 0.3),
      rgba(252, 191, 73, 0.3)
    ),
    url("../img/thumb.jpg");
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  text-align: center;
  color: #000;
}

JS:

var sliderGet = document.getElementById("thumb").style.backgroundImage;
  sliderGet = 'url("../img/thumb2.jpg")';

There is no way to change to thumb2.jpg using js...

4
  • 3
    try document.getElementById("thumb").style.backgroundImage = 'url("../img/thumb2.jpg")' Commented Feb 5, 2020 at 0:39
  • Imagine you did var x = 3; x = 5;. Would you expect 3 to change? Commented Feb 5, 2020 at 0:42
  • Not knowing how to do something <> not being possible to do. Commented Feb 5, 2020 at 0:44
  • you might want to try this $('#thumb').css('background-image', 'url("../img/thumb2.jpg")'); .. you can put this on onCLick Commented Feb 5, 2020 at 0:49

2 Answers 2

1

You can try this

document.getElementById("thumb").style.backgroundImage = 'url("../img/thumb2.jpg")'

Sign up to request clarification or add additional context in comments.

Comments

0

You need to change it directly.

document.getElementById("thumb").style.backgroundImage = 'url("../img/thumb2.jpg")'

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.