I'm trying to add a JustGiving widget to my website but it doesn't display at all. I had other scripts in the file which I thought might be interfering so I ended up testing in a new plain html file and it still wouldn't work.
Interestingly enough if I copy/paste it into a W3 schools code editor it works! It's the same exact code and I cannot work out why it doesn't load in an html file.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="jg-charity-events-board" data-config="id=45107">123</div>
<script>
(function(d) {
var jg = d.createElement('script');
jg.type = 'text/javascript';
jg.async = true;
jg.src = (d.location.protocol == 'https:' ? 'https://widgets.justgiving.com/charity-events-board/host.js' : 'http://widgets.justgiving.com/charity-events-board/host.js');
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(jg, s);
})(document);
</script>
</body>
</html>
<script>tag which contains the code above would be selected, no?<!DOCTYPE html> <html> <body> <script> var s = document.getElementsByTagName('script')[0]; console.log(s); </script> </body> </html>into it. Open it in the browser and check the console. You'll see it logs the script tag. JS code can't be executed unless it's in the DOM