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
javascript jquery
Jul 05 '10 at 15:09
source share
2 answers
 function getIndex(elem) { var $t = $(elem); alert($t.parent().index()); } 
+4
Jul 05 '10 at 15:20
source share

try this one

 function getIndex(elem) { var $i = $(elem).parent(); alert($i.index()); } 
0
Jul 05 '10 at 15:17
source share



All Articles