I\'m using jQuery\'s .data()
to work with custom HTML5 data attributes where the value of the attribute needs to be able to contain both single quotes and doubl
There is no way around it, you have to escape the values properly, or the HTML can't be parsed properly. You can't use Javascript to correct the code after it is parsed, because then it has already failed.
Your example with proper HTML encoding would be:
You can't use backslash to escape characters, because it's not Javascript code. You use HTML entities to escape characters in HTML code.
If you can't control how the data is input, then you are screwed. You simply have to find a way to take control over it.