If you want to manipulate the DOM you can find it documented here;
http://docs.jquery.com/Manipulation

As for your question, you could either do the following;

$("#foo").after("<p>text I want to insert</p>");
$("#foo").before("<p>text I want to insert</p>");

Or more neatly;

var pToInsert = $('<p/>').append("text I want to insert")

$("#foo").after(pToInsert);
$("#foo").before(pToInsert);




On Jan 8, 8:07 am, kimbaudi <kimba...@gmail.com> wrote:
> Hi, I'm sorry if this question has already been asked, but I searched
> for the term 'create element' on the jQuery Google Groups and didn't
> find the answer. I basically want to create html dynamically and be
> able to add it to my webpage. Suppose I have the following html:
>
> <html>
> <body>
> <p>This is the first paragraph of my webpage.</p>
> <p>Here is some more stuff</p>
> <p>and some more</p>
> <p id="foo">and even more</p>
> <p>and even more</p>
> </body>
> </html>
>
> How would I be able to create the html "<p>text I want to insert</p>"
> and append it into the <p id="foo"> tag? I'm hoping the new html DOM
> structure would look like this:
>
> <html>
> <body>
> <p>This is the first paragraph of my webpage.</p>
> <p>Here is some more stuff</p>
> <p>and some more</p>
> <p id="foo">and even more</p>
> <p>text I want to insert</p>
> <p>and even more</p>
> </body>
> </html>
>
> How would I be able to prepend it into the <p id="foo"> tag? I'm
> hoping the new html DOM structure would look like this:
>
> <html>
> <body>
> <p>This is the first paragraph of my webpage.</p>
> <p>Here is some more stuff</p>
> <p>and some more</p>
> <p>text I want to insert</p>
> <p id="foo">and even more</p>
> <p>and even more</p>
> </body>
> </html>
>
> Thanks.

Reply via email to