javascript - Get index of elements nested in different divs -
is possible index of checked input, of them nested in different divs. eg such situation:
<div class="parent"> <div> <input></input> <input></input> <input></input> </div> <div> <input checked="checked"></input> <input></input> <input></input> </div> </div>
so checked input show
index = 3
how build such selector? possible? or can show index of children nested directly withing same parent?
try invoke .index()
on entire collection passing target element,
var inputs = $(".parent input:checkbox"); var index = inputs.index(inputs.filter(":checked")); //3
demo
a demonstration valid html given here.
Comments
Post a Comment