I cannot understand how backgroundImage works

I don’t understand why backgroundImage wouldn’t work in this scenario. Now there are 2 errors in Inspect Element which I don’t understand which it means EXACTLY. Besides, these errors do not appear on my website. Could someone lean me hand (or even an arm) on this please?

You have a missing quote mark at the end.

document.getElementById("imgry").style.backgroundImage = "url('" + data +"')";

1 Like

Welcome to webdevelopment. Where one forgotten quote mark, gives you two errors and an hour wasted.

Thanks.

Wait a sec. My website DOES have quote mark at the end, wait a sec until I strip the code to the requiremental only.

1 Like

Here. I don’t know, I haven’t done pure JavaScript, ever :smiley: and it fails miserably.

You still got this the same line wrong :smile:

This is how it should look.

document.getElementById("theqrcode").style.backgroundImage = "url('" + data + "')";

I gave you the correct code in the previous post but you have added another semi colon into the mix.

You haven’t assigned ‘data’ to a variable. var data =" etc…

You need jquery for the $ function.

You still got this the same line wrong :smile:
Kappa. :smiley:

This is how it should look.
document.getElementById("theqrcode").style.backgroundImage = "url('" + data + "')";
Replacing it doesn’t seem to work ;(

I gave you the correct code in the previous post but you have added another semi colon into the mix.
Is it elaboration on current code, or pointing to the answer? I can’t understand.

You haven’t assigned ‘data’ to a variable. var data =" etc…
I have alerted it on my website, it is, set. It’s the same code as the one in example. Alerting it, prints to string shown in example.

You need jquery for the $ function.
I have jQuery 2, I guess that’ll how to do :smile:

Could you tell me more about the issue? xD

It says that there’s improper ). But I don’t see any that should’ve been escaped that isn’t, and normally these things are obvious :frowning:

It’s not about data variable or anything. It doesn’t work at all, and I don’t know why. It says there’s mismatch but as I love my life, I cannot see it!

I wonder how many people went screaming through their computers to tell me how stupid I am. The bug was not on JavaScript but on CSS surface.

From
document.getElementById("theqrcode").style.backgroundImage = "url('123.jpg');";
to document.getElementById("theqrcode").style.backgroundImage = "url('123.jpg')";

Yes it would if you made all the other changes I suggested.:slight_smile:

This is still wrong.

"url('123.jpg');";

You seem to have reintroduced the same semi colon typo that I already pointed out and corrected!

Here’s the working code:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
.qrcode {
  background-color: #000;
}

#theqrcode {
  background-color: rgba(0, 0, 0, 0.3);
  background-repeat: no-repeat;
  background-size: contain;
  height: 100px;
  width: 100px; 
}
</style>
</head>

<body>
<div id="qrcodeShower">
  <div id="theqrcode"> X </div>
  <span>click anywhere to close</span> </div>
<a href="#" class="qrcode">Code</a> 
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
var data = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAAAAACIM/FCAAAQJUlEQVR42u2dT2gV1xfHX9KYR4WEmGoC0i50IdikScDiroSuSvt+T61QN0XoQlfG92JEQUg3DQQUo3lNV3UhSDcWtCbG0pWE7kQhSY2BLuyiRTTaGAy0JKZJftx7pOf0nHvP3Jk8bZrMXQ333bkzn2Tm/jnfc85kltdIyaQgKUgKEgDycCis3MITF0ci2901h8PP8Jz79seHWAHXve++tVuBN/WQgAxmwkoeLzPXEtmuYA6rx/CcfvvjIFbAdfvdIPnAmxokIEMJQFoj2xXNYVaADGHFUDlAhlKQdQfSYQ4rR/GcAQ4ybCtK5Qb5uN9femoUkHbbpJmDjJjagSfm8MHxYrFYbMcLz3abilP2xM/N4fEH2O4qgtT0KDf1sQfkK2WYnmlUQLpszV7nfw7KKP8LPqozhzkc3TKj2O4IgjTOKDf1lQekXznnkQZS5I+CABnLcpBG57sE7Uh/jY+Um+pPQf5TIPNzrCy6Qd7N/l2Ou0EWsI87NaZdFV546i1Tsc/+2GkOa8ZN9XgN6w9AFvk9zUeDzH/SysqIE2Tp57G/ywM3yGns4393TLuTeOGFCVNx0f54xhyO/2mq/xxn/QHICL+nT+YjQeaanWsZAaKO+9DuKFa8s2AqvuTzyPXIeQRAxFqweS4apNU54SQBKWJF61zCmR1AxITdmoIEgOzBU/aQiU48CsPxH62XBPIAX04oT+wr307WLLbihPvlLOEoQV52Wh68IpDjOFy+WAzaQbgST6m0Fefdw+UGHLfJ8EvL8VcE4lmei9LvnsAyyrskJtgUZF2BHDGHFRN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9agGwSSSNAy4gSBlxiSTZCX3eMsA3HqZ9wffyD55UWcunjZZRnxbHXnuV/RonuPfRvTf5Dh1+O+BHHqne7PcZD88iJOXQy/siwm3rOHfjMhNBhAdSgLvL8UZFWDfKW0m+HfZ5efYRJusH0cpMAd1PJapI5weOsLBfm43196ajL//D67/DDWBUwAtp0nCoPEY5/zRGEC5MkA5oPvxav3Yn+0xEwUFu2jTsq0O5FkmzDQuQ1+o5XO/1zOfbGA1G2JQdTlfmhoUpJ3KQVZnSCD5QNpcJpWaUrRQWc7GsJUiAVC11oiKaun3IoEmfuBtQNjN8S930ejuGgHBYLKSJJX9bqkv0SeD6uypCApSAqil/8D0EL+JD7rq2wAAAAASUVORK5CYII=";	
	$("a.qrcode").click(function () {
		$("div#qrcodeShower").fadeIn();
		document.getElementById("theqrcode").style.backgroundImage = "url('" + data + "')";
	});	
</script>
</body>
</html>

Note that your fade-in routine will do nothing because the element is already visible and your fiddle has unwanted mis-matched bracket section right at the end.

});

1 Like

You seem to have reintroduced the same semi colon typo that I already pointed out and corrected!
Yes, if you could note, I already found it out. :smiley: (note edit date on my post and date of your post)

Thank you Sir :smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.