1

When I pass the string 2cdfdfa2-3639-4aed-bf37-9fb7ba1c936c to a javascript function, I get syntax error in Firebug.

I have my code in a variable before inserting it into a div-tag. I print this out in the Console when I press the DeleteBookmarkFunction. Firebug says there is a syntax error in the call of the function:

<div onclick='DeleteBookmarkFunction('3fad79fb-ce54-4ceb-9b35-cfb50d5540de')'>
  <a class='remove'>Slett</a>
</div>

Some of my code:

var id=data[j].UniqueID;
src += "<div  id='" + data[j].UniqueID + "'></div>" ;

src += "<div onclick=\'DeleteBookmarkFunction  ( \'"
src += id;
src += "\' )\'>";
src += '<a class=\'remove\'>Slett</a></div>';          

What is causing Firebug to report an error?

2
  • 2
    Hint: Look at the syntax highlighting in your question. Commented Dec 10, 2012 at 19:02
  • 1
    Your quotes are miss-matched, the single quotes inside the attribute value are breaking out of the attribute value. Commented Dec 10, 2012 at 19:03

1 Answer 1

2

Use double quotes for attributes

<div onclick="DeleteBookmarkFunction  ( '3fad79fb-ce54-4ceb-9b35-cfb50d5540de' )"><a class="remove">Slett</a></div>
Sign up to request clarification or add additional context in comments.

1 Comment

It doesn't matter which you use, just make sure the outer quotes are different from the inner ones.

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.