The children() in your loop is not counting the textnode either.

index() can't help you in this case, as it ignores nodes that are not
elements even using contents(). But you can use $.each to simplify
your code a bit:

var $items = $('<items><item>Hello</item><item>world</item>!!<item
id="my_item">Goodnight moon!</item></items>');
$.each($items.contents(), function(i) {
    if (this.id == 'my_item') {
         console.info(i);
         return false; //stop the loop
    }
});

- ricardo

On Dec 31, 1:04 am, nachocab <nacho...@gmail.com> wrote:
> Allright, so I guess manually going through the contents() array is
> the only solution.
> The only function that comes close to giving me the index is
> jQuery.inArray() (it's really just the for loop that I'm doing with a
> different condition), but it doesn't let me specify the id or the
> className, so I'm out of luck.
>
> Thanks anyway,
>
> Nacho
>
> On Dec 30, 11:22 pm, Dave Methvin <dave.meth...@gmail.com> wrote:
>
> > > var $items = $('<items><item>Hello</item><item>world</item>...
>
> > jQuery will try to parse that with the browser's HTML parser, but it's
> > not HTML. I don't know if that will cause you sorrow or not.
>
> >http://groups.google.com/group/jquery-en/browse_thread/thread/95718c9...
>
> > As for getting the index, maybe something like this?
>
> >   $items.find('#my_item').prevAll().length

Reply via email to