Web Development is extremely quirky. (Notes from a 22 Hour Programming Session)

Monday, January 4, 2010 , Posted by Johnny Fuery at 1:37 AM

Originally Published 2008-01-15 21:25:33

No, seriously. I know it's somewhat rhetorical, but I'm a little punchy right now. Once you're in your language of choice, you can count on certain consistencies, but when you're developing UI for the web using any of the buzzwords (DOM, DHTML, CSS, Javascript, AJAX), you're going to get inconsistencies all around.Example 1: Search on the internet for solutions on how to dynamically add options to a select list across both IE and Firefox, and you'll find all kinds of esoteric remarks about DOM versioning and such.

Screw the "HTMLSelectElement object". Whatever that is. ;-) Just append a text child and set the appropriate attribute.

This works in both IE and Firefox:


myOpt = document.createElement('option')myOpt.appendChild(document.createTextNode('hello');myOpt.setAttribute('value', 'hello was the choice');


As for these methods, don't bother. Firefox likes this one:

myOpt.value = 'hello was the choice, too bad IE users cannot see it';myOpt.text  = 'hello Firefox users only';


...and Internet Explorer can deal with (this is the #1 Google hit, by the way! Dammit.):

document.forms['testform'].testselect.options[i] = new Option('new text','but Firefox cannot see it!');


While I'm recording notes from hours of browser battles, here's how to get around the limitations (features?) of innerHTML and get to just the text:

element.firstChild.nodeValue


...works in both browsers.

If you have only one child object there, of course, if you don't, we'll, you'll just have to actually program. As for the other variations that are not cross-browser compatible:

element.textContent


...works in Firefox. not IE. And

element.innerText


...works in Internet Explorer. Not FF.

Comments

On 2008-01-27 01:52:42 Online Bingo said:
22 hours seems pretty long right?

i've been in such a situation, programming for the entire day up to next morning

it's like living in hell

On 2009-02-12 14:35:28 Tk said:
I've gone on 48 hour coding binges. When you're trying to fix something you really can't step away or you'll never fix it.

Currently have 0 comments:

Leave a Reply

Post a Comment