开发者

get the child ul id

开发者 https://www.devze.com 2023-01-29 05:02 出处:网络
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 thi

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

精彩评论

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