11

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>
4

3 回答 3

30

Use prepend method:

$('body').prepend('<div id="fb-root"></div>');
于 2013-05-01T22:02:01.250 回答
1

You can use

$('#fb-root').detach().insertBefore('body>*:first');
于 2017-05-08T17:55:38.507 回答
-2

You can do this without JQuery and without prepend

<body>
    <header>test</header>
</body>
<script>
    document.body = '<div id="fb-root"></div>' + document.body + "</div>";
</script>
于 2020-10-11T19:49:44.467 回答