I think that you want the semicolon outside the string literal:

var quote_str = '<option value="1">tea</option>';

If you mean that you want apostrophe characters inside the string also, you can use \' to put an apostrophe in a string delimited by apostrophes:

var quote_str = '\'<option value="1">tea</option>\'';

You can also use quotation marks to delimit the string. Then you don't have to escape the apostrophes, but you have to escape the quotation marks:

var quote_str = "'<option value=\"1\">tea</option>'";

If you already have a string, and want to add apostrophes around it, you concatenate strings:

var quote_str =  "'" + str + "'";
Answer from Guffa on Stack Overflow
๐ŸŒ
Infinetsoft
infinetsoft.com โ€บ Post โ€บ How-to-add-single-quotes-inside-a-string-using-JavaScript โ€บ 1136
How to add single quotes inside a string using JavaScript?
April 24, 2016 - Place your entire string inside double quotes and use single quotes inside the string whatever you want. <script type="text/javascript"> var myString = "Welcometo 'Infinetsoft' tutorials"; alert(myString); </script>
๐ŸŒ
javascript.com
javascript.com โ€บ learn โ€บ strings
JavaScript Strings: The Basic Methods and Functions | JavaScript.com
Strings in JavaScript are contained ... Strings but be sure to choose one and STICK WITH IT. If you start with a single quote, you need to end with a single quote....
๐ŸŒ
YouTube
youtube.com โ€บ watch
Quoting Strings with Single Quotes (Basic JavaScript) freeCodeCamp tutorial - YouTube
Do you need more help with coding?โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โœ… Apply for 1-1 coaching https://form.jotform.com/230156286763056Certification: JavaScript Algo...
Published ย  May 22, 2021
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ javascript-string-with-quotes
JavaScript String with Quotes - GeeksforGeeks
July 23, 2025 - One can use the backslash (\) inside the string to escape from the quotation mark. They will need to follow the below example to follow this method. ... Example: In this example, a string with a single quote is printed in the console.
๐ŸŒ
Flexiple
flexiple.com โ€บ javascript โ€บ double-vs-single-quotes-javascript
'Single' vs "Double" quotes for strings in javascript - Flexiple
March 10, 2022 - Wise selection of quoting can help you from escaping single (') or double(") quotes within a string. For example, if you wish to store a HTML snippet in a variable, you can use double quotes (") for HTML attribute values and use single quotes (') for enclosing the JavaScript string:
๐ŸŒ
Javatpoint
javatpoint.com โ€บ javascript-string-with-quotes
JavaScript String with quotes - Javatpoint
JavaScript String with quotes - JavaScript String with quotes with javascript tutorial, introduction, javascript oops, application of javascript, loop, variable, objects, map, typedarray etc.
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ geekculture โ€บ string-literals-in-javascript-should-i-use-double-quotes-or-single-quotes-3639342480f9
String Literals in JavaScript: Should I Use Double-quotes or Single-quotes? | by Bernhard Hรคussermann | Geek Culture | Medium
May 12, 2021 - Add the rule quotes: ['error', 'single'] to your .eslintrc.js to make ESLint enforce single quotes. If you happen to have a lot of style transgressions in your code, know that some rule violations can be automatically fixed by ESLint (including strings literals using the wrong type of quote). Just run the eslint command including the --fix option, like so (adjust the --ext option based on whether your code is in JavaScript or TypeScript):
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-work-with-strings-in-javascript
How To Work with Strings in JavaScript | DigitalOcean
August 24, 2021 - In this article, weโ€™re going to learn how to create and view the output of strings, how to concatenate strings, how to store strings in variables, and the rules of using quotes, apostrophes, and newlines within strings in JavaScript. In JavaScript, there are three ways to write a string โ€” they can be written inside single quotes (' '), double quotes (" "), or backticks (` `).
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Learn_web_development โ€บ Core โ€บ Scripting โ€บ Strings
Handling text โ€” strings in JavaScript - Learn web development | MDN
If your program is raising such errors, then go back and check all your strings to make sure you have no missing quotation marks. The following will work if you previously defined the variable string โ€” try it now: ... In JavaScript, you can choose single quotes ('), double quotes ("), or backticks (`) to wrap your strings in.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_strings.asp
JavaScript Strings
1 month ago - Strings created with single or double quotes work the same. There is no difference between the two. You can use quotes inside a string, as long as they don't match the quotes surrounding the string: let answer1 = "It's alright"; let answer2 = "He is called 'Johnny'"; let answer3 = 'He is called "Johnny"'; Try it Yourself ยป ยท Templates were introduced with ES6 (JavaScript 2016).
๐ŸŒ
Bytearcher
bytearcher.com โ€บ articles โ€บ single-or-double-quotes-strings-javascript
Should I use 'single' or "double-quotes" for strings in JavaScript
There is no type for a single character in JavaScript - everything is always a string. ... Strategic selection of the quote character can save you from escaping ' or " characters inside the string.
Top answer
1 of 5
204

You should always consider what the browser will see by the end. In this case, it will see this:

<img src='something' onmouseover='change(' ex1')' />

In other words, the "onmouseover" attribute is just change(, and there's another "attribute" called ex1')' with no value.

The truth is, HTML does not use \ for an escape character. But it does recognise &quot; and &apos; as escaped quote and apostrophe, respectively.

Armed with this knowledge, use this:

document.getElementById("something").innerHTML = "<img src='something' onmouseover='change(&quot;ex1&quot;)' />";

... That being said, you could just use JavaScript quotes:

document.getElementById("something").innerHTML = "<img src='something' onmouseover='change(\"ex1\")' />";
2 of 5
187

The answer here is very simple:

You're already containing it in double quotes, so there's no need to escape it with \.

If you want to escape single quotes in a single quote string:

var string = 'this isn\'t a double quoted string';
var string = "this isn\"t a single quoted string";
//           ^         ^ same types, hence we need to escape it with a backslash

or if you want to escape \', you can escape the bashslash to \\ and the quote to \' like so:

var string = 'this isn\\\'t a double quoted string';
//                    vvvv
//                     \ ' (the escaped characters)

However, if you contain the string with a different quote type, you don't need to escape:

var string = 'this isn"t a double quoted string';
var string = "this isn't a single quoted string";
//           ^        ^ different types, hence we don't need escaping
๐ŸŒ
W3docs
w3docs.com โ€บ javascript
When to Use Double or Single Quotes in JavaScript
In JavaScript, single (โ€˜ โ€™) and double (โ€œ โ€) quotes are frequently used for creating a string literal.
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ javascript
Quoting strings with single quotes JS - JavaScript - The freeCodeCamp Forum
February 11, 2022 - Challenge is basic javascript - javascript algorithms and data structures This is the challenge example const myStr = " Link"; challenge states to remove the backslashes and code should have 2 single quotes and 4 double quotes. which i did in the example below. var myStr = 'Link'; when i click ...
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ guide
freeCodeCamp Challenge Guide: Quoting Strings with Single Quotes - Guide - The freeCodeCamp Forum
October 16, 2019 - Quoting Strings with Single Quotes Problem Explanation String values in JavaScript may be written with single or double quotes, so long as you start and end with the same type of quote. Unlike some languages, single andโ€ฆ