Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display double quotes in JavaScript

Tags:

On html page if I give name in double quotes then it is not getting reflected on page. It displays a blank string. I tried with escape() function but that didn't work. So what is the way to display a string in double quotes.

One thing I forgot to mention that I want to display the string in input text box.

like image 204
pan1490 Avatar asked Dec 17 '13 07:12

pan1490


People also ask

Can you use double quotes in JavaScript?

In JavaScript, single (' ') and double (“ ”) quotes are frequently used for creating a string literal. Generally, there is no difference between using double or single quotes, as both of them represent a string in the end.

How do you display double quotes?

For printing double quotes(” “), using print() in C we make use of ” \” ” backslash followed by double quote format specifier.

How do I print a quotation mark in JavaScript?

Example: Print quotes using backslash (\) In this example, we will use the backslash (\) to escape the quotation mark. It's nine o' clock in the morning.

How do you put quotation marks in a string in JavaScript?

Enclosing Quotation Marks That means strings containing single quotes need to use double quotes and strings containing double quotes need to use single quotes. "It's six o'clock."; 'Remember to say "please" and "thank you."'; Alternatively, you can use a backslash \ to escape the quotation marks.


2 Answers

You have several options:

var str = 'My "String"'; //use single quotes for your string var str = "My \"String\""; //escape your doublequotes var str = "My "String""; //use it as html special chars 
like image 162
MaGnetas Avatar answered Oct 11 '22 22:10

MaGnetas


to show double quote you can simple use escape character("\") to show it.

alert("\"Hello\""); 
like image 42
Code Breaker Avatar answered Oct 11 '22 23:10

Code Breaker