How to set background Jquery methods?

0 like 0 dislike
5 views
Hello tell me how to set the background of the item if the address of the background is stored as a url in a variable?

In the script by clicking on the element in the variable bg is added to the image url... And how this picture now to put a background of a certain element? Is it possible with css method.() ???
$(".link").click(function(){ var bg = $(this).children('img').attr('src'); }
by | 5 views

1 Answer

0 like 0 dislike
Yes it is possible.
Here is real working example:
$('.link').click(function () { var bg = $(this).children('img').attr('src'); $('body').css('background', "url('" + bg + "') no-repeat scroll transparent"); }
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
0 like 0 dislike
5 answers
0 like 0 dislike
1 answer
asked Apr 9, 2019 by ivansimonov1984
110,608 questions
257,186 answers
0 comments
33,932 users