I want to select the parent item when any of the child is clicked. This code is working checked and check.
$(function() { $(\".child\").on(\"click\",function(
Adding the unordered list adds another layer of parent-children. Edit this line:
$parent = $(this).parent().prevAll(".parent");
to this:
$parent = $(this).parent().parent().prevAll(".parent");
to correctly point to your intended parent.