Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#10179 closed defect (fixed)

dojo.attr breaks with "class" on IE8

Reported by: henrik Owned by: anonymous
Priority: low Milestone: 1.3
Component: HTML Version: 1.2.3
Keywords: IE8 Cc:
Blocked By: Blocking:


This bug was on dojo 1.2.3. I have not checked other versions, it might be in others too.

In dojo html.js, line 1085 for 1.2.3 should be ieLT8 instead of d.isIE Because IE8 in "modern" mode uses the correct class instead of className, but dojo thinks not. Setting the css-class of elements is a very common operation, so this bug will break a lot of code, thus I have marked it as high priority.

This is the code fragment. One solution is to replace d.isIE with ieLT8 on line 1085. Or detect the actual bug instead of the browser version.

//      var ieLT8 = d.isIE < 8;
//      var _fixAttrName = function(/*String*/name){
//              switch(name.toLowerCase()){
//                      case "tabindex":
//                              // Internet Explorer will only set or remove tabindex
//                              // if it is spelled "tabIndex"
//                              // console.debug((dojo.isIE && dojo.isIE < 8)? "tabIndex" : "tabindex");
//                              return ieLT8 ? "tabIndex" : "tabindex";
//                      case "for": case "htmlfor":
//                              // to pick up for attrib set in markup via getAttribute() IE<8 uses "htmlFor" and others use "for"
//                              // get/setAttribute works in all as long use same value for both get/set
//                              return ieLT8 ? "htmlFor" : "for";
//                      case "class" :
//line 1085:  //                return d.isIE ? "className" : "class";
//                      default:
//                              return name;
//              }
//      }

Below is an example of how to feature-detect this problem instead of relying on browser-detection.

var featureSniffClassNameAttributeIsClass = function () {
    var d = dojo.doc.createElement("div");
    try {
        d.setAttribute("className", "c");
        var h = d.outerHTML;
        // if setting className on a node alters the class, we are on IE6 or 7
        var convertClassToClassName = ! /classname/.exec(h.toLowerCase());
        return convertClassToClassName;
    } catch (e) {
        //probably we are on a non IE browser because an error occurred
        return false;

Change History (2)

comment:1 Changed 13 years ago by bill

Component: CoreHTML
Milestone: tbd1.3
Priority: highlow
Resolution: fixed
severity: blockernormal
Status: newclosed

It works fine for me in 1.3 and trunk, I did dojo.attr(dojo.body(), "class", "bill") in the console and then checked dojo.body().className. I did manage to reproduce on 1.2, which BTW does not claim to support IE8 at all.

comment:2 Changed 13 years ago by henrik

Well, no support for IE8 is a good reason for IBM to upgrade dojo version on their latest Lotus Connections product. Thanks for a fast reply.

Note: See TracTickets for help on using tickets.