1
<a title="Delete" onclick="remove_file('folder', 4493,'Colin&#39;s folder')"><i class="icon-trash" style="cursor:pointer;"></i></a>

The above code has the html code &#39; to represent an apostrophe in the string. In Google Chrome, I am currently getting the following error from that line:

Uncaught SyntaxError: unexpected Identifier

I assume that one of those characters is breaking the parsing? I have other instances of this same code without the apostrophe code and I do not get the error. How can I fix this, while still being able to pass strings with apostrophes?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Colin Brogan
  • 728
  • 10
  • 26

2 Answers2

3

How about

'Colin\'s folder'

instead? Javascript understands backslash escapes.

Marc B
  • 356,200
  • 43
  • 426
  • 500
1

Can you not just escape it like the following:

onclick="remove_file('folder', 4493,'Colin\'s folder')"

See the following jsbin with an alert: http://jsbin.com/axuyun/1/

Seth Flowers
  • 8,990
  • 2
  • 29
  • 42