Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use HTML tags in the options for select elements? [duplicate]

Is it possible for the options of an HTML select element to include HTML tags?

For example, given the following code:

 <select>     <option value="one"><b>one is bold</b></option>     <option value="two">two has some <span style='color:red;'>red</span> text</option>     <option value="three">three is just normal</option>  </select> 

I would like the options to actually render in HTML. In this application I can play with HTML, CSS, JavaScript (including jQuery). And the HTML itself is being rendered via Django (django.form.fields.select).

like image 398
trubliphone Avatar asked Jun 28 '12 03:06

trubliphone


People also ask

What are the 3 types of selecting a HTML element?

Simple selectors (select elements based on name, id, class) Combinator selectors (select elements based on a specific relationship between them) Pseudo-class selectors (select elements based on a certain state)

Which tag can be used for selecting one of many choices in HTML?

The <select> Tag.

How do I render select2 options in HTML?

The key here for me is to build a data array with content for both templateSelection and templateResult . The latter renders fine in the dropdown but any multiline content will not be contained in the select2 element so needs to be displayed inline (or at least on a single line).

How select and option works in HTML?

Definition and UsageThe <select> element is used to create a drop-down list. The <select> element is most often used in a form, to collect user input. The name attribute is needed to reference the form data after the form is submitted (if you omit the name attribute, no data from the drop-down list will be submitted).


2 Answers

No, you can't do this. <option> tags cannot contain any other tags.

like image 68
meagar Avatar answered Sep 17 '22 15:09

meagar


No, but this: Styling HTML Select may help you and there a lof of detail and votes here:

How to style a <select> dropdown with CSS only without JavaScript?

like image 39
Michael Durrant Avatar answered Sep 21 '22 15:09

Michael Durrant