user1464139
user1464139

Reputation:

How can I quote text that's already inside a single and double quote?

I have:

'<textarea data-ng-show="modal.showPreview == 'Source'"  >'

How can I quote the word Source? I tried single quotes but that does not work.

Upvotes: 1

Views: 185

Answers (3)

Vishal Suthar
Vishal Suthar

Reputation: 17194

You can escape the double quotes with Backslash (\)

Your code won't work as intended because, as soon as the browser encounters the first double quote, it will think that the string has finished.

You can refer to this: JavaScript Escape Characters

How about this:

'<textarea data-ng-show="modal.showPreview == \"Source\"" >'

Upvotes: 1

Tareq Salah
Tareq Salah

Reputation: 3718

You need to use backslash \

'<textarea data-ng-show="modal.showPreview == \"Source\""  >'

Upvotes: 1

joews
joews

Reputation: 30330

You can use escaped double quotes:

'<textarea data-ng-show="modal.showPreview == \"Source\"">'

Upvotes: 2

Related Questions