#1072 new
Chris R.

Issue with Element.writeAttribute in IE7 and setting style

Reported by Chris R. | June 10th, 2010 @ 05:11 PM

I think there is a bug with the writeAttribute function on Element when using IE7 (only IE browser that I've tested). Below is the existing code:

1   writeAttribute: function(element, name, value) {
2      element = $(element);
3      var attributes = { }, t = Element._attributeTranslations.write;
4
5      if (typeof name == 'object') attributes = name;
6      else attributes[name] = Object.isUndefined(value) ? true : value;
7
8      for (var attr in attributes) {
9        name = t.names[attr] || attr;
10       value = attributes[attr];
11       if (t.values[attr]) name = t.values[attr](element, value);
12       if (value === false || value === null)
13         element.removeAttribute(name);
14       else if (value === true)
15         element.setAttribute(name, name);
16       else element.setAttribute(name, value);
17     }
18     return element;
19 }

20 Element._attributeTranslations.write = {
21    names: Object.extend({
22      cellpadding: 'cellPadding',
23      cellspacing: 'cellSpacing'
24    }, Element._attributeTranslations.read.names),
25    values: {
26      checked: function(element, value) {
27        element.checked = !!value;
28      },
29
30      style: function(element, value) {
31        element.style.cssText = value ? value : '';
32      }
33    }
34  };

On line 11 if the attribute is a style attribute then the code finds line 30 in t and calls the function. This function to me seems to fix the IE7 bug with setAttribute and style, however, line 11 doesn't break and the function call returns 'undefined' causing an 'undefined' attribute to be added to the element.

I proposed that line 12 be changed to an else if instead of an if and then assignment of name on line 11 is unnecessary. This should correct the issue. I checked the 1.7 RC and the issue seems to exist there as well.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Attachments

Pages