[英]get the child ul id
in my tree structure when a sibling is added (ul) (li) (div) span node name span (/div) (/li) ............... this strucutre goes on at one level when i add a child than the strucutre becomes like this 在我的树状结构中,添加同级时(ul)(li)(div)span节点名称span(/ div)(/ li)......此结构在当我添加一个孩子而不是结构时,一个层次变得像这样
(ul)
(li)
(div)
span node name span(selected)
(ul id="ul1")
(li)
(div)
(span) child node name(/span)
(/div)
(/li)
(/div)
....................... it goes on untill there is one more level added. .......................一直持续到再添加一个级别为止。 the thing is that i want to get the id of child ul when the parent span is selected. 事实是,当选择父跨度时,我想获取子ul的ID。 get ul1 as result 得到ul1作为结果
If the UL is a descendant of the span (which is how I understand this problem), you can do this: 如果UL是跨度的后代(这是我对这个问题的理解),则可以执行以下操作:
$("span").click(function() {
alert($(this).find("ul").attr("id"));
});
If the UL is always the very next sibling, you can use .next
: 如果UL始终是下一个兄弟,则可以使用.next
:
$(this).next("ul").attr("id");
When you select it you can grab it, for example: 选择它后,您可以抓住它,例如:
$("span").click(function() {
var ulID = $(this).siblings("ul").attr("id");
});
In your case it appears to be a sibling, so .siblings()
would be appropriate. 在您的情况下,它似乎是同级的,所以.siblings()
是合适的。
for my it looks like you want to find the first ul
as a child of a parent ul
. 我它看起来像你想找到的第一个ul
作为父母的孩子ul
。
So try this: 所以试试这个:
$( 'ul' ).click( function() {
console.debug( $(this).find('ul').attr('id') );
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.