Index of a div element
I have the following html:
<div class="rows"> <div class="row"><input type="text" onchange="javascript:getIndex(this);" value="" /></div> <div class="row"><input type="text" onchange="javascript:getIndex(this);" value="" /></div> <div class="row"><input type="text" onchange="javascript:getIndex(this);" value="" /></div> </div> my function:
function getIndex(elem) { var $i = $(elem).parent().parent(); alert($i.index($(elem).parent())); } I keep getting -1, saying that they didn’t find it ... I looked into it and tried to spit out the value in the parent object. (. $ (El) .parent () HTML ()) warning; this returns me a tag with the default value that has been changed ... but if I warn that $ (obj) .val () is completely different. So I think that maybe the reason I keep getting -1.
Has anyone experienced this before?
thank
+2
slik Jul 05 '10 at 15:09 2010-07-05 15:09
source share2 answers
function getIndex(elem) { var $t = $(elem); alert($t.parent().index()); } +4
galambalazs Jul 05 '10 at 15:20 2010-07-05 15:20
source sharetry this one
function getIndex(elem) { var $i = $(elem).parent(); alert($i.index()); } 0
user372551 Jul 05 '10 at 15:17 2010-07-05 15:17
source share