So, i know that this has already been answered, but none of the previous answers managed to make my code work. I have a html structure as the following:
<div class="form">
<div class="formrow">
<div class="previewcontainer">
<object id="preview">
<object>
</div>
</div>
</div>
I am trying to set the data attribute to the object like this:
var link = "http://www.someurl.com";
var preview = document.querySelectorAll ("#preview");
preview.setAttribute("data", link);
However, I get an error preview.setAttribute is not a function
preview
is a nodelist – Selfeffacingvar preview = document.querySelector ("#preview");
orvar preview = document.getElementById ("preview");
– Selfeffacing