Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get jquery-select2 to display html entities correctly?

I'm using jquery-select2 4.0.0 and I want to display a text containing an '&'.

This is the code of the option:

<option value="123">
   123 - This & That
</option>

However, Select2 shows the following as the option text:

123 - This &amp; That

How can I get Select2 to show the specialchar correctly?

like image 858
Benni Avatar asked Mar 10 '15 14:03

Benni


1 Answers

You can fix that with the help of escapeMarkup option.

<select id="s2">
    <option value="123">123 - This & That</option>
</select>

<script>
$(document).ready(function() {
    $('#s2').select2({
        escapeMarkup: function (text) { return text; }
    });
});
</script>

Here's the demo on jsfiddle.

You should take a look at this GitHub issue and look for escapeMarkup on the documentation.

like image 66
Luís Cruz Avatar answered Sep 22 '22 07:09

Luís Cruz