Change background with image in jquery

Posted by Klbaiju under jQuery on 9/11/2014 | Points: 10 | Views : 680 | Status : [Member] | Replies : 5
Hi ,

I want to change background of image using jquery.

i tried following example

$('img').css("background-image", "url(img/travel.jpg)");


but not working. here image has white back ground .travel.jpg is background of body.is it possible.

Regards

Baiju




Responses

Posted by: Bandi on: 9/11/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
refer
http://www.sitepoint.com/change-css-jquery/
http://stackoverflow.com/questions/20350221/set-background-image-in-css-using-jquery

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naveenhcl on: 9/11/2014 [Member] Starter | Points: 25

Up
0
Down
Hi,

Refer below link for more details
https://forum.jquery.com/topic/changing-background-image-with-animation

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetguy on: 9/11/2014 [Member] Starter | Points: 25

Up
0
Down
Hi
try this
$('img').css("background", "url(img/travel.jpg)");
still if you are unable to get the image then verify the path of the image in the browser console.


Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Klbaiju on: 9/11/2014 [Member] Starter | Points: 25

Up
0
Down
Actually my question is to change the color background of image.
here image is some letters means a name.its background is white.my requirement is to change white with another

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Goud.Kv on: 9/12/2014 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi Baiju,

In that case, you have to use 'background-color' attribute of CSS in your code.

Example,
$('img').css("background-color", "green");


Thanks & Regards,
Krishna

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response