tags:

views:

32

answers:

1

How to make this css code cross browser compatible using jquery. this code only works on firefox and IE8. i wan to use in IE6 and 7 also.

ol {list-style-type: none;}
li:before {content: "(" counter(section, lower-alpha) ") ";}
li { counter-increment: section;}

this is html

<ol class"fnotes">    
  <li> item 1 </li>
  <li> item 2 </li>
  <li> item 3 </li>
</ol>

and i need this output

(a) item 1

(b) item 2

(c) item 3

+1  A: 

You can do it like this:

$(function() {
  $("li").each(function(i) {
    $(this).prepend("(" + String.fromCharCode(i + 97) + ") ");
  });
});

Note: 26 character limit :)

In case anyone needs to go crazy high, this goes from (a) to (zz) correctly, that should be plenty of footnotes...

$("li").each(function(i) {
    var prefix = "";
    if(i >= 26) {
        prefix = String.fromCharCode((i / 26 + 96));
        i = (i % 26)
    }
    $(this).prepend("(" + prefix + String.fromCharCode(i + 97) + ") ");
});​​​
Nick Craver
i need like (a) (b). lower alpha with brackets
metal-gear-solid
@jitentra - In that case, why not `list-style-type: lower-alpha`?
Nick Craver
because i need (a) bracket, which is not possible using list-style. see my updated question.
metal-gear-solid
@jitendra - Are there every more than 26 or ignore that case?
Nick Craver
no on one page it can be max a-z.
metal-gear-solid
@jitendra - Updated, you can see it working here: http://jsfiddle.net/HQtdq/
Nick Craver
should i give like $("ol.fnotes li").each(function(i)
metal-gear-solid
@jitendra - Whatever selector you want to match on is fine, are there many footnote groups or just 1? For the multiple case... `$("ol.fnotes").find("li").each(function(i)` so the `i` is respective to the current group instead of overall.
Nick Craver
@Nick - `ol.fotnotes` is one but page has other simple <ol> also . so i want to be specific for `ol` with class `footnotes` only to apply ur solution
metal-gear-solid
Great help for me. applause to Nick and SO community. After google and my email account . SO is the 3rd site which i mostly use
metal-gear-solid