Why document.styleSheets[0].href doesn't get updated?

322 Views Asked by At

Why document.styleSheets[0].href doesn't get updated but document.getElementsByTagName('link')[0].href does, when I dynamically create a <base/> tag?

On Opera it works fine, but Firefox and Chrome don't update the value.

Here is the code, you can run it on http://jsfiddle.net/XcDCk/.

If you don't run it on jsfiddle.net you must add a linked stylesheet (<link rel="stylesheet" type="text/css" href="styles.css"/>)

var base = document.createElement('base');
base.href = 'http://google.com/';
document.getElementsByTagName('head')[0].appendChild(base);

var link = document.getElementsByTagName('link')[0];
alert('Link: '+link.href);

var styleSheet = document.styleSheets[0];
alert('Stylesheet: '+styleSheet.href);

var hojaEstilos = document.styleSheets[0];
alert('Stylesheet + ownerNode: '+hojaEstilos.ownerNode.href);

I could get it done (on the third alert) by using the ownerNode attribute (which is actually the link element, so I can get the same result as the first alert), but I can't understand why the second alert doesn't work.

Thank you

0

There are 0 best solutions below