[thelist] Workaround for setAttribute bug in IE7?

Matt Warden mwarden at gmail.com
Mon Dec 11 17:09:20 CST 2006

On 12/11/06, Edwin Martin <edwin at bitstorm.org> wrote:
> Ryan Rushton wrote:
> > I have a table that lists items (1 per row).  When the user clicks on an
> > item I want to insert a new row directly below the clicked item and pull
> > in a summary from a database.  My code works fine in Firefox, but in IE
> > the line: newCell.setAttribute("colspan",8); doesn't seem to set the
> > colspan.  Any suggestions for a workaround?
> >
> Have you tried newCell.colSpan=8?
> (I wonder why people use setAttribute so much, while the HTML-DOM has
> all these ready-to-use properties).
> http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html

Why? Because it makes no sense that setAttribute works in some cases,
unless you are talking about IE and attributes which have been turned
into object properties.

Here is the meaning of setAttribute from devguru:
"The setAttribute method sets the value of the named attribute. If an
attribute of the same name already exists in the element, then its
value is changed to that of the 'value' parameter; *if not, one is
created*." (emphasis mine)

and from moz:
"If the specified attribute already exists, then the value of that
attribute is changed to the value passed to this function. *If it does
not exist, then the attribute is created*." (emphasis mine)

It is very clearly a DOM manipulation. Why would I think that setting
.colSpan object property in IE would create an attribute node in the
DOM? It is a really dumb idea, especially when you consider what
happens when one does:

foo.colSpan = null;

Does this remove an existing attribute node (doubt it)? Does it just
set its value to null (probably)? If the attribute node doesn't
already exist, does it create it and set it to null (probably)?

Matt Warden
Cleveland, OH, USA

This email proudly and graciously contributes to entropy.

More information about the thelist mailing list