How to get list item (<li>) marker/label declared in list-style-type?
Asked Answered
G

1

16

Lets say I have a list like this:

<ul style="list-style-type: upper-latin;">
  <li>Lorem</li>
  <li>Ipsum</li>
</ul>

(list-style-type might be anything - upper-roman, katakana, lower-greek)

list-style-type: upper-latin; will put a alphabet letter (starting from A) in front of every list item. Is there a way to get this letter for any given list item? I can probably iterate over list using jQuery .index() or similar.

Or, maybe there is way to extract markers from style?

The answer here works only for Latin alphabet lists.

Gemsbok answered 25/10, 2012 at 6:48 Comment(5)
"The answer here works only for Latin alphabet lists." --- and why it doesn't work for you?Merely
upper-latin generates exactly the same letters as lower-alpha. Only for uppercase you have to start from 65 instead of 97. ascii-code.comCirri
I forgot to mention, the list-style-type is unknown. It might be upper-roman or katakana.Gemsbok
Ok, my bad, I was too fast. Concluding there was only one type. I only see a hardcoding way at the moment. Get the the list-style-type and depending on the type get the sequence from a list that you created. But hardcoding is a word I dont like.Cirri
have you checked if this css solution sugested here would work for you? #1770982Proust
S
2

Is there a way to get this letter for any given list item?

Yes. You can read the list-style-type and generate what characters are showing for each style type. Which character is shown for a specific item number and style type could vary across browsers though.

Or, maybe there is way to extract markers from style?

No. (At least not currently)

Some useful stuff for writing a generator:

Also, many of the list-styles are uppercase versions of other list styles. Could be good to know then that myString.toUpperCase() works on unicode characters as well. :)

Shippen answered 25/10, 2012 at 7:5 Comment(5)
Is it possible to generate characters for specific styles? How? Or I have to store all the characters sets for every style locally and map them to style names (doesn't sound too exciting)?Gemsbok
They would quite possibly be predictable, you'd have to explore each character set to search for patterns. Greek for example follows the unicode α, β, γ... or U+03B1, U+03B2, U+03B3... Helpful: en.wikipedia.org/wiki/List_of_Unicode_charactersShippen
you should use something like @Shippen propose, there is no way to do something like $(li).('list-style-value'); :/Gauguin
@Tom I'm afraid so. I thought that there would be something more simpler or elegant, but, oh well =)Gemsbok
Added some resources to my answer.Shippen

© 2022 - 2024 — McMap. All rights reserved.