Multiple DIV slides using Jquery

Multiple DIV slides using Jquery

Hello,

Im very new in Jquery and I was wondering if somebody can help me.

I got from the next link a DIV slide what I wanna use:

Only, not next to eachother but above eachother

1. Question
Answer
2. Question
Answer
----------->
14. Question
Answer

The next I have:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. <style type="text/css">
  7. .targetDiv {
  8.     display: none
  9. }
  10. </style>
  11. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  12. <script type="text/javascript" language="javascript">
  13. jQuery(function () {
  14.     jQuery('.showSingle').click(function () {
  15.         var index = $(this).parent().index(),
  16.             newTarget = jQuery('.targetDiv').eq(index);
  17.         jQuery('.targetDiv').not(newTarget).slideUp('fast')
  18.         newTarget.delay('fast').slideToggle('fast')
  19.         return false;
  20.     })
  21. });
  22. </script> 



  23. </head>

  24. <body>
  25. <!--put each <a> inside a div-->
  26. <div id="one"><a href="#" class="showSingle" target="1">Div 1</a>
  27. <div id="div1" class="targetDiv">Lorum Ipsum1</div>
  28. </div>

  29. <div id="two"><a class="showSingle" target="2">Div 2</a>
  30. <div id="div2" class="targetDiv">Lorum Ipsum2</div>
  31. </div>

  32. <div id="three"><a class="showSingle" target="3">Div 3</a>
  33. <div id="div3" class="targetDiv">Lorum Ipsum3</div>
  34. </div>

  35. <div id="four"><a class="showSingle" target="4">Div 4</a>
  36. <div id="div4" class="targetDiv">Lorum Ipsum4</div>
  37. </div>
  38. </td>


  39. </body>
  40. </html>
But when I put some <p> above my first DIV He wont show the first DIV but he will show the 2nd DIV.

How is that possible? And what am I doing wrong?

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. <style type="text/css">
  7. .targetDiv {
  8.     display: none
  9. }
  10. </style>
  11. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  12. <script type="text/javascript" language="javascript">
  13. jQuery(function () {
  14.     jQuery('.showSingle').click(function () {
  15.         var index = $(this).parent().index(),
  16.             newTarget = jQuery('.targetDiv').eq(index);
  17.         jQuery('.targetDiv').not(newTarget).slideUp('fast')
  18.         newTarget.delay('fast').slideToggle('fast')
  19.         return false;
  20.     })
  21. });
  22. </script> 



  23. </head>

  24. <body>
  25. <p>
  26. <p>
  27. <p>
  28. <p>
  29. <!--put each <a> inside a div-->
  30. <div id="one"><a href="#" class="showSingle" target="1">Div 1</a>
  31. <div id="div1" class="targetDiv">Lorum Ipsum1</div>
  32. </div>

  33. <div id="two"><a class="showSingle" target="2">Div 2</a>
  34. <div id="div2" class="targetDiv">Lorum Ipsum2</div>
  35. </div>

  36. <div id="three"><a class="showSingle" target="3">Div 3</a>
  37. <div id="div3" class="targetDiv">Lorum Ipsum3</div>
  38. </div>

  39. <div id="four"><a class="showSingle" target="4">Div 4</a>
  40. <div id="div4" class="targetDiv">Lorum Ipsum4</div>
  41. </div>
  42. </td>


  43. </body>
  44. </html>
Now it wont show anything.....

Kind regards,
Steven.