Thursday 7 June 2007

Web Views using Ajax part 2 (CSS)

CSS
I realised early on that I would have some CSS content to load, however I did want to reduce the amount of things a developer would have to do add to a form or page to get this to work. So the CSS would have to be loaded by the javascript, but how to do this?

Simple, create the CSS Link statement as a DOM object

var lnk = document.createElement('link');
lnk.setAttribute('rel', 'stylesheet');
lnk.setAttribute('type', 'text/css');
lnk.setAttribute('href', 'mycss1.css');

and then use

document.getElementsByTagName('head')[0].appendChild(lnk)

to add the CSS file into the header section of the current document.

I had a fiddle with this method and it works!!!
I can programatically load a CSS file to style my views and have it change the view to the
correct style as needed.

More Later

1 comment:

Patrick Kwinten said...

hej!

why dont you use divshare to upload and distribute your example applications?

Disqus for Domi-No-Yes-Maybe