[jQuery] Re: REFACTOR: contents() with index() or indexOf()

2008-12-30 Thread nachocab
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

[jQuery] Re: REFACTOR: contents() with index() or indexOf()

2008-12-30 Thread Kean
$('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

[jQuery] Re: REFACTOR: contents() with index() or indexOf()

2008-12-30 Thread Ricardo Tomasi
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');

[jQuery] Re: REFACTOR: contents() with index() or indexOf()

2008-12-30 Thread nachocab
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 =

[jQuery] Re: REFACTOR: contents() with index() or indexOf()

2008-12-30 Thread Kean
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

[jQuery] Re: REFACTOR: contents() with index() or indexOf()

2008-12-30 Thread Dave Methvin
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

[jQuery] Re: REFACTOR: contents() with index() or indexOf()

2008-12-30 Thread nachocab
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

[jQuery] Re: REFACTOR: contents() with index() or indexOf()

2008-12-30 Thread Michael Geary
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

[jQuery] Re: REFACTOR: contents() with index() or indexOf()

2008-12-30 Thread Ricardo Tomasi
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