Html: new feature suggestion for ordered list

Created on 11 Dec 2020  路  7Comments  路  Source: whatwg/html

it would be possible to make <ol> automatically sort from the values of <li>

<ol>
  <li value="2">Coffee</li>
  <li value="1">Tea</li>
  <li value="3">Milk</li>
</ol>

Most helpful comment

The value attribute for list items already has a specific meaning. Why can't you sort your data yourself before generating the webpage?

All 7 comments

What?

O que?

write <ol> in any way example below

<ol>
  <li value="2">Coffee</li>
  <li value="1">Tea</li>
  <li value="3">Milk</li>
</ol>

and browser would automatically sort automatically from the value of <li> example below

<ol>
  <li value="1">Tea</li>
  <li value="2">Coffee</li>
  <li value="3">Milk</li>
</ol>

Don't give it a value and that's what it will do. The value attribute is specifically for overriding the automatic numbering.

Don't give it a value and that's what it will do. The value attribute is specifically for overriding the automatic numbering.

if you do an example without passing value of <li> in this example Coffee would have an index of 1 and in this example it should be 2

[
  {
    id: 2,
    name: "Coffee"

  },
  {
    id: 1,
    name:"Tea"

  },
  {
    id:3,
    name: "Milk"

  }
]
  1. Coffee
  2. Tea
  3. Milk

The value attribute for list items already has a specific meaning. Why can't you sort your data yourself before generating the webpage?

This could be done in many ways even with JavaScript, but if it had this feature natively the performance would be better, it would also help to differentiate the <ol> and <ul> tags, besides working with JS disabled

SOLUTION

###

Sort on li value in HTML tags directly AS PER ASCII Value.

Was this page helpful?
0 / 5 - 0 ratings