S
S
sokol11112020-04-27 17:58:54
JavaScript
sokol1111, 2020-04-27 17:58:54

How to correctly insert a variable in css?

Good day.
There is this code:

$('.color-box-yellow').click(function(){
    $('.center-bg__box').css('background-image','url("img/shape_2.png")');
});


How to put a variable in 'url("img/shape_2.png")' instead of an image, like ${background}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maralov, 2020-04-27
@sokol1111

let bg = 'shape_2.png';
$('.color-box-yellow').click(function(){
$('.center-bg__box').css('background-image', `url("img/${bg}")` ) ;
});
where the url is, put back quotes instead of single ones

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question