Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append element to top of body in jQuery

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>
like image 363
O P Avatar asked May 01 '13 21:05

O P


1 Answers

Use prepend method:

$('body').prepend('<div id="fb-root"></div>');
like image 75
undefined Avatar answered Oct 12 '22 22:10

undefined