So here is the function:

<script type="text/javascript">
        (function($) {
  $.toc = function(tocList) {

    $(tocList).addClass('jquery-toc');
    var tocListArray = tocList.split(',');
    $.each(tocListArray, function(i,v) { tocListArray[i] = $.trim
(v); });

    var $elements = $('.jquery-toc');

    $('body').append('<div></div>');
    var $toc = $('body div:last');

    var lastLevel = 1;

    $toc.append('<ul class="jquery-toc-1"></ul>');

    $elements.each(function() {
      var $e = $(this);
      var text = $e.text();
      var anchor = text.replace(/ /g,'-');

      $e.before('<a name="' + anchor + '"></a>');

      var level;

      $.each(tocListArray, function(i,v) {
        if (v.match(' ')) {
          var vArray = v.split(' ');
          var e = vArray[vArray.length - 1];
        } else { e = v; }
        if ($e.is(e)) { level = i+1; }
      });

      var className = 'jquery-toc-' + level;

      var li = '<li><a href="#' + anchor + '">' + text + '</a></li>';

      if (level == lastLevel) {
        $('ul.' + className + ':last',$toc).append(li);
      } else if (level > lastLevel) {
        var parentLevel = level - 1;
        var parentClassName = 'jquery-toc-' + parentLevel;
        $('ul.' + parentClassName + ':last',$toc).
          append('<ul class="' + className + '"></ul>');
        $('ul.' + className + ':last',$toc).append(li);
      } else if (level < lastLevel) {
        $('ul.' + className + ':last',$toc).append(li);
      }

      lastLevel = level;

    });

    var $toc_ul = $('ul.jquery-toc-1',$toc);
    $toc.remove();
    return($toc_ul);

 }

})(jQuery);

          $(document).ready(function(){
                $.toc('#pagecontent_b h1,#pagecontent_b h2,#pagecontent_b
h3').prependTo('#pagecontent_b');
          });
        </script>


It creates a table of content for all the h1, h2, etc on a page. What
i want to do is, to set a number in front of each TOC Element. I cant
use OL's cause the subheader (h2, h3, etc) must be numbered like 1.1.1
or 1.2.1 etc.

Thats one thing. The other thing is, when i did this for a heading, i
want to manipulate the html inside this hx Tag so it exactly shows the
same number as the table of content. That means i have to manipulate
the hx tag and add in front of the "insidehtml" the number. Nothing
more.

thank you
yavuz


On 22 Okt., 15:27, jerome <m...@amosdesigns.net> wrote:
> sorry, but I don't know Rebecca Murphey. Why can't you just wrapper the head
> tag in an ol? or do you need to change the h tag level to a different level?
>
>
>
> ----- Original Message -----
> From: "bc04Inc." <bc04...@googlemail.com>
> To: "jQuery (English)" <jquery-en@googlegroups.com>
> Sent: Thursday, October 22, 2009 1:24 AM
> Subject: [jQuery] How can i set a number inside a h1 tag before the text
>
> starts?
>
> Hi,
> i am using the table of contents function of rebecca murphey. The
> script works fine, but i need to extend itin two ways.
>
> 1. set a number for each toc element?
> 2. set exactly this number to he h1 inner html in fron of the text?
>
> So that the result is:
>
> 1. Head 1
> 2. Head 2
> …
> …
>
> 1. Head 1
> mycontent text djaskdjasödjaskdj aslökjd asd
> dkajsdjaslödkjasdkljasldkjasd
>
> 2. Head 2
> mycontent text sldkasäfasdfkasdjflöasdf
> asdfasdkfjasdfnasdm,fn sdjaf asöd
> ...
>
> Thank you!- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Reply via email to