Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to add <div> or <span> inside an <option> tag? [duplicate]

how can i add <div> or a <span> tag inside an <option> tag?

I want the row to be <option> of course it has a value and everything, but I need to put a circle red color next to the text in that option, is that possible?

code like:

<option value="1">text<div style='background:none repeat scroll 0 0 green;height:25px;width:25px;'></div></option> <option value="2">text<div style='background:none repeat scroll 0 0 green;height:25px;width:25px;'></div></option> <option value="3">text<div style='background:none repeat scroll 0 0 green;height:25px;width:25px;'></div></option> <option value="4">text<div style='background:none repeat scroll 0 0 green;height:25px;width:25px;'></div></option> 
like image 472
Abude Avatar asked Aug 09 '12 19:08

Abude


People also ask

Can you put span inside option?

So depending on context there are two things that you can put inside an <option> — text or nothing at all — you may not put a <span> or any other element there. An option element cannot have any child elements.

Which attribute Cannot be used inside option tag?

Definition and Usage. The <option> tag defines an option in a select list. <option> elements go inside a <select>, <optgroup>, or <datalist> element. Note: The <option> tag can be used without any attributes, but you usually need the value attribute, which indicates what is sent to the server on form submission.

Can we use div in select tag?

i.e. There is an element called "SELECT", the start tag is required, the end tag is required. It's children can be OPTGROUP elements and/or OPTION elements and there must be at least one of them. Since a DIV is not an OPTGROUP or an OPTION, the answer is no.


2 Answers

2019 UPDATE

This solution doesn't work anymore.

Checked in latest Chrome, Firefox and Safari.


It is possible to put a red circle after the text - http://jsfiddle.net/V8cvQ/

option:after {     content: " ";     height: 5px;     width: 5px;     background: #c00;     border-radius: 5px;     display: inline-block; } 

...

UPDATE

To have different color dots

HTML

<select>     <option> select </option>     <option class="red"> one </option>     <option class="green"> two </option>     <option class="blue"> three </option> </select> 

CSS

option:after {     content: " ";     height: 5px;     width: 5px;     border-radius: 5px;     display: inline-block; }  option.red:after { background: #c00; } option.green:after { background: #0c0; } option.blue:after { background: #00c; } 

DEMO

like image 65
Zoltan Toth Avatar answered Sep 20 '22 21:09

Zoltan Toth


No. According to MDN, this is what is allowed:

Permitted content: Text with eventually escaped characters (like &eacute;)

like image 31
Dave Avatar answered Sep 21 '22 21:09

Dave