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>
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.
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.
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.
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
No. According to MDN, this is what is allowed:
Permitted content: Text with eventually escaped characters (like
é
)
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