Automatically create drop-down menu with links to the list items at the beginning of long lists


/ Published in: jQuery
Save to your folder(s)

The name of the link should be in strong (or you may change this in the script)


Copy this code and paste it in your HTML
  1. $('#publications').prev(':header').css('float','left');
  2. $('#publications').before('<select id="toc" class="jumpmenu"></select>');
  3. $("#publications li strong").each(function(i) {
  4. $(this).attr("id", i+1);
  5. $("#toc").append("<option value='#"+(i+1)+"'>"+$(this).text()+"</option>");
  6. });
  7. $(".jumpmenu").change(function() {
  8. window.location.href = $(this).val();
  9. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.