Class Name not getting changed in IE 7, 8 and chrome

后端 未结 1 1189
情歌与酒
情歌与酒 2021-01-23 15:30

I am trying to change class name of two elements during onload.

Here is my code for the same :

    var browserName=navigator.appName;
    var tfElem = do         


        
1条回答
  •  离开以前
    2021-01-23 16:11

    There is a bug in the implementation of setAttribute in old versions of IE. In newer versions of IE that bug may be emulated if you do not use a Doctype that triggers standards mode.

    Replace:

    foo.setAttribute('class', value);
    

    With:

    foo.className = value;
    

    Do this everywhere. Don't try to do browser detection. All browsers that support setAttribute('class', value) also support foo.className = value.

    The code in your question should be rewritten as:

    var tfElem = document.getElementById("TTlExpct");
    var blTfElem = document.getElementById("BTLExpct");
    tfElem.className ="pn-tf";
    blTfElem.className ="pn-tf active";
    

    0 讨论(0)
提交回复
热议问题