help with DOM and IE

T

The alMIGHTY N

I can't figure out why the function below isn't doing anything in IE 6.
I pass the id of a table as the "which" variable. When I activate the
function, nothing happens. It doesn't return any errors.

This works perfectly fine in Firefox - a new table row appears with a
table cell containing the text "Hi there".

Can anyone give some advice on this?

Thanks!

N


function ieTest(which) {
var objTmp1 = document.createElement("td");
objTmp1.appendChild(document.createTextNode("Hi there"));
objTmp1.setAttribute("colspan",5);
var objTmp2 = document.createElement("tr");
objTmp2.appendChild(objTmp1);
document.getElementById(which).appendChild(objTmp2);
window.alert(document.getElementById(which).getAttribute("cellpadding"))
}
 
I

Ian Collins

The said:
I can't figure out why the function below isn't doing anything in IE 6.
I pass the id of a table as the "which" variable. When I activate the
function, nothing happens. It doesn't return any errors.

This works perfectly fine in Firefox - a new table row appears with a
table cell containing the text "Hi there".

Can anyone give some advice on this?

Thanks!

N


function ieTest(which) {
var objTmp1 = document.createElement("td");
objTmp1.appendChild(document.createTextNode("Hi there"));
objTmp1.setAttribute("colspan",5);
var objTmp2 = document.createElement("tr");
objTmp2.appendChild(objTmp1);
document.getElementById(which).appendChild(objTmp2);
window.alert(document.getElementById(which).getAttribute("cellpadding"))
}
Use insertRow(-1) and insertCell(-1) to create and add the row and cell.

var row = document.getElementById(which).insertRow(-1);
var cell = row.insertCell(-1);
.....
 
R

Randy Webb

The alMIGHTY N said the following on 5/1/2006 4:39 AM:
I can't figure out why the function below isn't doing anything in IE 6.
I pass the id of a table as the "which" variable. When I activate the
function, nothing happens. It doesn't return any errors.

This works perfectly fine in Firefox - a new table row appears with a
table cell containing the text "Hi there".

In this case, Firefox is actually getting it wrong.
Can anyone give some advice on this?

Thanks!

N


function ieTest(which) {
var objTmp1 = document.createElement("td");
objTmp1.appendChild(document.createTextNode("Hi there"));
objTmp1.setAttribute("colspan",5);

Don't use setAttribute with IE, it is known to be buggy.

objTmp1.colspan = "5";
var objTmp2 = document.createElement("tr");
objTmp2.appendChild(objTmp1);
document.getElementById(which).appendChild(objTmp2);

You can't appendChild to the Table element in IE, you have to append it
to a TBODY. In that regards, Mozilla based browsers get it wrong.
window.alert(document.getElementById(which).getAttribute("cellpadding"))

You can access the attributes directly also:

alert(document.getElementById(which).cellpadding);
 
T

The alMIGHTY N

Great thanks! I'm surprised that Firefox would have gotten something
wrong... of course, I probably should have tested with IE a lot
earlier.

Thanks again!
 
T

The alMIGHTY N

Thanks a lot for your suggestions and help. I'm quite surprised that
Firefox would have gotten something wrong. I'm also quite surprised
that O'Reilly would have gotten something wrong - I learned all about
getAttribute, setAttribute, etc. from their AJAX book.

Oh well.

You learn something new everyday. Thanks again!
 
J

Jim Ley

Thanks a lot for your suggestions and help. I'm quite surprised that
Firefox would have gotten something wrong.

What it gets wrong is that it treats all documents as if they could be
XHTML, the requirement for a TBODY doesn't exist in XHTML, so
therefore it is valid if you have an XHTML document.

Jim.
 
R

Randy Webb

Jim Ley said the following on 5/1/2006 11:15 AM:
What it gets wrong is that it treats all documents as if they could be
XHTML, the requirement for a TBODY doesn't exist in XHTML, so
therefore it is valid if you have an XHTML document.

Is there a URL anywhere that documents that? I don't doubt you at all,
just curious/wanting a URL reference for the future.
 
I

Ian Collins

Randy said:
Jim Ley said the following on 5/1/2006 11:15 AM:



Is there a URL anywhere that documents that? I don't doubt you at all,
just curious/wanting a URL reference for the future.
http://www.w3.org/TR/xhtml1/

The element is described as optional in C.11.2 (which explains why) and
C.13.2.
 
R

Randy Webb

Ian Collins said the following on 5/1/2006 9:13 PM:
http://www.w3.org/TR/xhtml1/

The element is described as optional in C.11.2 (which explains why) and
C.13.2.

I wasn't wanting a URL to TBody being optional, I was wondering if there
was a URL reference that shows Mozilla treating all documents as if they
could be XHTML and thus getting the TBODY wrong. Or, if the behavior is
just observed behavior and a guess at the explanation.
 
J

Jim Ley

I wasn't wanting a URL to TBody being optional, I was wondering if there
was a URL reference that shows Mozilla treating all documents as if they
could be XHTML and thus getting the TBODY wrong. Or, if the behavior is
just observed behavior and a guess at the explanation.

In that they only have a single document mode, so need to support both
xhtml and html. so I guess you'd say it was observed behaviour.

Jim.
 
V

VK

Randy said:
I was wondering if there
was a URL reference that shows Mozilla treating all documents as if they
could be XHTML and thus getting the TBODY wrong. Or, if the behavior is
just observed behavior and a guess at the explanation.

It is a shifty term "treating" :) If you mean "trying to render it"
then FF behavior is the same as for all other UA's willing to be in use
(and not W3C demos). If document is served as text/html, FF will render
it somehow anyhow.

