[jQuery] fundamentals: .index(obj) or better solution
.index() is driving me nuts, and I'm trying to figure out if there's an
obvious solution to what I'm trying to do, or if I'm missing something
in the API.
Let's say I have the following:
<div name="list">
<div class='list_item'>
<input type='hidden' name='id[]' value='1'>
// interface
</div>
<div class='list_item'>
<input type='hidden' name='id[]' value='2'>
// interface
</div>
<div class='list_item'>
<input type='hidden' name='id[]' value='3'>
// interface
</div>
<div class='list_item'>
<input type='hidden' name='id[]' value='4'>
// interface
</div>
</div>
How do I determine the current element position of a particular
list_item in that container, using jQuery?
Using .index(), it seems like this should work:
// div i want to find
id = 3;
// get the element i want to move
var curr_obj = $("input[@name='id[]'][@value='"+id+"']").parent().get();
// determine its current location within the set of list_items
var old_pos = $("#list").index(curr_obj);
...or a number of other combinations I've tried, and none of them can
get anything but -1 from .index().
What am I doing wrong here?
- Does .get() really return an element object? (It seems to.)
- What kind of object is .index() looking for?
--
| Michael Crowl
| Web Developer
| octopus@serv.net
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/