Add html into select options

I need to add “strong” into select option text, I need to highline text into select content. I set the select option like,

<option value="X"><strong>Name</strong> secondname....</option> 

but select2 delete all html code (strong) in this case… is it possible to add html or strong or span whit css class to get some more options into it.?

I call select2 simple whitout options, and select is complete formated when inicialitaced.

Try custom templating: https://select2.org/dropdown#templating. Depending on what you know about the option text you need to highlight, your custom template callback function might be able to insert the HTML algorithmically, or you might need to store some additional data in the <option> elements that you want to highlight (e.g., via a data-* attribute), which you can then access from within the custom template callback function.

If you need to customize the display of the selected option(s), custom templating works there too: https://select2.org/selections#templating.

1 Like