1

My code which is giving error in IE8

$(function(){
 $.ajax({url:"http://localhost/css/register.txt",  
         cache : false,
         success:function(ris){$("<style></style>").appendTo("head").html(ris);//culprit statement
          },
         error:function(){}
                                    });
});
bugwheels94
  • 30,681
  • 3
  • 39
  • 60
  • Try replacing `.html(ris)` with `.text(ris)`. ...or try `$("")` –  Jul 27 '12 at 16:31
  • $("") worked but can you tell me why my code not worked – bugwheels94 Jul 27 '12 at 16:36
  • 2
    All I know is that there are browser compatibility issues when setting the content of a ` –  Jul 27 '12 at 16:38
  • Did that technique work in the other browsers as well? I'd hate to leave a solution if it breaks in some other browser. –  Jul 27 '12 at 16:40
  • yes it is working in all browsers – bugwheels94 Jul 27 '12 at 16:41

2 Answers2

3

It seems that jQuery doesn't resolve the browser compatibility issues regarding setting the content of a <style> element via innerHTML.

I believe this will work instead...

$("<style>" + ris + "</style>")
3

Internet Explorer does not allow setting of innerHTML on <style> elements. See How to create a <style> tag with Javascript

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375