Obviously it doesn't connect every time to w3.org to get a DTD, it uses
a build one. That would be another aspect of your question: what DTD/
tag database is build in into FF? Only one so far: XHTML 1.0 The only
namespace for HTML Firefox knows about is
xmlns:html="http://www.w3.org/1999/xhtml"
But what decision will it make based on this table - it depends
completely on the Content-Type. Say absolutely the same content with
Content-Type text/html will go through or get adjusted, but with
application/xhtml+xml will lead to a parsing error.

And if anyone curious: the build in DTD of IE6 is
<http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd> This is the
only one it's aware of and the only one it uses. Respectively the only
type of documents existing in IE is <!DOCTYPE HTML PUBLIC "-//W3C//DTD
HTML 4.01 Transitional//EN">

By providing other DTD's one can switch IE in "CSS1Compat" mode, but
it's just a formal reaction on "Unknown DTD" programmed into the
browser, DTD itself never changes. Say you can put IE into CSS1Compat
mode by placing instead:
<!DOCTYPE FOOBAR "Micro$oft must die!">
:)
 
R

Randy Webb

VK said the following on 5/2/2006 9:48 AM:
It is a shifty term "treating" :)

Only if you allow it to be.
If you mean "trying to render it" then FF behavior is the same as for
all other UA's willing to be in use (and not W3C demos). If document is
served as text/html, FF will render it somehow anyhow.

So you are saying it totally disregards the DTD and any hints from the
server how to handle the document?
Obviously it doesn't connect every time to w3.org to get a DTD, it uses
a build one.

So you are saying, again, that DTD's are irrelevant?
That would be another aspect of your question: what DTD/
tag database is build in into FF? Only one so far: XHTML 1.0 The only
namespace for HTML Firefox knows about is
xmlns:html="http://www.w3.org/1999/xhtml"

If that is true, then Firefox is not even close to Standards Compliant.
But what decision will it make based on this table - it depends
completely on the Content-Type. Say absolutely the same content with
Content-Type text/html will go through or get adjusted, but with
application/xhtml+xml will lead to a parsing error.

Odd behavior if you tell it text/html with a 4.01 DTD
And if anyone curious: the build in DTD of IE6 is
<http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd> This is the
only one it's aware of and the only one it uses. Respectively the only
type of documents existing in IE is <!DOCTYPE HTML PUBLIC "-//W3C//DTD
HTML 4.01 Transitional//EN">

Now that I don't believe.
By providing other DTD's one can switch IE in "CSS1Compat" mode, but
it's just a formal reaction on "Unknown DTD" programmed into the
browser, DTD itself never changes.

Can you prove that?
Say you can put IE into CSS1Compat mode by placing instead:
<!DOCTYPE FOOBAR "Micro$oft must die!">

Does the fun never end?

document.doctype gives some neat info in Firefox though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top