because cont1
is not an ancestor of the button
It is the previous sibling of the closest .exp1
element
alert($(this).closest(".exp1").prev('.cont1').attr("id"));
or you can say, you need the cont1
element within the closest wrapper
like(you have a >
in the class name wrapper... remove it)
alert($(this).closest(".wrapper").children('.cont1').attr("id"));
Demo: Fiddle