Setting Background-Image Using Jquery CSS Property

Setting background-image using jQuery CSS property

You probably want this (to make it like a normal CSS background-image declaration):

$('myObject').css('background-image', 'url(' + imageUrl + ')');

Changing background-image with jQuery CSS property is not working

There are two things you need to correct in this line of code:

$('jumbotron').css('background-image', 'url(' + /images/bg_v3.png + ')');

First, the selector $('jumbotron') is not going to select any element. It returns null, hence calling the .css function will cause an error. If your targeting element has ID = 'jumbotron', then the selector should be changed to $('#jumbotron'). If that element has CSS class of .jumbotron, then the selector should be $('.jumbotron').

Secondly, your 'url(' + /images/bg_v3.png + ')' part also causes another error. This should be 'url(/images/bg_v3.png)'.

Set background image in CSS using jquery

Try this:

<div class="rmz-srchbg">
<input type="text" id="globalsearchstr" name="search" value="" class="rmz-txtbox">
<input type="submit" value=" " id="srchbtn" class="rmz-srchico">
<br style="clear:both;">
</div>
<script>
$(function(){
$('#globalsearchstr').on('focus mouseenter', function(){
$(this).parent().css("background", "url(/images/r-srchbg_white.png) no-repeat");
});
});
</script>

jquery not changing css background-image property

You need to remove the semi-colon(;) after declaring the pixels.

 div.css('background', 'url(' + images[i]  + ') no-repeat 0px 0px');

Working example : https://jsfiddle.net/DinoMyte/ez8cgsx7/8/

Jquery Dynamically Replace Background Image

That isn't strange that Chrome set your background-image style unticked, because jquery set background-image as inline style of the element that always has a higher priority than styles from your css file.

Probably, you change old file with a new file, while they have the same name and Chrome don't update background, because he has old file with given name in its cache. You should load file with a new name and reset background-image.

Changing background image using jquery

You need to include the url() part of the background-image property.

$('#full').css('background-image','url(img/1.jpg)');

Jquery change background size AND image src

Setting the background style twice overwrites it, so only the last one will stick, you'll need to use valid CSS properties, like background-image and background-size to change them seperately :

$(".clickableimg").on('click', function() {
var choosenpic = this.id;
$("#image").val(choosenpic);
$("#preview").css({
'background-image' : 'url(backgrounds/'+choosenpic+')',
'background-size' : '50%'
});
});

Can't change background image in body using jQuery

working example just wrap your code inside document.ready funtion