I want to insert some html into a div suppose this:
I am using $(\'#Sag\').html(data)
, in ord
so how can I escape ",',... should I use a \ before each one, or is there something like @ in c# to use in javascript
No, JavaScript doesn't have an equivalent of C#'s @
feature.
In JavaScript, strings can be quoted by either single ('
) or double ("
) quotes. Within a quote, only the style you've used for quoting needs to be escaped. So within a string quoted with single quotes, double quotes don't need escaping; and within a string using double quotes, single quotes don't need escaping. (It's always okay to escape them, all that varies is whether you have to.)
So you usually pick the one you're using least, and use that for the main string's delimiter. E.g.:
str = "This uses doubles, so I don't have to worry about the ' in \"don't\".";
Note that I didn't have to escape '
there, but I did have to escape "
.
Similarly:
str = 'This uses singles, so I don\'t have to worry about "quoting" things.';
There I had to escape '
but not "
.