Actually that gives an error. It should be:
var $items = $('itemsitemHello/itemitemworld/item!!item
id=my_itemGoodnight moon!/item/items');
for(var i=0; i = $items.children().length; i++){
if ( $items.contents()[i].id == 'my_item' )
console.info(i)
}
It also needs to work with
$('itemsitemHello/itemitemworld/item!!item
id=my_itemGoodnight moon!/item/items').find(#my_item).each
(function(){
alert(this.innerHTML);
});
Hmm I'd be interested to see how this can be done without using
each
On Dec 30, 12:07 pm, nachocab nacho...@gmail.com wrote:
Actually that
var $items = $('itemsitemHello/itemitemworld/itemitem
id=my_itemGoodnight moon!/item/items');
var $my = $items.find('#my_item');
console.info( $items.children().index($my) );
or
var $items = $('itemsitemHello/itemitemworld/itemitem
id=my_itemGoodnight moon!/item/items');
Thank you both,
The only problem is that the right answer isn't 2, it's 3. I'm
actually looking for the index of item#my_item inside the contents
array. children() doesn't take into consideration the !! textnode.
On Dec 30, 9:43 pm, Ricardo Tomasi ricardob...@gmail.com wrote:
var $items =
I believe jQuery does not count/iterate textnode. Maybe there's a
function in jQuery but I have no idea.
On Dec 30, 12:52 pm, nachocab nacho...@gmail.com wrote:
Thank you both,
The only problem is that the right answer isn't 2, it's 3. I'm
actually looking for the index of item#my_item inside
var $items = $('itemsitemHello/itemitemworld/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/95718c9aab2c7483/af37adcb54b816c3
As for
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
There's nothing wrong with running that for loop yourself. In fact, it will
be faster than any other solution - because all the other solutions will
just boil down to a loop with a bunch of extra code.
-Mike
From: nachocab
Allright, so I guess manually going through the contents()
array
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 = $('itemsitemHello/itemitemworld/item!!item
id=my_itemGoodnight
9 matches
Mail list logo