this in your code is the
<body> element, which, of course, doesn't have a "next".
Can you change the HTML?
You need a way to select the summary divs only. Can you give them a CSS class of e.g. "summary". It would probably also be helpful to give the detail divs some common class - e.g. "detail".
Forget about giving each div a unique ID! This is almost always a bad idea, and seldom serves a useful purpose.
- <div class='summary'>lorem ipsum</div>
- <div class'detail'>ipsum lorem</div>
- <div class='summary'>blah blah</div>
- ....
- $(document).on('click', '.summary', function(event){
- var $summary = $(this); // the summary that was clicked on
- var $detail = $summary.next();
- // Here, "do something" with $summary and/or $detail
- });
If you need more help, a concrete example that we can try is more useful. Use jsFiddle. Make it the minimum needed to show the problem. e.g. you only need to show TWO summaries and TWO details, and they can contain minimal, dummy content.
You can learn the basics of jQuery at the jQuery Learning Center:
MDN is a good place to learn more about Javascript: