javascript - Nested ordered lists -


I need a nested list with sub-numbering, such as:

  1 item 1 1.1 - Subtitle 1 1.2 - Subtitle 2 1.3 - Subtitle 3 1.4 - Subtitle 4 1.5 - Subtitle 5 2. Item 2 2.1 - Subtitle 1 2.2 - Subtitle 2 2.3 - Subtitle 3 2.4 - Subtitle 4 2.5 - Subtitle 5  

Well, I know that I can not get it with pure HTML, so it would be great to use something like this and count yourself as a mosaic counting yourself. Ega:

  & lt; Ol & gt; & Lt; Li & gt; Item 1 & lt; Ol & gt; & Lt; Li & gt; Subtitle 1 & lt; / Li & gt; & Lt; Li & gt; Subtitle 2 & lt; / Li & gt; & Lt; Li & gt; Subtitle 3 & lt; / Li & gt; & Lt; Li & gt; Subtitle 4 & lt; / Li & gt; & Lt; Li & gt; Subtitle 5 & lt; / Li & gt; & Lt; / Ol & gt; & Lt; / Li & gt; & Lt; Li & gt; Item 2 & lt; Ol & gt; & Lt; Li & gt; Subtitle 1 & lt; / Li & gt; & Lt; Li & gt; Subtitle 2 & lt; / Li & gt; & Lt; Li & gt; Subtitle 3 & lt; / Li & gt; & Lt; Li & gt; Subtitle 4 & lt; / Li & gt; & Lt; Li & gt; Subtitle 5 & lt; / Li & gt; & Lt; / Ol & gt; & Lt; / Li & gt; & Lt; / Ol & gt;  

Is there a solution to use JavaScript or jQuery or something?

If you want to cross-browser with jQuery:

 < Code> $ ("ol # list ol"). Each (function (i, el) {$ (this). Children () .each (function (ci, cl) {$ (this) .prepend ('& lt; span class = "pseudonym" & gt; + [I + 1, ci + 1]. Include ('.') + '& Lt; / span & gt;');});}) AddClass ('proxy-processed');  

and in your CSS:

  ol .seudo-num {display: none} ol.pseudo-processed {list-style: none; Padding-left: 0} ol.pseudo-processed .seudo-num {display: inline; Font-weight: bold}  

This is for only one level. You can change the code to create recursive functions for many levels.

This is setup to increase your page progressively without JavaScript, it will fallback on normal nested numbering.

UPDATE : @gumbo Thanks for working, I started this code again in a recursive plugin, same as my previous example. Will use CSS, but now it is a "full" jQuery plugin that supports support for any depth:

  $ .fn.outline = function (option, counter) { Var option = $. Extension ({}, $ .fn.outline.defaults, option), counter = counter || []; it () (function () {$ (this). Child ('li'). (Function (i) {var Ct = counters.concat ([i + 1]); if (counter. Length) {$ ('& lt; span & gt; & lt; / span & gt;') .addClass (options.numberClass) .text Ct.join ('.') + '') .prependTo (this);} $ (this) .Kids ('ol') .line (option, whistle);})}); (counter! Length); This.addClass (options.processedClass)} $ .fn.outline.defaults = {numberClass: 'pseudo-number', processed class: 'pseudo-processed'}  

You can call #id :

  $ ("# list"). Outline ();  

Or one Use of the "Perfect Chooser of @Gumbo" to apply it to all ol tags on the page T:

  $ ( "ol: No (li & gt; Ol) "). Outline ();  

And you can either originally override by default or on a personal basis:

  $ .fn.outline.defaults.processedClass = 'ol-ready'; // or $ ("# list"). Outline ({processedClass: 'ol-ready'});  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -