One of the dropdown in my web page contains many checkbox with following constructs:
<div class="select_item select_action jq1 traverseKeyboard" title="Noida" style="display:table; undefined" data-selid="top_selCl_9" data-parent="cluster_selCl_9" data-check="unchecked" data-ttype="top" data-mainid="selCl" data-val1="9">
<input type="checkbox" name="cl" value="9" style="display:none;" class="selCl_checkbox">
<div class="left check" id="top_selCl_9_check"></div>
<div class="left" style="width:195px;" id="top_selCl_9_val">Noida</div>
<div class="clear_left"></div>
</div>
When I click on checkbox then, I add checked="checked"
to the checkbox. Whole HTML change is as below:
<div class="select_item select_action jq1 traverseKeyboard" title="Noida" style="display:table; undefined" data-selid="top_selCl_9" data-parent="cluster_selCl_9" data-check="unchecked" data-ttype="top" data-mainid="selCl" data-val1="9">
<input type="checkbox" name="cl" value="9" style="display:none;" class="selCl_checkbox" checked="checked">
<div class="left check selected" id="top_selCl_9_check"></div>
<div class="left" style="width:195px;" id="top_selCl_9_val">Noida</div>
<div class="clear_left"></div>
</div>
Now I used jQuery(".selCl_checkbox").filter(":checked");
to get checked checkboxes. It shows different behavior.
Case 1: When I first opened the dropdown, then checkbox is same as mentioned in code 1, and my jQuery code returns the same as I need, i.e. a blank array (because no checkbox is selected).
Case 2: When I checked any checkbox, code is same as in code snippet 2, and again jQuery code returned desired result, i.e. array of checkboxes selected.
Case 3: Again I deselected, got blank array.
Case 4: Again I selected the same checkbox that was previously selected, HTML is same as in code snippet 2, but this time jQuery returned blank array. If I select multiple checkboxes, then all other checkbox is returned in array, except this one (the one which gone under cycle of checked, unchecked and again checked)
Can anyone please help me in this case (Case 4)?
Aucun commentaire:
Enregistrer un commentaire