Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  71] [ 4]  / answers: 1 / hits: 37920  / 14 Years ago, mon, june 14, 2010, 12:00:00

How do you nest quotes in HTML beyond the second level? As far as I know, there are only 2 types of quotes - single(') and double(). I am aware of escaping using slashes - you have to escape in the code but that escaping won't work at the browser level. What is the accepted method to get around something like the following?



<p onclick=exampleFunc('<div id=divId></div>');>Some Text</p>


That code prints to the browser:




');>Some Text



More From » html

 Answers
23

You need to use proper escaping/encoding. Either in HTML using character references:



<p onclick=exampleFunc('&lt;div id=&quot;divId&quot;&gt;&lt;/div&gt;');>Some Text</p>


Or in JavaScript using string escape sequences:



<p onclick=exampleFunc('x3Cdivx20idx3Dx22divIdx22x3Ex3C/divx3E');>Some Text</p>

[#96496] Saturday, June 12, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucianom

Total Points: 601
Total Questions: 98
Total Answers: 109

Location: Kenya
Member since Fri, Dec 23, 2022
1 Year ago
lucianom questions
Tue, Feb 22, 22, 00:00, 2 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Sun, Jan 24, 21, 00:00, 3 Years ago
Sat, Aug 15, 20, 00:00, 4 Years ago
Mon, Jun 22, 20, 00:00, 4 Years ago
;