adarshaU
adarshaU

Reputation: 960

setAttribute not working in IE7

The below code works fine in IE9 and IE8 but not working in IE7. May I know, What's wrong with this code?

JS Code:

if(innerwidth>1000 && innerwidth<1500){
     var fileref=document.createElement("link");
     fileref.setAttribute("rel","stylesheet");  
     fileref.setAttribute("type","text/css");
     fileref.setAttribute("media","all");
     fileref.setAttribute("href","1001aboveie7.css");
     document.getElementsByTagName("head")[0].appendChild(fileref);
}

Thanks:)

Upvotes: 3

Views: 2859

Answers (2)

user2724772
user2724772

Reputation:

IE7 do not support:

setAttribute

you use to use base attribute to add it.

var foo = document.createElement("link"); foo.rel = "stylesheet";

Upvotes: 0

asharajay
asharajay

Reputation: 1193

try this, it works with my IE7

if (innerwidth > 1000 && innerwidth < 1500) {
    var fileref = document.createElement("link");
    fileref.rel = "stylesheet";
    fileref.type = "text/css";
    fileref.media = "all";
    fileref.href = "1001aboveie7.css";
    document.getElementsByTagName("head")[0].appendChild(fileref);
}

Upvotes: 3

Related Questions