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");