(function($){ $.fn.makeFAQ = function(options) { var defaults = { indexTitle: "Index", faqHeader: ":header", displayIndex: true }; var options = $.extend(defaults, options); return this.each(function() { var $obj = $(this); $obj.wrap("
"); if(options.displayIndex) { $obj.before("

" + options.indexTitle + "

"); }; var $faqEntries = $obj.children(options.faqHeader); var i = 0; $faqEntries.each(function () { var $entry = $(this); var entryName = $entry.text(); var entryNameSafe = entryName.replace(/\W/g,"") + i; i++; var itemHTML = "
  • " + entryName + "
  • "; $('#faqindex ul').append(itemHTML); if(options.displayIndex) { $('#' + entryNameSafe.toString() + 'Index').click( function(){ $('#' + entryNameSafe.toString()).next('span').slideDown('fast'); $('#' + entryNameSafe.toString()).addClass('faqopened'); }); }; $entry.next("div").addClass('faqcontent'); $entry.attr({ title: "Click to expand/collapse", name: entryNameSafe, id: entryNameSafe }) .addClass("faqclosed") .click( function() { $entry.next('div').slideToggle('fast'); $entry.toggleClass('faqopened'); }) .next('div').css({ display: "none" }); }); }); }; })(jQuery); jQuery(document).ready(function() { jQuery('#faq').makeFAQ({ displayIndex: false }); });