Append element to top of body in jQuery

javascript, jquery

Solution

Use `prepend` method:

$('body').prepend('<div id="fb-root"></div>');

Problem

Right now Facebook wants me to throw this ugly div at the top of my page directly under `<body>` ``` <div id="fb-root"></div> ``` I would like to avoid this by instead, appending it via JavaScript. ``` .append('<div id="fb-root"></div>'); ``` This places it at the bottom of the page. ``` </head> <body> <header>test</header> <div id="fb-root"></div> </body> ``` How can I 'append' it to the top? ``` </head> <body> <div id="fb-root"></div> <header>test</header> </body> ```

Original source

Related problems