How to load a css file with Java Script - Eg Net Solution

Here in this sites web and software developer can get some essential information.

MY Favorite .Net Question For Interview

This are not tidy. Just for rough. In Sha Allah will make it tiddy soon. 1.  DateTime2 Date range 0001-01-01 through 9999-12-31  vs Date...

Users Countries


Saturday, June 28, 2014

How to load a css file with Java Script

I search this here and there in net. Also found many. But most of them were not working.Soo for making this thing easy now I am here.I made it by getting help from many sites. The code for how to load a css file by java script is given below.Just add the code in your header tag.And also make a style.css file in the same directory of the html file.

<script type="text/javascript">
var callbackFunc = function(){
//alert("Yes It worked");
};


var head = document.getElementsByTagName( "head" )[0];
var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");


fileref.setAttribute("href", "style.css");
fileref.onload = callbackFunc();
head.insertBefore( fileref, head.firstChild );

</script>

No comments:

Add Choice