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()); 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());
Comments
Post a Comment