Ok, this is how my final (?) code look I think it have too many if, a function for make the same thing could help but at least it work and perfectly
$("#toc").addClass("toc derecha"); $("#toc").prepend('<h2 id="toctitle">Tabla de contenidos<\/h2><ul id="genTOC"><\/ul>'); counter = 1; $('*','#main_content').each(function() { if ( $(this).attr('id') !='toctitle' ) { if ( $(this).is("H2") ) { $(this).before('<a name="ref' + counter + '" id="ref' + counter + '"></a>'); $("#toc ul").append('<li class="toclevel-1"><a href="#ref' + counter + '"><span class="tocnumber">' + (counter++) + '. </span><span class="toctext">' + $(this).html() + '</span><\/a><\/li>'); } else if ( $(this).is("H3") ) { $(this).before('<a name="ref' + counter + '" id="ref' + counter + '"></a>'); $("#toc ul").append('<li class="toclevel-2"><a href="#' + $(this).html() + '"><span class="tocnumber">' + (counter++) + '. </span><span class="toctext">' + $(this).html() + '</span><\/a><\/li>'); } else if ( $(this).is("H4") ) { $(this).before('<a name="ref' + counter + '" id="ref' + counter + '"></a>'); $("#toc ul").append('<li class="toclevel-3"><a href="#' + $(this).html() + '"><span class="tocnumber">' + (counter++) + '. </span><span class="toctext">' + $(this).html() + '</span><\/a><\/li>'); } else if ( $(this).is("H5") ) { $(this).before('<a name="ref' + counter + '" id="ref' + counter + '"></a>'); $("#toc ul").append('<li class="toclevel-4"><a href="#' + $(this).html() + '"><span class="tocnumber">' + (counter++) + '. </span><span class="toctext">' + $(this).html() + '</span><\/a><\/li>'); } } }); U need to use a css and put in your html <div id="toc"></div> where u want the toc appear if any1 wanna contrib with my first jquery advanced programation can help lol thx sebastian ----- Original Message ----- From: "Blair Mitchelmore" <[EMAIL PROTECTED]> To: "jQuery Discussion." <discuss@jquery.com> Sent: Friday, March 02, 2007 9:03 PM Subject: Re: [jQuery] get element inside a div simple question If I recall correctly, to get it in order you need to take all elements and then filter manually or do it hierarchically. One way: $('*',main_content).each(function() { if (this.tagName.toLowerCase() == 'h1') // ... else if (this.tagName.toLowerCase() == 'h2') // ... // etc. }); The Other: $('h1',main_content).each(function() { $('h2',this).each(function() { // and so on.. }); }); Which one you use would depend on what your ultimate goal is, though I'm sure either technique can be modified to suit any situation. -blair sebastianw wurtz wrote: > But still isnt what i need i making a auto gen table of content list i > have this > > var main_content = $("#main_content"); > var toBeTOCced = $("h2,h3,h4,h5", main_content); > toBeTOCced.each(function(i) { > ......... > ......... > }); > > * 1. Title 1 > * 3. Title 2 > * 4. Title 3 > * 5. Title 4 > * 6. Title 5 > * 7. Title 2.1 > * 8. Title 2.2 > * 9. Title 4.1 > * 10. Title 4.1 > > Seems to be not in order. Like is usual i need to put the > 2 > 2.1 > 2.2 > .... > ... > > > > > ----- Mensaje original ---- > De: Blair Mitchelmore <[EMAIL PROTECTED]> > Para: jQuery Discussion. <discuss@jquery.com> > Enviado: viernes 2 de marzo de 2007, 20:44:55 > Asunto: Re: [jQuery] get element inside a div simple question > > var main_content = $("#main_content"); > var toBeTOCced = $("h2,h3,h4,h5", main_content); // there it is > > -blair > > sebastianw wurtz wrote: > > I want to get all the Heading element up to 5 (ex |h2,h3,h4,h5| ) > > inside a div like #main_content > > > > something like this, but inside the #main_content > > |var toBeTOCced = getElementsByTagNames('h2,h3,h4,h5');| > > > > How i can do that with jquery? > > > > > > thanks > > > > Sebastián > > > _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ __________ NOD32 2090 (20070302) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com -------------------------------------------------------------------------------- Estoy utilizando la versión gratuita de SPAMfighter para usuarios privados. Ha eliminado 5021 correos spam hasta la fecha. Los abonados no tienen este mensaje en sus correos. ¡Pruebe SPAMfighter gratis ya! _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/