开发者

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 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. get ul1 as result


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.


for my it looks like you want to find the first ul as a child of a parent ul.

So try this:

$( 'ul' ).click( function() {
  console.debug( $(this).find('ul').attr('id') );
});


If the UL is a descendant of the span (which is how I understand this problem), you can do this:

$("span").click(function() {
    alert($(this).find("ul").attr("id"));
});

If the UL is always the very next sibling, you can use .next:

$(this).next("ul").attr("id");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