1321941
1321941

Reputation: 2170

Jquery to load java script content into a div

I have the following code:

var refreshId = setInterval(function()
{
    $("#footad").html('myjshere');
}, 15500);

Where it says myjshere I want to load this content into the div:

    <script type='text/javascript'>
      AdServer.placeAd({"sz":"728x90","pos":1});
    </script>

But when I try just having it where myjshere is, it throws out a syntax error?

Any help?


To clear up the confusion I was put the JavaScript where myjshere is I just used the word myjshere as a place holder to show you what I was doing. Sorry for the confusion. The issue is that when I put the javascript within the jQuery it does not work and returns an error: invalid syntax.


Upvotes: 1

Views: 175

Answers (5)

Subhajit
Subhajit

Reputation: 1987

You need to do it like this

<script type='text/javascript'>

     var myjshere = AdServer.placeAd({"sz":"728x90","pos":1});
     $(document).ready(function(){
        setInterval(function()  {
             $("#footad").html(myjshere);
          }, 15500);
     });

</script>

Upvotes: 0

Holger D. Schauf
Holger D. Schauf

Reputation: 147

do you want to see the js as plain text you can load it with:

var js = AdServer.placeAd({"sz":"728x90","pos":1});
$("footad").html(js);

but will the js function placeAd return html? if not you must give an target to the AdServe class. like Adserver.target("#footad");

if this all is not that what you need, you must give more informations.

Upvotes: 0

Curtis
Curtis

Reputation: 103368

I'm assuming AdServer.placeAd is a third-party function you want to implement. Therefore it depends on what the output of this function is. If Adserver.placeAd returns a HTML string you could do the following:

<script type='text/javascript'>
var refreshId = setInterval(function()
{
   $("#footad").html(AdServer.placeAd({"sz":"728x90","pos":1}));
}, 15500);
</script>

My guess is that this code is running document.write() inside the function seeing as its called placeAd. Therefore you could add the code into the part of the HTML document you want it to appear like:

<script type='text/javascript'>
setInterval(function()
{
   AdServer.placeAd({"sz":"728x90","pos":1});
}, 15500);
</script>

Upvotes: 1

Rufinus
Rufinus

Reputation: 30751

i better dont aks why you want to do this....

$('#footad').html('<script type="text/javascript">
AdServer.placeAd({"sz":"728x90","pos":1});
</script>');

Upvotes: 0

Playmaker
Playmaker

Reputation: 1456

What your script is doing is putting 'myjshere' into the element with id 'footad' .

Is that what you are trying to achieve?

If I understood right, what you want, then this is the code:

var refreshId = setInterval(function()
{
    $("#myjshere").html("<script type='text/javascript'>     AdServer.placeAd({'sz':'728x90','pos':1});</script>");
}, 15500);

Else if you want to replace myshere

var refreshId = setInterval(function()
{
    $("#footad").replace("myjshere","<script type='text/javascript'>     AdServer.placeAd({'sz':'728x90','pos':1});</script>");
}, 15500);

Upvotes: 1

Related Questions