user1341839
user1341839

Reputation: 75

Script isn't working inside jQuery

I have this jQuery code:

document.getElementById('geo_us').innerHTML = "<script type='text/javascript' src='http://www.101greatgoals.com/wp-content/themes/tutorial/js/gadout.js'></scr" + "ipt>";
$("#geo_us").append("<div id='div-gpt-ad-1335877669074-0' style='width:160px; height:600px;'></div>");
document.getElementById('div-gpt-ad-1335877669074-0').innerHTML = "<script type='text/javascript' src='http://www.101greatgoals.com/wp-content/themes/tutorial/js/gad.js'></scr" + "ipt>";

This is the result I am getting: The content/code of the external js is not there..

<div id="geo_us">
   <script src="http://www.101greatgoals.com/wp-content/themes/tutorial/js/gadout.js" type="text/javascript">
   </script>
   <div style="width: 160px; height: 600px;" id="div-gpt-ad-1335877669074-0">
      <script src="http://www.101greatgoals.com/wp-content/themes/tutorial/js/gad.js" type="text/javascript">
      </script>
   </div>
</div>

Do you know what's wrong in the code?

Thanks.

Upvotes: 1

Views: 138

Answers (2)

kaz
kaz

Reputation: 1943

Try this:

$('#geo_us').html("<script type='text/javascript' src='http://www.101greatgoals.com/wp-content/themes/tutorial/js/gadout.js'></scr" + "ipt>");

$("#geo_us").append($("<div id='div-gpt-ad-1335877669074-0' style='width:160px; height:600px;'></div>"));

$('#div-gpt-ad-1335877669074-0').html("<script type='text/javascript' src='http://www.101greatgoals.com/wp-content/themes/tutorial/js/gad.js'></scr" + "ipt>");

Upvotes: 0

epascarello
epascarello

Reputation: 207501

You can not add script tags with innerHTML, use append with document.create element. Why are you mixing jQuery and regular JavaScript. Pick one.

var str = '<script src="http://www.101greatgoals.com/wp-content/themes/tutorial/js/gadout.js"></script><div style="width: 160px; height: 600px;" id="div-gpt-ad-1335877669074-0"><script src="http://www.101greatgoals.com/wp-content/themes/tutorial/js/gad.js"></script></div>';
jQuery("#geo_us").append( str );

Upvotes: 2

Related Questions