/    Sign up×
Community /Pin to ProfileBookmark

Can I add tag in options for select elements?

I want to add html tags in options. For example:
`<select>
<option value=”one”><b>testing 1</b></option>
<option value=”two”> <span style=”color:red;”>testing2</span></option>
</select>`

Is it possible?

to post a comment
CSSHTMLJavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@cootheadJun 26.2020 — It is not possible.

_coothead_
Copy linkTweet thisAlerts:
@JMRKERJun 26.2020 — Cannot do it with a HTML tag, but could achieve the desired results with:
``<i>
</i>&lt;select&gt;
&lt;option value="one" style="font-weight:bold"&gt;testing 1&lt;/option&gt;
&lt;option value="two" style="color:red"&gt;testing 2&lt;/option&gt;
&lt;option&gt;testing 3&lt;/option&gt;
&lt;/select&gt;<i>
</i>
``

Or put the style stuff into a class option
Copy linkTweet thisAlerts:
@cootheadJun 26.2020 — > @JMRKER#1619956

> **[color=#069]....but could achieve the desired results with:[/color]**


That may well work in Chrome but it certainly does not work in Firefox.

My original answer should have read...

[b]It is not possible with any cross browser reliability[/b].

I thought, though, that you might have suggested an alternative

approach to the problem, as you discussed here...

[url=https://forums.cutcodedown.com/index.php?topic=67.0]**[color=#069][u]Alternate select submission[/u][/color]**[/url]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@JMRKERJun 27.2020 — I tested with FF and it worked with the version I'm using.

I neglected to test it with Chrome initially, but it too now seems to work.

What am I looking at that is wrong?


It does not perform the titled action of the post about using the <del> tag,

but it did change the color displays of the options per the OP's initial code.
Copy linkTweet thisAlerts:
@cootheadJun 27.2020 — > @JMRKER#1620005

> **[color=#069]I tested with FF and it worked with the version I'm using.[/color]**

>
Well it certainly does not work in my Firefox 77.0.1(64bit) browser. :D

_coothead_
Copy linkTweet thisAlerts:
@JMRKERJun 27.2020 — 'Tis interesting ... I'm using the same version of FF (??? 😕 )

Chrome Version 83.0.4103.116 is OK too.

Nothing to argue about as I have no use for it anyway.
Copy linkTweet thisAlerts:
@VITSUSAJun 29.2020 — @shobha#1619946 I agree with coothead, it is not possible with any cross-browser reliability, and this is not possible in the Firefox browser also but I have tried in Chrome Version 83.0.4103.116 it is OK too.
Copy linkTweet thisAlerts:
@siddhi_patelJun 29.2020 — hello..

No it is not possible to add <del> teg in option for select elements .
Copy linkTweet thisAlerts:
@JMRKERJun 29.2020 — There seems to be some mis-understanding here.

The code of the first post by the OP shows use of the <b> and <span> tags.

Only place <del> is mentioned is in the title of the post. No reference anywhere else.

I never indicated that <del> could be used in this example.

My answer related ONLY to the boldness and colors of the options where I removed the HTML tags.

I replaced with CSS substitutes in the original code example, which I interpreted as part of the request.

So my believe is that in the words of Strother Martin

in Cool Hand Luke: "What we have here is a failure to communicate". 😆
Copy linkTweet thisAlerts:
@cootheadJun 29.2020 — Hi there shobha,

as the ``select and option elements`` cannot be

styled with any cross-browser reliability it would

be prudent to look for alternative methods.

Here is just one example...
<i>
</i>&lt;!DOCTYPE HTML&gt;
&lt;html lang="en"&gt;
&lt;head&gt;

&lt;meta charset="utf-8"&gt;
&lt;meta name="viewport" content="width=device-width,height=device-height,initial-scale=1"&gt;

&lt;title&gt;Untitled document&lt;/title&gt;

&lt;link rel="stylesheet" href="screen.css" media="screen"&gt;

&lt;style media="screen"&gt;
body {
background-color: #f0f0f0;
font: normal 1em / 1.6em sans-serif;
}

form {
max-width: 30em;
margin: auto;
}

#field1 {
position: relative;
margin-bottom: 0.5em;
border: 1px solid #999;
background-color: #eef;
}

#field1 legend {
padding: 0;
border: 1px solid #999;
border-radius: 0.4em;
background-color: #fff;
}
#field1 legend label{
padding-right: 1em;
margin: 0;
border: 0;
}

#field1 input {
position:absolute;
opacity:0;
top: 1em;
left:1em;
}

#field1 label{
display: block;
margin: 0.25em 0;
border: 1px solid #999;
border-radius: 0.4em;
background-color: #fff;
cursor: pointer;
}

#field1 label:hover,
#field1 label:active {
background-image: linear-gradient( to bottom, #fff, #fec );
}

#field1 legend label:hover,
#field1 legend label:active {
background-image: none;
}

#field1 label::before,
#field1 legend input:checked + label::before {
content: '2713';
font-size: 1.5em;
opacity: 0;
}

#field1 input:checked + label::before {
opacity: 1;
}

label[for="r0"] {
font-weight: bold;
}

label[for="r1"] {
color: #f00;
}

label[for="r2"] {
font-style: oblique;
color: #00f;
}

input[type="submit"] {
padding: 0.5em 1em;
border: 1px solid #040;
border-radius: 0.4em;
font-size: 1.5em;
background-color: #008000;
color: #fff;
}
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;form action="?"&gt;
&lt;fieldset id="field1"&gt;
&lt;legend&gt;
&lt;input id="rx" name="item" type="radio" value="no-selection-made" required&gt;
&lt;label for="rx"&gt;Select items&lt;/label&gt;
&lt;/legend&gt;
&lt;input id="r0" name="item" type="radio" value="item one"&gt;
&lt;label for="r0"&gt;Item one&lt;/label&gt;
&lt;input id="r1" name="item" type="radio" value="item two"&gt;
&lt;label for="r1"&gt;Item two&lt;/label&gt;
&lt;input id="r2" name="item" type="radio" value="item three"&gt;
&lt;label for="r2"&gt;Item three&lt;/label&gt;
&lt;/fieldset&gt;
&lt;input type="submit"&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;


[i]coothead[/i]
×

Success!

Help @shobha spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...