Get Background-image Src From Div And Set That As An Image's Src
So I'm trying to grab the background-image from a div when it is clicked and set it as the src of an img element somewhere else on the page. The issue is that I'm getting an error
Solution 1:
this should be:
$("#rice-bowl").click(function() {
var bg = $(this).css('background-image');
bg = bg.replace('url(','').replace(')','').replace(/\"/gi, "");
var modalImg = document.getElementById("img01");
modalImg.src = bg;
}
Keep rocking!
Post a Comment for "Get Background-image Src From Div And Set That As An Image's Src"