Saturday, April 28, 2007
JavaScript & DOM
I just finished reading Jeremy Keith's book on JavaScript and the Document Object Model. Up till now I honestly didn't have a clue what JavaScript was, even though I was using some on the site. Let me tell what prompted me to discover JavaScript.
For some time I had been noticing a strangely named book under Veerle's recommended reading list titled DOM Scripting: Web Design with JavaScript and the Document Object Model. What was this DOM Scripting? Could I use it? For the time I decided that I would wait and see.
During my recent re-design I came across a little bit of a problem. I wanted a three column layout with a white background for the rightmost column. However, since the left column was fluid, I was having a problem getting the white background to extend to the full size of the left content. Some suggested that I just make the backgrounds all the same color so that you couldn't tell the column didn't extend all the way to the bottom, but I didn't want to do that because I wanted a visual separation between the content. I needed a way to find out the height of the left column and apply it to the rightmost column. Enter JavaScript and the Document Object Model.
With a little searching I came across this handy little script that would match my columns in size. With a little cut & paste I was able to get the results I wanted. With that said, I don't really like just adding something to my design without understanding what it's actually doing, so I decided that it was time for me to look closer at this DOM thingy.
In his book Jeremy makes a good argument for using JavaScript to separate behavior from structure, and he details several scripts that would add interesting and dynamic effects to your web site. I didn't understand every script that Jeremy was using but I did come away with the strong feeling that I really needed to investigate JavaScript further.
There is a 'gotcha' to consider when using JavaScript. Although most user will have JavaScript enabled, there is a growing minority that wont. The main problem is that JavaScript has been used to annoy web users by serving up pop-under ads and even worse. As a result more and more users have started disabling JavaScript. It's unfortunate because JavaScript can do a lot of good, and having nefarious companies ruin it for us is really sad. For that reason Jeremy constantly reinforced the idea that any JavaScript that you use on your site should degrade gracefully for those that have JavaScript disabled. Currently 98.47% of visitors to this site have JavaScript enabled, for those that don't the site will still function properly, it just will not look as nice.
Labels: JavaScript
Links



