Retrieveing ALL head elements in document including iframe

Posted by Vishal Shah on Stack Overflow See other posts from Stack Overflow or by Vishal Shah
Published on 2010-04-21T19:12:53Z Indexed on 2010/04/21 19:13 UTC
Read the original article Hit count: 286

Filed under:

I'm trying to add style elements to all ALL the head elements in a document, including those in an iframe.

if i use

var heads = document.getElementsByTagName('head');

It just returns the first head element and not the ones in the iframe. this is the complete code :

var heads = document.getElementsByTagName("head");
var style = document.createElement("style");
style.type = "text/css";
style.appendChild(document.createTextNode(css));
for(var i=0;i<heads.length;i++) heads[i].appendChild(style);

but this doesn't seem to work! am i doing something wrong here...?

© Stack Overflow or respective owner

Related posts about JavaScript