Here we are showing how the script can handle raw markup, adding the classes on the fly
Also showing the use of "noLinks" to keep from adding the +/x links to the second section
In this case, all the containers - div, ul, fieldset, paragraph - have a class of 'myfaq', and we simply call
$('.myfaq').makefaq();
to apply it to all of them at once!

Simple nested divs

This set is simply divs, no class preassigned or anything!... see the source:

<div class="myfaq">

<div>
<div>This set is simply divs, no class preassigned or anything!... see the source: </div>
<div>
<p>&lt;div class=&quot;myfaq&quot;&gt;</p>
<p>&lt;div&gt;<br>
&lt;div&gt;This set is simply divs... see the source: &lt;/div&gt;<br>
&lt;div&gt;This should be an answer&lt;/div&gt; <br>
&lt;/div&gt;</p>
<p>&lt;div&gt;<br>
&lt;div&gt;How is it working? &lt;/div&gt;<br>
&lt;div&gt;The faq script is adding the classes to our markup for us&lt;/div&gt; <br>
&lt;/div&gt;</p>
<p>&lt;div&gt;<br>
&lt;div&gt;This is a question &lt;/div&gt;<br>
&lt;div&gt;This should be an answer&lt;/div&gt; <br>
&lt;/div&gt;</p>
<p>&lt;div&gt;<br>
&lt;div&gt;This is a question &lt;/div&gt;<br>
&lt;div&gt;This should be an answer&lt;/div&gt; <br>
&lt;/div&gt;</p>
<p>&lt;/div&gt;</p>
</div>
</div>

<div>

How is it working?
The faq script is adding the classes to our markup for us
How does it do that?
It looks for children of the element that is initially called by makefaq(),
and sets up the classes as needed
What does that code look like?
// first, we find the children of the faq container that are not <a> links
var faqch = $(this).children('*:not(a)');
// then we add the class of "faq" to those children
$(faqch).addClass('faq');
// the first element of any kind inside the 'faq' gets the class of 'qq'
$('.faq > *:first-child').addClass('qq');
// all other elements get a class of 'aa'
$('.faq > *:not(.qq)').addClass('aa');
// find the all the 'qq' in the current faq container
var fqq = $(this).children().children('.qq');
if the class is not 'noLinks', add the links!
var fcl = $(this).attr('class');
if (!(fcl.match('noLinks'))){
$(sh).insertBefore(fqq);
//$(sh).prepend($(this).children($('.faqList:not(.noLinks) > .qq'))); };

UL / LI with <p> for question and answer, no x/+ links shown

Fieldset container

Classes preassigned in markup, works either way

This section has all the classes preassigned...
... and it still works!
This is another question - it loads open with class oo
This is another answer - loaded open
See the markup

<div id="sample4" class="myfaq">

<div class="faq">
<div class="qq">
This section has all the classes preassigned...
</div><!-- / q -->
<div class="aa">
... and it still works!
</div><!-- / a -->
</div><!-- / faq -->

<div class="faq oo">
<div class="qq">
This is another question - it loads open with class oo
</div>
<!-- / q -->
<div class="aa">
This is another answer - loaded open
</div><!-- / a -->
</div><!-- / faq -->

<div class="faq">
<div class="qq">
See the markup
</div><!-- / q -->
<div class="aa">
--markup--
</div><!-- / a -->
</div><!-- / faq -->

<div class="faq">
<div class="qq">
This could be a question. Wanna bet?
</div><!-- / q -->
<div class="aa">
Nope! You lose.
</div><!-- / a -->
</div><!-- / faq -->

</div>

This could be a question. Wanna bet?
Nope! You lose.

<p> container with <span> for questions / answers

This is a <span> with nested spans inside, no preassigned classes Something else This is a question, loaded open with class "oo" This is the answer