» in my experience...
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Elsewhere...
·8bit joystick ·a list apart ·amishrobot ·arcadezen ·antipixel ·boxes and arrows ·black belt jones ·curiousLee ·daring fireball ·design interact ·design not found ·everything hurts ·forwarding address: osx ·gridface ·info design ·izzywizzy ·jon madisons ·joshua kaufman ·k10k ·kalsey ·kelake ·kuro5hin ·the lion's web(log) ·louise ferguson ·memepool ·metafilter ·quinn macdonald ·railhead design ·rentzsch ·surfin' safari ·the onion ·winterspeak ·web-graphics ·xblog ·zen haiku Here at IMX
Recent posts...
·Unreal 2 is... uh, not so great. ·Video Game legitimization. ·Random access info architecture. ·Too soon. ·I want my P2P. ·Detecting alphanumeric characters in JavaScript. ·Having some copyright fun with GarageBand. ·Are five minute compositions worth anything? ·Yeah, GarageBand is cool. ·Taking the plunge (again).
Categorically speaking...
·AOL
·Apple and Mac OSX ·Books and Reading ·Business Technology ·Design ·Design Technology ·Effort ·Gaming ·Information Architecture ·Interaction Design ·Internet Consulting ·JavaScript ·O'Reilly Emerging Tech Conference ·Personal ·Photography ·Random ·Software ·U and I ·UI Programming ·Usability ·User Experience ·Web Browsers ·Weblogs and Blogging ·When Bad Things Happen to Good BMW's Memes R' Us
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
What do you think of your firstChild?
[ Posted by Dan on October 03, 2003 | 4 Comments ] I've discovered an inconsistancy and/or a bug in Mozilla's DOM implementation. Consider this simple unassuming HTML table which has it's id set to "ourTable"...
The source of that table isn't anything weird and certainly isn't malformed HTML. Here's what the source of that table looks like... <table border="1" width="50%" cellspacing="1" cellpadding="5" id="ourTable"> <tr id="_Row_1_"> <td id="_Row_1_Cell_1_">_Row_1_Cell_1_</td> <td id="_Row_1_Cell_2_">_Row_1_Cell_2_</td> <td id="_Row_1_Cell_3_">_Row_1_Cell_3_</td> </tr> <tr id="_Row_2_"> <td id="_Row_2_Cell_1_">_Row_2_Cell_1_</td> <td id="_Row_2_Cell_2_">_Row_2_Cell_2_</td> <td id="_Row_2_Cell_3_">_Row_2_Cell_3_</td> </tr> <tr id="_Row_3_"> <td id="_Row_3_Cell_1_">_Row_3_Cell_1_</td> <td id="_Row_3_Cell_2_">_Row_3_Cell_2_</td> <td id="_Row_3_Cell_3_">_Row_3_Cell_3_</td> </tr> </table>Now, using some JavaScript, let's start alerting things so we can see where Mozilla goes wrong (well, it does something different than Safari and Internet Explorer and I think it's incorrect). what we are going to do is alert the firstChild of the first row of the table. We do that in JavaScript by saying... function whatIsThis(item) {And then we call that function and pass in the name of the table we want to interrogate. In Mozilla you will get an alert box that says "[Object TEXT]" where as in Safari and Internet Explorer (I tested on my Win2k box for IE) you get "[Object TD]" and "[Object]" respectively. If you go back up to the source of the table, and look at the firstChild of the first row, you very clearly see that there's a table cell there, and not the text contents of a random container. And for the record, accessing the table row thru getElementById and asking for it's firstChild returns the same result everywhere. "Why is this important?" you ask. Well, if you want to use the DOM tools available to you for tracing around the DOM without knowing the ID's of everything, you can't do that with firstChilsd in Mozilla. That's bad. In my case, in a web application I'm working on, I have some HTML being written by a component in a very standardized way, and using ID's in everything is for more cumbersome than just grabbing the stuff that's in the firstChild of the firstChild of a table row. When we get "[Object TEXT]" back from Mozilla, there are no more firstChild[ren] available to us. "So?" you ask, "why not use the cells[] array to trace into those table cells?" Well, the cell[] array is broken in Safari, and I'm trying to NOT write hopelessly forked (fucked?) JavaScript code for the sake of maintainability and editability by those who are more JavaScript challeneged than I am. IMHO, Mozilla is obviously broken here.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Copyright © 2001 - 2003 by Daniel Kapusta | |||||||||||||||||||||||||||||||||||||||||||||||||||||