jquery - Skip the control while find using data attribute of parent control -


i have couple of check boxes , have find checked check boxes need skip has 'unknown' data attribute of check box's parent control(span). cannot add data attribute check box because of other limitations.

html code

<ul>     <li class="race">         <span caption="other" data-originalname="a">         <input type="checkbox" id="chk1" onclick="selection();" />         <label for="chk1">a</label>     </li>     <li class="race">         <span caption="other" data-originalname="b">         <input type="checkbox" id="chk2" onclick="selection();"/>         <label for="chk2">b</label>     </li>     <li class="race">         <span caption="other" data-originalname="c">         <input type="checkbox" id="chk3" onclick="selection();"/>         <label for="chk3">c</label>     </li>     <li class="race">         <span caption="other" data-originalname="d">         <input type="checkbox" id="chk4" onclick="selection();"/>         <label for="chk4">d</label>     </li>     <li class="race">         <span caption="other" data-originalname="unknown">         <input type="checkbox" id="chk5" onclick="selection();"/>         <label for="chk5">unknown</label>     </li> </ul> 

jquery code

var arrselectedraces=$(".race").find("input[type=checkbox]:not(:parent[data-originalname='unknown']):checked") 

what missing in jquery script?

you can use .filter().

in function passed .filter(), check if closest span (the parent) has data-originalname attribute of 'unknown'. if so, return true otherwise return false.

$('.race').find('input:checkbox').filter(function(){     return $(this).closest('span').attr('data-originalname') != 'unknown'; }); 

jsfiddle


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -