$('<style></style>').text('css').appendTo('head') does not work in IE?

Posted by powerboy on Stack Overflow See other posts from Stack Overflow or by powerboy
Published on 2010-04-22T16:47:18Z Indexed on 2010/04/22 16:53 UTC
Read the original article Hit count: 560

Filed under:
|

It works fine in Firefox and Chrome, but does not work in IE8. Here is the html structure:

<!DOCTYPE html>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  <script type="text/javascript">
   $(function() {
    // this does not work in the stupid IE
    $('<style type="text/css"></style>').text('body {margin: 0;}').appendTo('head');
   });
  </script>
 </head>
 <body>
 </body>
</html>

And what' s the alternative to do this in IE?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about internet-explorer