Solved

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

Posted on 2014-01-17
2
422 Views
Last Modified: 2014-01-17
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.
0
Comment
Question by:mike99c
  • 2
2 Comments
 

Accepted Solution

by:
mike99c earned 0 total points
ID: 39788140
OK I fixed it:

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

Open in new window


I had to excape the /
0
 

Author Closing Comment

by:mike99c
ID: 39788142
Forgot to escape the /.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now