Puneet Purohit
Puneet Purohit

Reputation: 1281

How to show single quotes in string in javascript code?

I am generation dynamic content using javascript and inside that content a part will be like

onfocus="if(this.value=='Enter Email Address'){this.value='';}" onblur="if(this.value=='')    {this.value='Enter Email Address';}" value="Enter Email Address"

I want above code but after generation of the content but all the single quotes are not showing properly. Please help me out. Thanks

Upvotes: 0

Views: 2056

Answers (4)

Brugnar
Brugnar

Reputation: 227

If you're working in HTML 5 with input element, i would suggest you to look at the placeholder attribute, as this is exactly what you are needing for. No javascript needed.

 <input type="text" placeholder="Enter Email Address" />

Upvotes: 1

rajesh kakawat
rajesh kakawat

Reputation: 10896

try something like this , Remove backslash from double quotes,FIDDLE

<input type="text" onfocus="if(this.value=='Enter Email Address'){this.value='';}" onblur="if(this.value=='')    {this.value='Enter Email Address';}" value="Enter Email Address">

Upvotes: 0

Muneeb Nasir
Muneeb Nasir

Reputation: 2504

try this

'\'Text\''

or

"'Text'"

Upvotes: 0

highwingers
highwingers

Reputation: 1669

use Escape character \

'\\'Enter Email\\''

Upvotes: 0

Related Questions