jquery - Acess element in a nested table -


im trying print policy when of child elements clicked. it's weird list got , trying work cannot display.

 $(".submenu li").click(function() {   alert($(this).text());   alert( $(this).parent().find('li.sub').text());   }); 

i tried

     alert( $(this).parent().find('li.sub').text());      alert($(this).closest('.submenu').closest('a').text());       alert($(this).closest('.submenu').closest('sub').find("a").text()); 

http://jsfiddle.net/ettnxuxa/

expected output after clicking child element: alerts "policy"

the parent() method gives immediate parent element. you'd do, try:

alert($(this).parent().parent('.sub').text());

better though, use:

alert($(this).closest('.sub').text());

to child element of .sub use children() method, so:

alert($(this).closest('.sub').children('a').text());

jsfiddle


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

c# - Json.Net Serialize String from URI -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -