0

I imagine this has been asked many times but I am having problems with the above error, What I am trying to do is have a cortina effect menu whose child divs content will change depending on a variable which is coming from a drop down menu.

So I wrote roughly how the content of the div would look for one option in a bid to test it out and this is what I have:

function popupContent(selectedText)
{

    return '<div>Operating System:
    <a class="changer">+<\/a><select class="firstSelect">
<option>Windows<\/option>
<option>OSX<\/option>
<option>Linux<\/option>
<\/select>
<\/div>
<div>Releases:<a class="changer">+<\/a><select class="secondSelect"><option>11.0<\/option><option>11.2<\/option>
<option>10.1<\/option>
<\/select>
<\/div>';
}

I set the content of the div using $('#divname').html(popupContent(this.name));

When I try to load the page I get a unterminated string literal error, I have spent some time looking around and most of the questions seem to be when the word script is in it (which I don't have) and escaping / characters which I have tried as you can see.

Can anyone shed some light on this please?

3
  • possible duplicate of Javascript code,unterminated string literal Commented Dec 19, 2011 at 17:53
  • 1
    Just put that HTML code inside your HTML file and hide it with CSS... Commented Dec 19, 2011 at 17:56
  • did you try it in only one line? Commented Dec 19, 2011 at 18:02

1 Answer 1

3

Your string has line breaks in it.

You can do this instead:

return '<div>Operating System:' +
  '<a class="changer">+<\/a><select class="firstSelect">' +
  '<option>Windows<\/option>' +

etc.

Sign up to request clarification or add additional context in comments.

1 Comment

Right. The error message means that the line return '<div>Operating System: (and in fact, the next nine lines after that) ends without a closing single-quote mark.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.