title: Changing CSS background dynamically with jQuery
body: <p>I want to change the background image of a fixed div when you hover over another div. I can change other properties but it won't let me override the image URL once set.</p>
  
  <p>I want the product-preview's background-image to change dynamically when hovered over another div.</p>
  
  <p>I tried combining multiple methods like hover, mouseenter+mouseleave and I also tried different css properties like background and background-image</p>
  
  
  
  <p><strong>Javascript</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>jQuery( document ).ready( function() {
  
      //check for init
      window.alert("jQuery succesful");
  
  
      //basic
  
      //Poke Rice
      $("label.form-check-label[for=poke_rijst]").hover(function() {
          jQuery( ".product-preview" ).show();
          //afbeeldings URL
          var url = "http://i64.tinypic.com/ie12f9.jpg";
          jQuery(".product-preview").css("background-image",url);
      });
  
      //Poke Salad
      $("label.form-check-label[for=poke_salad]").hover(function() {
          jQuery( ".product-preview" ).show();
          //afbeeldings URL
          var url2 = "http://i65.tinypic.com/2zyv7dc.jpg";
          jQuery(".product-preview").css("background-image", url2);
      });
  
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.product-preview {
    display: none;
    color: white;
    position: fixed;
    width: 120px;
    height: 120px;
    top: 230px;
    padding: 10px;
    right: 0;
  background-image: url("http://i64.tinypic.com/ie12f9.jpg");
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="product-preview"&gt;&lt;/div&gt;
  &lt;label class="form-check-label" for="poke_rijst"&gt;&lt;input type="radio" id="poke_rijst" name="ppom[fields][basis]" class="ppom-check-input" value="Poke Rijst" data-price="" data-optionid="poke_rijst" data-label="Poke Rijst" data-title="BASIS" data-onetime="" data-taxable="" data-without_tax="" data-data_name="basis"&gt; &lt;span class="ppom-label-radio"&gt;Poke Rijst&lt;/span&gt;&lt;/label&gt;
  
  &lt;label class="form-check-label" for="poke_salad"&gt;&lt;input type="radio" id="poke_salad" name="ppom[fields][basis]" class="ppom-check-input" value="Poke Salad" data-price="" data-optionid="poke_salad" data-label="Poke Salad" data-title="BASIS" data-onetime="" data-taxable="" data-without_tax="" data-data_name="basis"&gt; &lt;span class="ppom-label-radio"&gt;Poke Salad&lt;/span&gt;&lt;/label&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>It works whenever no background-image is set yet. As soon as one of the functions placed a background-image, the other function will not override it. It does work when I set background-image, "none" on the second function.</p>
  
  <p>Thanks in advance, I'm stil learning jQuery.</p>
  
  <p>Here is a JDFiddle:</p>
  
  <p><a href="https://jsfiddle.net/buyfcr6q/" rel="nofollow noreferrer">https://jsfiddle.net/buyfcr6q/</a></p>