Tuesday, August 26, 2014

How to Escape Double Quote (or Single Quote) Character in JavaScript

Let's
It can be done by putting the backslash \ in front of the character. It can be also implemented for other character.
For example
We wanna inject a quotation-wrapped text for a div element with the id example below:


The JavaScript:



Result


We can also substitute the double quotation with ", and single quotation with ' — without using the backslash.

Let's use the earlier example:
That also applicable for inserting actual HTML element with class or id or other attribute.


Thanks for visiting!

No comments:

Post a Comment

Tell me what you think...