How escape single quote with jQuery Template

450 Views Asked by At

With jQuery Template I process this string

$.tmpl('regionTemplate', {value: key, title: value.name});

if value.name have a single quote, example L'Aquila jQuery template not rendering string

2

There are 2 best solutions below

0
flowtron On
value.name.replace( "'", "\'" )
0
BorisMoore On

The syntax $.tmpl('regionTemplate', {value: key, title: value.name}); is incomplete. Are you using appendTo or similar?

 $.tmpl('regionTemplate', {value: key, title: value.name}).appendTo( "#myContainer" );

See archived docs

You should not need to escape the '. ${title} in the template will render correctly. (See this sample, for example). Otherwise, you need to show your code and template, or create a jsfiddle to show your problem...