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 & That
How can I get Select2 to show the specialchar correctly?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With