jquery - Getting Div ID on Header Click, Accordion -
i'm using jquery accordion populate dynatree. need accordion div's populate on click of header, why trying grab div id. jquery works when click inside expanded div , not header. makes sense because event .common click.
$(".common").click(function () { var currentid = $(this).attr("id"); alert(currentid); }); <div id="accordion"> <h3>project type</h3> <div id="1" class="common" style="height:150px;"> </div> <h3>ammenities</h3> <div id="2" class="common" style="height:150px;"> </div> </div> i need figure out how can div id on header click. accordion doesn't play nicely if switch id , class onto header, event doesn't fire. i've tried using $("#accordion .common").click , doesn't work either
you can target h3 elements previous sibling of .common element
$(".common").prev('h3').click(function () { var currentid = $(this).next().attr("id"); alert(currentid); }); demo: fiddle
or can target h3 elements children of #accordion element
$("#accordion > h3").click(function () { var currentid = $(this).next().attr("id"); alert(currentid); }); demo: fiddle
Comments
Post a Comment