A.C.Balaji
A.C.Balaji

Reputation: 1113

unterminated string literal error

I have placed the below code inside of the tag.

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('head').append('<script type="text/javascript" src="../wp-includes/js/thickbox.js"></script>');    
    });
</script>

I got an error of "unterminated string literal".

Upvotes: 3

Views: 10344

Answers (4)

Trotter
Trotter

Reputation: 1270

The problem is coming from the fact that your code includes </script> in it. This is causing the browser to think that you're terminating your <script> tag early. If you change your code to the following, it will work:

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('head').append('<script type="text/javascript" src="../wp-includes/js/thickbox.js"></' + 'script>');    
    });
</script>

As you can see, the above code breaks the </script> in your string into '</' + 'script>', so that the browser doesn't parse it as a closing tag.

Upvotes: 10

Linus Kleen
Linus Kleen

Reputation: 34632

"unterminated string literal error" is not a Javascript error.

It hints towards a PHP script error, though. Post that code and you shall receive help.

Upvotes: 1

kobe
kobe

Reputation: 15835

Balaji ,

Use jquery' getscript , its very nice way of doing it , it will append in head section and less changes of errors

http://api.jquery.com/jQuery.getScript/

Upvotes: 0

outis
outis

Reputation: 77400

The code you posted doesn't have an unterminated string literal. The error means that you've started a string with a single or double quote, but don't have a second quote of the same kind to close the string.

Upvotes: 1

Related Questions