Trying to add css to header using jquery, but it wont work?

Discussion in 'jQuery' started by Anveto, Oct 30, 2011.

  1. #1
    The css works without jquery, but I would like to apply it with jquery if possible, this is my code so far.

    <script>
    $(document).ready(function(){
    $("<style type='text/css'> .flipped {-webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2);
    } </style>").appendTo("head");
    $("<div/>").addClass("flipped").appendTo("body");
    });
    </script>
    Code (markup):
    This is the css I am going from

    <style type="text/css">
     
    html body {
      -webkit-transform: rotate(180deg);
      -moz-transform: rotate(180deg);
      filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2);
    }
     
    </style>
    Code (markup):
    Thanks for the help!
     
    Last edited: Oct 30, 2011
    Anveto, Oct 30, 2011 IP
  2. kellyphong

    kellyphong Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The required code is as;
    $('html body').css('-webkit-transform', 'rotate(180deg)').css('-moz-transform', 'rotate(180deg)').css('filter','progid:DXImageTransform.Microsoft.BasicImage(rotation=2);');
    
    Code (markup):
    Full example:
    <html>
    <head>
    <script type="text/javascript" src="reform/source/js/jquery-1.6.4.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){ 
        $('html body').css('-webkit-transform', 'rotate(180deg)').css('-moz-transform', 'rotate(180deg)').css('filter','progidXImageTransform.Microsoft.BasicImage(rotation=2);');
    });
    </script>
    </head>
    <body>
    <h1>hellow world</h1>
    </body>
     </html>
    HTML:
     
    kellyphong, Oct 31, 2011 IP
  3. Anveto

    Anveto Well-Known Member

    Messages:
    697
    Likes Received:
    40
    Best Answers:
    19
    Trophy Points:
    195
    #3
    Thanks! Really appreciate it.

    Now to prank some friends hehe
     
    Anveto, Oct 31, 2011 IP