This has advantages over using document.write, which will only work during the time the page is loading.
To add css, use the following code:
var cssNode = document.createElement('link');
var scriptNode = document.createElement('script');
Yes it is a little weird that sometimes you use setAttribute and sometimes you set the attributes using properties. The different browsers like different combinations of these two ways of setting attribute values, and the above combinations work in IE, firefox and Opera.