How to place html dynamically right after the body tag, but inside the body tag? JQuery

I need to add some html right after the body tag like this:

<body> <p>this is the HTML I need to add</p> </body> 

Here is my jQuery code:

 jQuery(document).ready(addPageFlipHTML); function addPageFlipHTML() { jQuery('body') // after body tag .after( "<div id='pageflip'><a href='http://sabwd.com'><img src='/test/wp-content/plugins/page-flip/images/page_flip.png' alt='' />" //create this html + "<span class='msg_block'>Subscribe via RSS</span></a></div>"); } 

Does anyone know how to do this? I am trying to write a universal plugin and need a specific tag, such as a body, which needs to be added after, but inside.

Thanks Advance,

Mike

+6
jquery html plugins
source share
1 answer

To place new content inside a <body> element, you want prepend() (docs) instead:

 jQuery('body') .prepend( "<div id='pageflip'><a href='http://sabwd.com'><img src='/test/wp-content/plugins/page-flip/images/page_flip.png' alt='' />" //create this html + "<span class='msg_block'>Subscribe via RSS</span></a></div>"); 

The reason is that jQuery('body') does not select the opening <body> , but the entire <body></body> element.

Thus, the after() (docs) method tried to post new content after </body> , which is invalid. But .prepend() places the new content inside the body (and before any other content that may be inside).

+16
source share

All Articles