Link to home
Start Free TrialLog in
Avatar of mike99c
mike99c

asked on

Trying to insert a script block in <head> using JQuery

I am trying to use JQuery to insert a script block in the head part of my website but I get an unterminated string error. Here is my code:

	<script>
		$(function() {
		  
		  $("head").append("<script type='text/javascript'>alert('Hello world');</script>");
		
		});
	</script>

Open in new window


When I use the IE debugger it gives the following error:
SCRIPT1015: Unterminated string constant

And it points to the start of </script>.

I tried escaping the single quotes by adding \' but it still does not work.
ASKER CERTIFIED SOLUTION
Avatar of mike99c
mike99c

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mike99c
mike99c

ASKER

Forgot to escape the /.