user177785
user177785

Reputation: 2269

<div> and <select> tags

Can I have a <DIV> within an HTML <SELECT> tag?

e.g.:

<select tabindex="2" name="agegrp" id="agegrp" >
    <div> 
        <option value="-1">No preference</option>
    </div>
</select>

Upvotes: 3

Views: 10812

Answers (6)

cp3
cp3

Reputation: 2139

As everyone has stated there would be no need to do a div within a select list. if you need to individually move list elements in a form id suggest using radio buttons.

Upvotes: 0

Quentin
Quentin

Reputation: 943518

From the specification:

<!ELEMENT SELECT - - (OPTGROUP|OPTION)+ -- option selector -->

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.

Upvotes: 14

D&#39;Arcy Rittich
D&#39;Arcy Rittich

Reputation: 171401

While you can generate any crazy HTML you want, that is not a recommended use of DIV. What is the problem you are trying to solve by introducing the DIV?

Perhaps you are unaware of the OPTGROUP tag?

The tag is used to group together related options in a select list.

If you have a long list of options, groups of related options are easier to handle for the user.

Upvotes: 0

NickFitz
NickFitz

Reputation: 35031

No, but you may be interested in the optgroup element. Be aware that its appearance tends to vary a lot across different browsers before you start building designs around it though.

Upvotes: 1

Kolten
Kolten

Reputation: 3503

No. And there is no reason to.

Upvotes: 0

Deniz Dogan
Deniz Dogan

Reputation: 26227

No. Nope. Niet.

Upvotes: 4

Related Questions