0

I wanted to insert this ad code.

 <script type="text/javascript" src="http://website.com/wp-content/plugins/oiopub-direct/js.php?type=banner&align=center&zone=1"></script>

right after

<div id="adminmenu"></div>

So that the output of the script will be displayed after the adminmenu div

Is there a way to do that using jquery? I tried .insertAfter but it only works on plain html.

3
  • does that link even have content? Commented Apr 19, 2012 at 3:29
  • Yes.. it displays random advertisements.. Commented Apr 19, 2012 at 3:31
  • Can you post the code you originally tried? Commented Apr 19, 2012 at 3:32

2 Answers 2

2

Render the content first in a hidden, temporary container:

<div class="temp">
    <script type="text/javascript" src="http://website.com/wp-content/plugins/oiopub-direct/js.php?type=banner&align=center&zone=1"></script>
</div>

then move the contents after it is rendered:

$('.temp').contents().appendTo(finalDestination) 
Sign up to request clarification or add additional context in comments.

Comments

0

If a script is using document.write() to emit content, then you have to place the script in the place that you want the content to go.

If you control the script, then you can have the script not emit it's content by default and you can call a function in the script and pass a parent object that directs the script where it should put it's content (which it will not use document.write() to create).

The only other option is to place a div around the script, let it emit the content into that div and then move that container div to another location in the page after it runs.

<div id="ads">
<script type="text/javascript" src="http://website.com/wp-content/plugins/oiopub-direct/js.php?type=banner&align=center&zone=1"></script>
</div>
<script>
$(document).ready(function() {
    $("#ads").appendTo("#myFooter");
});
</script>

I'm not sure exactly what you're trying to ask about jQuery. jQuery is capable of inserting dynamically created content anywhere you want in the page. You'd have to ask a more specific question for us to advise in more details.

2 Comments

I have a div naming adminmenu and i want to add the ad code just right after that div using jquery.. not appending its content.
@Ken, you need to tell us more about how the ad content is created before we can know how to help you. Is it created inline with document.write() in its own container div? You can put something after a div, but it's easier to put something in that div. Why not make a div to put it into and use the code I've already provided you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.