Jacob
Jacob

Reputation: 4031

Can I add custom attributes to an option value in select(drop down)

Is this possible. I fill my drop down from different sources. I was thinking of separating different entries odf adding a custom attribute something like this:

<option value="12" customatrribute: "123" >NAME</option>

Upvotes: 3

Views: 9963

Answers (1)

Mr. Alien
Mr. Alien

Reputation: 157334

The attribute you are using is considered as invalid, if you want to make your own, you need to have data- prefix as it is valid as per HTML5 specification.

From the specification:

A custom data attribute is an attribute in no namespace whose name starts with the string "data-", has at least one character after the hyphen, is XML-compatible, and contains no characters in the range U+0041 to U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z).

So you can use something like

<option value="12" data-customatrribute="123" >NAME</option>

Also note that you need to use = and not :


As you commented, here's the screenshot of the source, it does show up for me enter image description here

Upvotes: 8

Related Questions