473,659 Members | 2,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Firefox inserts text nodes in TR elements?


Why does Firefox insert #text nodes as children of TR elements?

As a work-around for older Safari versions not properly supporting a
table row's cells collection, I used the row's childNodes collection as
it was pretty much exactly the same thing. However, in Firefox 1.0.7
text nodes are inserted between the TDs. I'm certain that this didn't
use to happen with older versions.

The HTML specification states that the only element that can be the
child of a TR is a TD, so why does Firefox put text nodes in there?

If this how the DOM is supposed to be built, can someone give me a
reference to where it states that? Or should this be reported as a
Firefox bug?

--
Rob
Sep 23 '05 #1
2 3206
ASM
RobG a écrit :

Why does Firefox insert #text nodes as children of TR elements?
I would be glad to see your example (url?)
for my
- own tests
- own knowledge
As a work-around for older Safari versions not properly supporting a
table row's cells collection, I used the row's childNodes collection as
it was pretty much exactly the same thing. However, in Firefox 1.0.7
text nodes are inserted between the TDs. I'm certain that this didn't
use to happen with older versions.

The HTML specification states that the only element that can be the
child of a TR is a TD, so why does Firefox put text nodes in there?
As I know you didn't do errors, strange it is
If this how the DOM is supposed to be built, can someone give me a
reference to where it states that? Or should this be reported as a
Firefox bug?


--
Stephane Moriaux et son [moins] vieux Mac
Sep 23 '05 #2

RobG wrote:
Why does Firefox insert #text nodes as children of TR elements?
Because they are in the source e.g. if you have
<tr><td>Kibo</td></tr>
then there are no white space text nodes as child nodes of the <tr>
element but as people usually author
<tr>
<td>Kibo</td>
</tr>
if you build a (normalized) DOM then the first child of the <tr> element
is a text node with white space, the second the <td> element, and the
third a text node with white space.
However, in Firefox 1.0.7
text nodes are inserted between the TDs. I'm certain that this didn't
use to happen with older versions.
I rather doubt that, I don't think such behaviour has changed between
1.0.x releases. I haven't tested now but I don't think the beahvior is
much different in earlier Mozilla releases.

The HTML specification states that the only element that can be the
child of a TR is a TD, so why does Firefox put text nodes in there?
Well the browser's tag soup parser does not look at a DTD so even if you
author your HTML to a HTML 4.01 DTD and declare that at the beginning of
the document the browser does not check whether your markup complies
with that DTD and throws out stuff that is not supposed to be in there
when building a DOM.
If this how the DOM is supposed to be built, can someone give me a
reference to where it states that?


White space and whether it or when it should occur in the DOM tree is an
underspecified issue I think, anyone picturing the tree usually ignores
that.
The current W3C DOM FAQ has this entry
<http://www.w3.org/DOM/faq.html#emptyt ext> on the issue:

"In XML, all whitespace has to be passed through to the application.
This means that if you have whitespace, such as carriage returns,
between tags in your source file, these have to be passed through, even
if they're just there for pretty-printing. The DOM implementation has to
put this whitespace somewhere, and the only possibility is a text node.
Thus you will get text nodes which look empty, but in fact have a
carriage return or other whitespace in them."

But then it adds: "Note that some DOM implementations , which do not
consider whitespace in element content to be meaningful for the XML
languages they support, discard these whitespace nodes before exposing
the DOM to their users."

So that FAQ acknowledges that implementations differ and that means you
have to deal with the differences if you write code against the
different implementations .
The latest core DOM Level 3 in its introduction pictures an example tree
for a table in
<http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/introduction.ht ml>
and does not show white space text nodes but mentions in the text before
the graphics:
"A graphical representation of the DOM of the example table, with
whitespaces in element content (often abusively called "ignorable
whitespace") removed"
In the end if you script against different implementations then my
experience is that if you walk childNodes or use firstChild or lastChild
then you should never expect a certain type of node (e.g. an element
node) at a particular position as what is an element node in one
implementation might be a text node in another. Checking nodeType and
then dealing with the type found is a safer way.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2874
by: Jürgen Holly | last post by:
Hi! I have the following xml-node: <docu> <p>Sample: <b>bold</b></p> <p>and text in <i>italic</i></p> </docu> I need to create a text-file, so I set the output-mode to text.
8
1529
by: Xamle Eng | last post by:
One of the things I find most unnatural about most XML APIs is that they try to abstract both elements and text into some kind of "node" object when they have virtually nothing in common. The reason these APIs do it is to make it possible for both text and elements to be children of elements. But there is another way. The XPath/XQuery data model does not allow two consecutive text nodes. As far as I can tell, most XML processing...
5
13156
by: hibernate | last post by:
I'm somewhat new to javascript/DHTML, and this problem has been plaguing me. I have made an 'array' of <div> tags within my html document like so: <div id="menu"> menu1 </div> <div id="menu"> menu2 </div> <div id="menu"> menu3 </div> <div id="menu"> menu4 </div> <span onclick="showOrHide('menu')"> show/hide menu1 </span>
4
8631
by: Michael Schuerig | last post by:
I'm trying to change the options of a select element by setting its innerHTML. Here's a demo case: <html> <head> <script language="javascript" type="text/javascript"> function addOpts() { var s = document.getElementById("s"); s.innerHTML = '<option>Opt1</option><option>Opt2</option>'; }
4
2228
by: jarek | last post by:
Hi, this is my code: CSSStyleDeclaration.prototype.__defineSetter__('display', displaySetter); function displaySetter(value) { var parent = findParent(document, this); if (parent) {
1
2460
by: KPS | last post by:
I'm attempting to create a simple treeview-like behavior in JavaScript. The desired behavior happens in IE but I cannot get the same to happen in FireFox. The primary thing I want to accomplish is to set the id and href of some objects dynamically during the onload of the page instead of hard-coding it in the HTML. I want to set the id/href so when I add new entries I don't have to remember to increment the id's. In FireFox, the href...
3
2288
by: robert.oschler | last post by:
I have an AJAX driven page where I dynamically add rows to a known table on the page, based on the return document from the AJAX call, using DOM node methods (except for a small snippet of code, see below) .. The code I use to do that is shown below. The code runs fine in FireFox. I can see the newly created table rows and everything looks fine on the page. In Internet Explorer, I don't see any changes to the page after the new nodes...
7
5425
by: Thierry Lam | last post by:
I have the follownig codes: <html> <head> <title>Simple doc</title> </head> <body> <script type="text/javascript"> function greet() {
4
5357
by: Patrick Nolan | last post by:
I am using javascript to manipulate optgroups in select elements. When the results are displayed in Firefox 2.0 there is an annoying blank line at the top of the multi-line select box. This doesn't happen with IE7. There's a little program below which illustrates the problem. I create two multi-line select boxes. The first one has an optgroup and an option specified in the HTML. That one displays with "opt1" as the first line. The...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.