Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert DIV Just after <body> tag

I have the following code:

<script type="text/javascript">
    $(document).ready(function() {
        $('<div id="tools" style="text-align:right;float:right;"><input type="button" value="Print this page" onclick="window.print();return false;" /><input type="button" value="Save this page" onclick="go_saveas();return false;" /></div>').insertBefore('body');
    });
</script>

Basically, I need to insert that whole Div just right after the <body> tag:

</head>
<body>
    <div id="tools"..
...

Which works in Firefox but doesn't work in IE 7, what do I have to change to fix this?

like image 957
Connection Avatar asked Jun 03 '11 20:06

Connection


2 Answers

You're using insertBefore. That will try to put it between head and body; not what you want. Try prependTo.

like image 125
icktoofay Avatar answered Sep 30 '22 16:09

icktoofay


http://jsfiddle.net/XDFMt/:

<script type="text/javascript">
    $(document).ready(function() {

        $('<div id="tools" style="text-align:right;float:right;"><input type="button" value="Print this page" onclick="window.print();return false;" /><input type="button" value="Save this page" onclick="go_saveas();return false;" /></div>')
            .prependTo('body');

    });
</script>
like image 27
Code Maverick Avatar answered Sep 30 '22 16:09

Code Maverick