What is the real reason that we must escape a forward slash in a JavaScript string, and also why must we escape string/no string in XHTML. A lot of tutorials just brush over this issue.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In an HTML 4 document, the sequence
</inside an element defined as containing CDATA (such as script) is an end tag and will end the element (with an error if it is not</script>.As far as JS is concerned
/and\/are identical inside a string. As far as HTML is concerned</starts an end tag but<\/does not.XHTML doesn’t provide a method of specifying that an element intrinsically contains CDATA, so you need to explicitly handle characters which would otherwise have special meaning (
<,&, etc). Wrapping the contents of the element with CDATA markers is the easiest way to achieve this.