IgorAlves
IgorAlves

Reputation: 5556

How to create a tag (like class) inside a option inside a SELECT element?

I have a select box where I could have 2 kinds of options: cars or boats. So I was think to create some like that:

<select>
  <option value="1" class="cars">Car1</option>
  <option value="2" class="boats">Boat1</option>
  <option value="3" class="cars">Car5</option>
  <option value="4" class="cars">Car7</option>
  <option value="5" class="boats">Boat4</option>
</select>

The aim is to identify what class of element was selected using jquery. Once class is an attribute not supported inside "option" what could be the best approach to tag these 2 different classes in this case?

Upvotes: 0

Views: 180

Answers (1)

Quentin
Quentin

Reputation: 944545

Try accurate documentation. The class attribute appears on HTML elements (all of them).

Use a class. It's the standard way to mark an element as part of an arbitrary group.


And much as I dislike W3Schools, it doesn't get this particular issue wrong. The class attribute is mentioned on the other side of the link to Global Attributes.

Upvotes: 1

Related Questions