Categories
Web Development

You want XHTML, you want XML declaration, forget about IE

So I am creating a vigorously XHTML-Strict compliant layout in template we are providing to a client who is very standards minded. A very good thing, really.
When you validate your XHTML using any of the sites dedicated to that, they all want to know it is an XML file and as such, also would love to know what encoding you are using.
To solve the aforementioned issue, a normal person would add the line:

<?xml version="1.0" encoding="UTF-8"?>

If you do that, a lot of your layout in Internet Explorer 6, will be messed up. Font sizes will be ignored, layout will be ugly, and you will start looking and looking, pulling your hair.

Makes sense, right? No.

At least the beast is aware of it.

Share
Categories
Web Development

Positioning dynamically created page elements with DHTML

The problem:

So I am creating a fancy user interface component with XHTML and JavaScript, what is known by the obscenely vague term DHTML. And it is pretty much a dynamic thing – one of the functional components creates <img>elements which it then proceeds to append to the page’s DOM structure. More fun than fancy, the code looks like this:

// create the element
var legendImageElement = document.createElement("img");
legendImageElement.setAttribute('src', "images/dot.gif");
legendImageElement.setAttribute('height', 20);
legendImageElement.setAttribute('width', 1);
legendImageElement.setAttribute("id", "stick1");
legendImageElement.setAttribute("class", "legendLine");
// get a handle on the div under which the element will be placed
var snapStatusDiv = document.getElementById("slider-container");
// append the element to the div
snapStatusDiv.appendChild(legendImageElement);

This all works in Internet Explorer except for the fact that it does not actually apply the class attribute to the newly created element. but when I try to position these newly created elements, Internet Explorer refuses to do so dynamically using a line like


legendImageElement.style.left = 50px;

The only way I can get Internet Explorer to position the element is to set its class attribute, and do that after the element was actually added to the page. There is no visual lag, but setting a class is much less flexible than actually accessing an element’s positioning.
Worse, if I try to output the dynamically-created-element’s position on the page, all that is returned is an empty string.

I have a couple ideas to go around this limit, but in all, it is either pretty lame or that I just need to dig deeper to find an answer.

The solution to this issue was pretty simple but took time to experiment.
First, after you add the element to the page, you need to get a handle of the actual element using the getElementById() method (which also means that the dynamically created element needs to have its id attribute set).
Once you have a reference to the element, you need to define its style in three steps.
1. theElementRef.style.position = "absolute"; // (coould also be "relative")
2. theElementRef.style.left= "50px";
.. and this works!

The complete code again…

var legendImageElement = document.createElement("img");
legendImageElement.setAttribute('src', "images/dot.gif");
legendImageElement.setAttribute('height', 20);
legendImageElement.setAttribute('width', 1);
legendImageElement.setAttribute("id", "stick1");
var snapStatusDiv = document.getElementById("container");
snapStatusDiv.appendChild(legendImageElement);
var theImage = document.getElementById("stick1");
theImage.style.position = "absolute";
theImage.style.left = "50px";
theImage.style.top = "50px";

Share
Categories
Music

Best of 2005

The upside of having a music subscription service is its all you can eat ability. Nevermind the upsides and downsides of the model, you get to listen to almost everything that is out there. In any case, this the music I found I liked the most during 2005.

Guero / Beck
This is such an original, fresh and interesting album. It aims in so many directions, from hip hop to folk and just manages to score on everything. If you did not have a chance to listen to other Beck albums (such as the more mellow ‘Sea Change’), what are you waiting for. Time to worship.

Future Leaders of the World / Lvl Iv
This is the other extreme of everything I wrote about Beck. This album is a masterpiece of derivative work. Nirvana reincarnate for poor people. Still, a very solid album that puts together angst with mostly well executed grunge. Now if the lyrics and the band bios were less irritating. Fun nonetheless.

Interpol / Antics
I got to know Interpol this year, so I include their awesome previous album, “Turn on the bright lights” in making them one of my favorite albums of the year. This Joy Division-inspired band manages to sound like a happier, albeit still dim-lit, version of the original. They sound too vain and appear to enjoy life too much than to do anything as bad as hurt themselves as the original band’s leader did. Their sound is clean, simple and brilliant with dramatic vocals. I like them.

Nine Inch Nails / With Teeth
I forgot this album the first time I posted this entry and I am doing it justice now. When you first listen to this album you think Trent Reznor lost it, but when you give it a second, third, fourth, chance, you get it. ‘With Teeth’ has some great songs, and some not so great songs. Albums like ‘Broken’ happen once in a lifetime probably (unless you are Beck), but Reznor with one armed tied behind his back is better than most of the crap out there.

Music I started listening to in 2005
The Greenhornes
Another blues-inspired band from Ohio (a la the Black Keys), but with a stronger Animals and Beatles influence. If you like Hammond organs and mid-60s rock, the Greenhornes are your band.

Lou Donaldson
With my growing fondness of Jazz comes my first favorite artist, Lou Donaldosn. A great saxophone player with decades of recordings under his belt, I find his albums from the early ’60s especially entertaining. A combination of funky lounge music and be-bop jazz, Lou takes me away when notihing else can.

Share
Share