Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
150
rated 0 times [  156] [ 6]  / answers: 1 / hits: 20163  / 10 Years ago, sat, august 2, 2014, 12:00:00

I use bootstrap and create html nodes which contain popovers with jQuery. The popovers contain html so that I have problems with the quotes and escaping:



var content = '<input type=text ng-model=test1 />';
var txt = '<button type=button data-container=body ' +
'data-toggle=popover title=myTitle data-html=true '+
'data-content='+content+'>Click</button>';


How can I escape the double quotes inside the attributes => html-attributes? in the data-content attribute correctly?



Edit: I compile the code with angular so that it should also work with it.


More From » angularjs

 Answers
18

If it is HTML, you can use HTML entities to escape characters that might be interpreted otherwise. For example, &quot; will be displayed as in HTML attributes:



var content = '<input type=&quot;text&quot; ng-model=&quot;test1&quot; />';


Proof of concept: http://jsfiddle.net/teddyrised/5X5Ye/



Refer to W3C's HTML entities chart for more information: http://dev.w3.org/html5/html-author/charref


[#69947] Thursday, July 31, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jenamackennac

Total Points: 304
Total Questions: 110
Total Answers: 107

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
jenamackennac questions
Fri, Feb 18, 22, 00:00, 2 Years ago
Wed, Apr 21, 21, 00:00, 3 Years ago
Thu, Apr 1, 21, 00:00, 3 Years ago
Tue, Feb 2, 21, 00:00, 3 Years ago
;