Dojo.attr() doesn’t work as expected in IE

Stop me if you’ve heard this before: a cross-browser solution doesn’t work in IE. (For a recap on my feelings about the browser, feel free to review this post).

I tried to take a solution that I posted recently to fix category indenting in a view panel with a totals column and apply it to a test database and I noticed that it didn’t work in IE 9. (I didn’t test other versions.)

It found the category rows and removed the empty cells, but didn’t indent properly. It worked fine in Firefox and Chrome (where I was testing when I figured it out and wrote the original post). By displaying the outerHTML property of the category nodes, I was even able to verify that the colspan attribute was technically there, but it just didn’t take effect.

I tried using dojo.attr() to set attributes of other elements and had no success. It seems that the method just doesn’t work well in IE.

I was almost finished with a hacktastic workaround (which involved inserting my own cells by copying the existing category cell and inserting a colspan, positioning them, removing the originals) when I came across this simple JavaScript DOM method: colSpan

To make the code work cross-browser, all I had to do was change line 24 in the last code block on the last post from this:

dojo.attr(nodeCat, 'colspan', 1+emptyCells);

to this:

nodeCat.colSpan = 1+emptyCells;

Now it works in IE, Firefox, and Chrome!


2 responses to “Dojo.attr() doesn’t work as expected in IE”

  1. Erik Brooks says :

    All attributes are technically string arguments, so shouldn’t your last arg to dojo.attr() be a string instead of a number?

    • Brad Balassaitis says :

      Thanks for the feedback. In this case, the data type didn’t make a difference, though. While isolating the problem, I was testing it with both numeric and string values, both as variables and hard-coded. It didn’t make a difference in the functionality in any of the browsers, so I guess it handles the type conversion automatically.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: