0

I need to create list elements with numbered as (a) , (b) , etc....

I have tried as below

<ol type="a">
<li>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</li>
<li> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</li>
</ol>

However rather than having a. ... and b. ... I want (a) ... and (b) ....

Is there a special type for numbered letter list with brackets around?

Need it to work on IE7 also

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Hello Universe
  • 3,248
  • 7
  • 50
  • 86

2 Answers2

1

IE 7 Workaround (?)

var i =0;
                                                        // A is #65 in Unicode
$("ol").children()
       .prepend('<span class="li-counter">(' + String.fromCharCode(64+(i++)) + ')' );

Generaly, people uses CSS counters and ":before" pseudo-element.

ol {
    counter-reset: my-counter;
}
ol li:before {
    content: "(" counter(my-counter, lower-alpha) ")"; 
    counter-increment: my-counter;
    margin-right: 5px;
    font-weight: bold;

}

There is a similar question about custom ol numbering: Ordered list (HTML) lower-alpha with right parentheses?

http://jsfiddle.net/dd63m/10/

Community
  • 1
  • 1
nvsnkv
  • 21
  • 5
0

No, there is no HTML way to generate numbering such as “(a)”. The type attribute of ol has a very limited set of values. There are some more values for the corresponding CSS construct, the list-style-type property, but even for it, it’s a matter of setting the style of “numbers”, not punctuation around them.

The usual approach nowadays is to use CSS counters and generated content, but that does not work on IE 7.

Assuming the markup and content cannot be changed, this leaves just the JavaScript way. You would then replace the ol element e.g. by a div element, with the li elements changed to div elements, with content like “(a)” prepended to them, and with suitable styling (margins).

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390