Skip to content

Instantly share code, notes, and snippets.

@LouisWhit
Created July 11, 2013 12:59
Show Gist options
  • Select an option

  • Save LouisWhit/5975231 to your computer and use it in GitHub Desktop.

Select an option

Save LouisWhit/5975231 to your computer and use it in GitHub Desktop.
Dynamic FAQ Maker - HTML has bootstrap tags in it. It is output after the DOM loads by JS that reads the page for h3 tags and dynamically creates the FAQ.
var ToC =
"<div class='well table-of-contents'>" +
"<h2>Question's List:</h2>" +
"<p>Click on any of the questions to go their corresponding answers below or you may just scroll down the page to find the answers you are looking for.</p>"+
"<ul>";
var newLine, el, title, link, id, i = 0;
$('.second-level-content .span8 h3').each(function(){
el = $(this);
title = el.text();
i = i+1;
id = 'FAQ' + i
el.addClass('relative');
el.prepend("<span id='"+id+"' style='position:absolute;top:-50px;'></span>")
el.append("&nbsp;&nbsp;&nbsp;<a class='faq-link' href='#custom1_mod'>Back to Top &uarr;</a>")
link = "#" + id;
newLine =
"<li>" +
"<a href='" + link + "'>" +
title +
"</a>" +
"</li>";
ToC += newLine;
});
ToC +=
"</ul>" +
"</div><div class='row-fluid'><div class='span-12 dashes'>&nbsp;</div></div>";
$(".span8 h1").after(ToC);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment