.index() doesn't do what you think it does. It works like this:
// Find the position of the P that an ID of someP /within/ the list of
p elements.
$("p").index( $("#someP")[0] )
So, in your code it would be something like this:
// div i want to find
id = 3;
// get the element i want to move
var curr_obj = $("[EMAIL PROTECTED]'id[]'[EMAIL
PROTECTED]'"+id+"']").parent()[0];
// determine its current location within the set of list_items
var old_pos = $("div.list_item").index(curr_obj);
So two things to note: .get() returns an array of elements, not just a
single element and .index() works over a list of elements, not the
children of an element. I hope this makes sense, it is something of
confusing method. I plan on polishing it up some, as it was a late
addition to 1.0.
--John
On 10/17/06, Michael Crowl <[EMAIL PROTECTED]> wrote:
>
> .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 = $("[EMAIL PROTECTED]'id[]'[EMAIL
> PROTECTED]'"+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?
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/