i am having an issue appending a script to the head in ie7/8

this is the code i am using

var requireTag = document.createElement('script');
requireTag.setAttribute('type',         'text/javascript');
requireTag.setAttribute('src',          link+ 'require.js');
requireTag.setAttribute('data-main',    link+ 'data');

document.head.appendChild(requireTag);

this is the error i get

SCRIPT5007: Unable to get value of the property
'appendChild': object is null or undefined  

I found this createElement error in IE8 and tried updating my code to have

var appendChild = document.head.appendChild(requireTag);

but still get the same error. Can anyone help?

Edit
Report