Friday, 1 March 2013

How to create a CSS link element using JavaScript

As you might know, some of the CSS code is no  W3C valid . Even though  Google  has  HTML  and CSS errors in it’s home page it doesn’t mean ... thumbnail 1 summary

As you might know, some of the CSS code is no W3C valid. Even though Google has HTML and CSS errors in it’s home page it doesn’t mean you want them in yours.
If you want the green sticker for your site you can load this invalid CSS in an other file. Then, load this file using JavaScript.
Here’s how to do it:
<script>   
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = '/css/invalid.css';
cssNode.media = 'screen';
document.getElementsByTagName("head")[0].appendChild(cssNode);
</script>

No comments

Post a Comment