David
David

Reputation: 4518

writing source of image in variable and using that variable when changing css in jquery

Simple code that works

 $(this).css({'background-image':'url(images/icons/accept.png)'});

And now the code that doesn't work

kkk='images/icons/accept.png';
$(this).css({'background-image':'url(kkk)'});

What do I do wrong ?

Upvotes: 1

Views: 72

Answers (1)

Guffa
Guffa

Reputation: 700840

You can't use a variable name inside a string. Concatenate the strings:

kkk='images/icons/accept.png';
$(this).css({'background-image':'url(' + kkk + ')'});

Upvotes: 1

Related Questions