setAttribute problem with td-tag in IE

P

Pugi!

I use
mycurrent_cell.setAttribute("style", "background-color:green");
and
mycurrent_cell.setAttribute("colspan", "3");
to set some attributes of a table. The code works perfect in FireFox and
Opera, but in IE the table looks like those properties haven't been set.
When I use the 'view generated source' (from webdevelopers toolbar in FF)
and I use that to create a static html-page, it looks OK in IE. I've checked
but the setAttribute is recognized by IE, but maybe there is a problem with
the setAttribute when used for a <td> or <th> ?

If necessary I can post complete code.

Pugi!
 
J

Jonas Raoni

Pugi! said:
mycurrent_cell.setAttribute("style", "background-color:green");
mycurrent_cell.setAttribute("colspan", "3");
to set some attributes of a table. The code works perfect in FireFox and
Opera, but in IE the table looks like those properties haven't been set.

IE has quite a lot of bugs, I didn't tested these two lines above and I
won't do it now hehe. Anyway, in my opinion it should work, try to set
through JavaScript to see if it works ;)

cell.style.backgroundColor = "green";
cell.colSpan = 3;

But maybe you're right, since there's a problem with the class property,
when you set through setAttribute on IE it doesn't reflect your changes,
it does only if you set using "object.className = 'lala'";

If necessary I can post complete code.

Post an URL, with the minimun code to generate the problem. If you post
a big code here, nobody will read :)
 
P

Pugi!

Jonas Raoni said:
IE has quite a lot of bugs, I didn't tested these two lines above and I
won't do it now hehe. Anyway, in my opinion it should work, try to set
through JavaScript to see if it works ;)

cell.style.backgroundColor = "green";
cell.colSpan = 3;

But maybe you're right, since there's a problem with the class property,
when you set through setAttribute on IE it doesn't reflect your changes,
it does only if you set using "object.className = 'lala'";



Post an URL, with the minimun code to generate the problem. If you post a
big code here, nobody will read :)

Thanks,

The cell.style.backgroundColor ... and cell.colSpan work great. I wonder is
there a way to test/detect that a browser doesn't support the setAttribute
method ? I am learning DOM & Javascript and it is thaught it is not done to
test for a browser but to test if a property, method, object , ... is valid
(if (window.ActiveXObject) {...}).

Pugi!
 
P

Pugi!

Pugi! said:
Thanks,

The cell.style.backgroundColor ... and cell.colSpan work great. I wonder
is there a way to test/detect that a browser doesn't support the
setAttribute method ? I am learning DOM & Javascript and it is thaught it
is not done to test for a browser but to test if a property, method,
object , ... is valid (if (window.ActiveXObject) {...}).

Pugi!

IE supports the setAttribute for a table, but not for a cell (td or th).
So I guess I will have to work with cell.style.backgroundColor, ... to set
properties for a <td> or <th>-tag.

Pugi!
 
M

Michael Winter

"Jonas Raoni" <[email protected]> schreef in bericht

[snip]
But maybe you're right, since there's a problem with the class
property, when you set through setAttribute on IE it doesn't
reflect your changes, it does only if you set using
"object.className = 'lala'";

One has to pass 'className' to the setAttribute method for IE to
recognise it. Yes, I know: stupid.

[snip]
I wonder is there a way to test/detect that a browser doesn't support
the setAttribute method ?

Just avoid it. As far as I know, all HTML attributes and CSS properties
can be accessed using the shortcut properties.

If a document is served as XHTML (that is, with an application/xhtml+xml
MIME type) the situation is different, but then IE doesn't support
XHTML, anyway.
I am learning DOM & Javascript and it is thaught it is not done to
test for a browser but to test if a property, method, object , ... is
valid

Yes, but as IE does implement the *Attribute methods, a test would need
to be more complicated than that. Besides, what would you do if the test
failed? Use the shortcut properties, no doubt, so you might as well do
that from the outset.
(if (window.ActiveXObject) {...}).

A rather random example. It certain has no relevance here.

Mike
 
J

Jonas Raoni

Pugi! said:
IE supports the setAttribute for a table, but not for a cell (td or th).
So I guess I will have to work with cell.style.backgroundColor, ... to set
properties for a <td> or <th>-tag.

I don't know about you, but I always preffer to use the built-in
JavaScript stuffs.

Instead of:

select.appendChild(document.createElement("option")).text = "Jonas";

I preffer:

select.options.add(new Option("Jonas", ""));
 
K

kay

"So I guess I will have to work with cell.style.backgroundColor"

well... whats wrong with that? its easier to use, faster and less
complicated, so rather than "having to" you "are luckily allowed to"
:)))
 

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,780
Messages
2,569,608
Members
45,248
Latest member
MagdalenaB

Latest Threads

Top