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:
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Untitled Document</title>
- <style type="text/css">
- .targetDiv {
- display: none
- }
- </style>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
- <script type="text/javascript" language="javascript">
- jQuery(function () {
- jQuery('.showSingle').click(function () {
- var index = $(this).parent().index(),
- newTarget = jQuery('.targetDiv').eq(index);
- jQuery('.targetDiv').not(newTarget).slideUp('fast')
- newTarget.delay('fast').slideToggle('fast')
- return false;
- })
- });
- </script>
-
-
-
- </head>
-
- <body>
- <!--put each <a> inside a div-->
- <div id="one"><a href="#" class="showSingle" target="1">Div 1</a>
- <div id="div1" class="targetDiv">Lorum Ipsum1</div>
- </div>
-
- <div id="two"><a class="showSingle" target="2">Div 2</a>
- <div id="div2" class="targetDiv">Lorum Ipsum2</div>
- </div>
-
- <div id="three"><a class="showSingle" target="3">Div 3</a>
- <div id="div3" class="targetDiv">Lorum Ipsum3</div>
- </div>
-
- <div id="four"><a class="showSingle" target="4">Div 4</a>
- <div id="div4" class="targetDiv">Lorum Ipsum4</div>
- </div>
- </td>
-
-
- </body>
- </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?
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Untitled Document</title>
- <style type="text/css">
- .targetDiv {
- display: none
- }
- </style>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
- <script type="text/javascript" language="javascript">
- jQuery(function () {
- jQuery('.showSingle').click(function () {
- var index = $(this).parent().index(),
- newTarget = jQuery('.targetDiv').eq(index);
- jQuery('.targetDiv').not(newTarget).slideUp('fast')
- newTarget.delay('fast').slideToggle('fast')
- return false;
- })
- });
- </script>
-
-
-
- </head>
-
- <body>
- <p>
- <p>
- <p>
- <p>
- <!--put each <a> inside a div-->
- <div id="one"><a href="#" class="showSingle" target="1">Div 1</a>
- <div id="div1" class="targetDiv">Lorum Ipsum1</div>
- </div>
-
- <div id="two"><a class="showSingle" target="2">Div 2</a>
- <div id="div2" class="targetDiv">Lorum Ipsum2</div>
- </div>
-
- <div id="three"><a class="showSingle" target="3">Div 3</a>
- <div id="div3" class="targetDiv">Lorum Ipsum3</div>
- </div>
-
- <div id="four"><a class="showSingle" target="4">Div 4</a>
- <div id="div4" class="targetDiv">Lorum Ipsum4</div>
- </div>
- </td>
-
-
- </body>
- </html>
Now it wont show anything.....
Kind regards,
Steven.