Reputation: 621
I want some help for someone about how to insert a new element in a body of document using JQuery.
I´m recover the body with:
var a = $(editorFrame).contents().find('body').html();
Then, I need to verify that the body has the element <p></p>
, with it doesn´t, I have to put this element after the first <DIV>
. Here is my body
<body>
<div id="testeFooter" class="footer-element">
<table id="footerDiv" class="mceItemTable" width="100%">
<tbody>
<tr>
<td id="footerContent">
<b>Digite aqui o seu Rodapé</b>
</td>
</tr>
</tbody>
</table>
</div>
<div id="testeHeader" class="header-element">
<table id="headerDiv" class="mceItemTable" width="100%">
<tbody>
<tr>
<td id="headerContent">
<b>Digite aqui o seu cabeçalho</b>
</td>
</tr>
</tbody>
</table>
</div>
<p>ESSSE MODELO TESTE</p>
</body>
I just need to know how I can put a new element after the first on the body.
Thank´s a bunch with you can help me!
Upvotes: 2
Views: 6754
Reputation: 621
First, I want to thank all for help!
I resolve my problem just making this:
$(editorFrame).contents().find('body').append('<p><br></p>').html();
The method prepend works too!
Upvotes: 0
Reputation: 2631
What you mean after the first?
Anyway
var body = $(editorFrame).find('body');
body.prepend('<someelement>')
will insert right in the begining
If you need to insert for example after first element in the body you should use
body.find(':eq(0)').after('<someelement>')
Upvotes: 5