How to set the background-image according to the dynamic content .
My html code like below
<div class="main-div">
     <div class="content-div">
     </div>
</div>
How to set the background-image according to the dynamic content .
My html code like below
<div class="main-div">
     <div class="content-div">
     </div>
</div>
 
    
    $(document).ready(function() {
  var imageUrl = 'https://www.stoneycreekhunting.co.nz/2_Key_Features_Rainwear_Insulation.png';
  $("<div class='dynamic-element'/>", {
    text: ""
  }).appendTo(".content-div");
  $('.dynamic-element').css({
    'background-image': 'url('+imageUrl+')',
    'background-size': 'cover',
    'height': '100%'
  });
});.content-div {
  height: 100%;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="width:120px;height:120px;" class="main-div">
  <div class="content-div">
  </div>
</div>