[jQuery] Re: How to select sub element text on clicking the parent element.

2009-04-17 Thread Raja Koduru

*
var answer_text = $(ul li, this).text();
alert(answer is  + answer_text);



does this help?

-raja koduru


[jQuery] Re: How to select sub element text on clicking the parent element.

2009-04-17 Thread enygmari

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
pquestions goes here/p
ulliAnswer 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
    pquestion1/p
     ul
      lianswer1/li
     /ul
    /div