You can target the h3
elements which are the previous sibling of a .common
element
$(".common").prev('h3').click(function () {
var currentID = $(this).next().attr("id");
alert(currentID);
});
Demo: Fiddle
or you can target the h3
elements which are the children of #accordion
element
$("#accordion > h3").click(function () {
var currentID = $(this).next().attr("id");
alert(currentID);
});
Demo: Fiddle