Problem: If that's actual code, you have duplicate IDs and nothing
based on those IDs will fire correctly.  In which case use classes
instead.  If they're all unique, your function doesn't handle them -
and you'd need to loop through finding the one that fired the event,
and *then* find the next->li text.

Assuming this markup:

<div id="questions-page">
  <div class="question">
    <p>questions goes here</p>
    <ul><li>Answer to it goes here</li></ul>
  </div>

this should work:

$(#questions-page p).click(function(){
  var answer_text = $(this).next(li).text();
  alert('Answer is'+answer_text);
});

You don't need to ID/class everything either, in order to work with
it.  The "#questions-page p" finds all <p>'s inside #questions-page,
and when they're clicked on, it finds the next <li> after the clicked
<p>, and gives you it's text.

On Apr 16, 9:07 pm, Kapse <kapse.nar...@gmail.com> wrote:
> <div id="questions-page">
>    <div id="question">
>    <p>question1</p>
>     <ul>
>      <li>answer1</li>
>     </ul>
>    </div>

Reply via email to