jquery - Delete Div and get Hidden field value - best approach -
i have below html sample
<div id="testdiv_0"> <input id="hf_0" type="hidden" value="0"> <span class="checkbox checked"> </div> <div id="testdiv_1"> <input id="hf_1" type="hidden" value="10"> <span class="checkbox checked"> </div> <div id="testdiv_2"> <input id="hf_2" type="hidden" value="23"> <span class="checkbox"> </div>
dynamic html , may grow
am trying implement few logic using jquery.
the scenario if span has class checked.i need implement 2 things
get type="hidden" value in comma seprated field(if multiple span checked). eg: in above html need 0,10 in variable
remove particular div. eg: in above html need remove testdiv_0,testdiv_1.
what best way implement this? tried getting count of div , looping through find class , removed div. thought there better ways.
var arr = $('span.checked').map(function(){ var id = $(this).siblings("input[type='hidden']").val(); $(this).closest('div').remove(); return id; }).get().join(',');
demo -->
http://jsfiddle.net/pendy/
Comments
Post a Comment