I'm trying to write a short javascript function to add buttons for prev/next to a css-slider I've put together.
I don't have access to the DOM, so figured I'd just insert the div's via javascript. Here is the function:
function createfn(){
var element = document.createElement("div");
var prev = document.createTextNode("<");
element.appendChild(prev);
document.getElementsByClassName("sqs-gallery")[0].appendChild(element);
}
window.onload=createfn();
I am getting an error:
"Cannot read property 'appendChild' of undefined"
The div container with class .sqs-gallery is definitely appearing on the page. I was questioning whether this was somehow running before the DOM fully loaded, but I have the window.onload in there which (I believe) should wait until everything is loaded before running the function.
Any and all thoughts and help is greatly appreciated!
sqs-galleryisset?window.onload=createfn()