Search code examples
javascriptjqueryinternet-explorer-7

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?


Solution

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