shireef khatab shireef khatab - 10 months ago 74
Javascript Question

Can't change background-image of a div

I'm trying to change background-image of a div #image by hovering on thumbnail images (something like a simple slider)
My plunker is provided below.

1- First I tried to do like:
but i got this in the console:
Using .style.backgroundImage

2- Then i tried something like element.backgroundImage
although it looks good in the console but didnt work, here is the console:
Without .style

Note: I don't want to use any library, just want to study JavaScript core.

my plunker

Answer Source

The issue is in the way you are changing the background image:

image.backgroundImage= bgI_value;

What it should be is: bgI_value;

Note that this here is correct:

var bgI_value = 'url('+ src + ')';

Here is the Plunker: