Is it possible to make the optgroup label selectable?

Asked

Viewed 136 times

3

It is possible to make the option of optgroup label selectable along with the rest of the group options, for example:

 <optgroup label="EUA">
<option value="0">NY</option>
<option value="1">LA</option>

Only the US would also have to be a selectable option, but it still has to be shown as the father of these two options.

  • 2

    I believe this is not possible. You can try to style the select with CSS to achieve a similar result, but the answer accepts of this question of the Soen, it is clear from the comments that this does not work in most navgadores.

  • 1

    I read exactly this question, and I was in doubt, so I’ll have to style my menu myself somehow.. Anyway, thank you, thank you.

  • 1

    It was interesting your question, but not really how to date.

  • Laguma of the answers served you or guided your question @Michelhenriq?

2 answers

2


  • 1

    Yes, I came to the same conclusion by researching at the same time and in the same place as you. : ) +1

  • 1

    The way I found it is to make a Combox with select autocomplete jquery ui, so I can mask this deficiency a little bit in the select part. http://jqueryui.com/autocomplete/#combobox

  • 1

    Maybe you could use Select2, which is a javascript framework. =)

  • 1

    I’ve seen this Select2, but it still doesn’t meet what I need. What I’m going to do is put together a custom array, putting the countries with an H3 to differentiate, and with that, put an autocomplete in the select, if the user type, so it’s easier to interact. Thank you all.

2

I’ve been doing some research, and following a "clue" I found in a comment of one of the answers to the question I posted in the comment above (in the question), I think the reason this is impossible only with simple HTML is as follows:

optgroup has no attribute value.

I mean, it’s not possible because optgroup does not have an attribute value. As you can see here, the only attributes of optgroup sane:

Attribute | Value | Description

disabled | disabled | Specifies that an option-group should be disabled
label | text | Specify the label for an option-group

Browser other questions tagged

You are not signed in. Login or sign up in order to post.