-4

I am trying to set background image of a div for that I am trying

var a = "http://media1.santabanta.com/full2/Indian%20%20Celebrities(F)/Sonam%20Kapoor/sonam-kapoor-40a.jpg";
$("#login-cover").css('background-image', 'url("' + a + '");');

but it is not showing image as background. Console is not showing any error

I tried above here

xrcwrn
  • 5,339
  • 17
  • 68
  • 129

4 Answers4

4

You have a ; at the end of the css value

var a = "http://media1.santabanta.com/full2/Indian%20%20Celebrities(F)/Sonam%20Kapoor/sonam-kapoor-40a.jpg";
$("#login-cover").css('background-image', 'url("' + a + '")');
#login-cover {
  position: absolute;
  background-repeat: no-repeat;
  width: 100%;
  height: 90%;
  top: 0px;
  left: 0px;
  right: 0px;
}
#wrap {
  height: 90%;
  margin: 0 auto 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="wrap">
  <div class="container-fluid" id="login-cover"></div>
</div>
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
3

Just remove ; like below

$("#login-cover").css('background-image', 'url("' + a + '")');

Working Demo

Innodel
  • 1,416
  • 12
  • 16
Manwal
  • 23,450
  • 12
  • 63
  • 93
3

Try this in place of your javascript

var a= "http://media1.santabanta.com/full2/Indian%20%20Celebrities(F)/Sonam%20Kapoor/sonam-kapoor-40a.jpg"; 
$("#login-cover").css('background', 'url("' + a + '")'); // You had an un-needed semi-colon in your 2nd parameter
hightekjonathan
  • 581
  • 1
  • 9
  • 29
1

Try $("#login-cover").css('background-image', 'url("' + a + '")');

Suchit kumar
  • 11,809
  • 3
  • 22
  • 44
Debasish Pothal
  • 387
  • 1
  • 9