There's a typo on the getElementById
method, and the string you are building is not in quotes. I've roughly quoted the string you've provided, but it will likely need extra attention where your ...
code is.
var code = "<ins class=\"adsbygoogle\"" +
"style=\"display:block;width:300px;height:600px;margin-bottom: 20px;\"" +
"data-ad-client=\"...\"" +
"data-ad-slot=\"...\"></ins>" +
"<script>" +
"(adsbygoogle = window.adsbygoogle || []).push({});" +
"</script>";
document.getElementById("rightAdScroll").append(code);
// ^^ was missing "Id"
This will only work though if you have an append
method on your DOM element. append
is a jQuery method but it doesn't appear that you are using it directly in this case.
I'd recommend either making 2 calls to:
var myElem = document.getElementById("rightAdScroll");
myElem.appendChild(insTag);
myElem.appendChild(scriptTag);
or use jQuery (if you have it loaded already):
$('#rightAdScroll').append(code)
document.getElementById("rightAdScroll").append(code);