innerHTML will not work in IE, but using the DOM methods it will:
function getValue() { var x=document.getElementById("myHeader") , link = document.createElement('link') , div = document.createElement('div'); x.innerHTML = ''; x.appendChild(link); x.appendChild(div); div.innerHTML = 'abc'; link.href = 'http://test.com/css/template.css'; link.rel = 'stylesheet'; alert(x.innerHTML); }
Although the link indicates that the link tag can only be displayed in the title, itβs interesting enough that the style link works if you use the code I provided in all the browsers I tried (IE, firefox, chrome). See this jsfiddle (where I used real css-href from test.com ;-)
If you want to place the link in this legal section ( <head> ), use:
var header = document.getElementsByTagName('head')[0]; , link = document.createElement('link'); header.appendChild(link); link.href = 'http://test.com/css/template.css'; link.rel = 'stylesheet';
Kooiinc
source share