23 June 2003
‘I don’t know JavaScript that well, but I’m sure it’s a very nice language once you get to know it.’
‘It’s not JavaScript, it’s me.’
‘Things didn’t work out between us, y’know? I think they might have, but not there and not then.’
All I wanted to do was copy someone else’s script and modify it to my own purposes. Script being Simon Willison’s blockquote citations, my own purposes being better use of the ins and del elements. The plan was to find each instance of each element on a page, check to see if one of its parents was a block-level element (defined for this as p, li, dt, dd, or pre), and if it wasn’t, show the update time (datetime) and a link for the reason (cite).
All this, like the cite attribute of blockquote, is already in HTML, but browsers don’t seem to care, preferring to ignore it instead. Some used CSS to get around this; others used the DOM instead. Because I wanted to deal with elements and not just :content pseudo-selectors, I took the JavaScript/DOM road.
Things went well at first. Just a few silly syntax errors stopped things working in Firebird, thanks to its JavaScript console. Then I tried putting that code on the same page as the blockquote citations code, because it would be silly to just do one or the other. No luck, so I switched back and all worked well.
When I tried it in IE it threw a script error. Because the script was in a separate file I had a bit of trouble working out what line it meant (most of the methods I tried showed a blank line), so I scooped it all into one local file. And this was what IE choked on:
parent = element.parentNode;
The hell? I looked up a chart, which I’m too lazy to link to, and it said that IE supported the parentNode property. This was the beginning of the end, although I didn’t know it at the time.
Let’s try in Opera. Nope, won’t let me create an element, with or without a namespace.
So I went back to Firebird, having not changed a thing. The plan at this point was to be really elitist and just say
‘it still works in your sucky browser, right, loser?’
But suddenly the citations don’t actually link, just show the URL in the title attribute. When I removed the calls to deal with elements other than blockquote, all worked well. I still can’t figure out what I did wrong, so I’m throwing in the towel. The heat and humidity (one of the most common phrases used in the build-up to the last World Cup) have taken their toll.