문제

Hey guys I was just wondering whether there is a way to find out what Unordered List the List Item is in? So like for example I have a UL with the ID 1 and another one with the ID 2 and I'd have the List Items under both Unordered List sortable but on update I want to find out what Unordered List the List Item has been left in.

How Would I do this?

도움이 되었습니까?

해결책

Your best bet would be to use closest rather than parents in case you have nested lists. closest will only return the nearest ancestor matching the selector as opposed to parents which will return all ancestors matching (potentially multiple instead of just one).

Assuming in your case this is your li:

$(this).closest("ul");

다른 팁

you can use the parents() method for that

$("#ID1").parents("ul");

just find its parent ul using parent()

$("li").parents("ul");

Demo Fiddle

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top