Actually that gives an error. It should be: var $items = $('<items><item>Hello</item><item>world</item>!!<item id="my_item">Goodnight 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 $items.contents()[i].className
On Dec 30, 8:30 pm, nachocab <nacho...@gmail.com> wrote: > Hi everyone, > I'd like to know if there's a way to do this without using a for loop. > You can just paste this in Firebug: > > var $items = $('<items><item>Hello</item><item>world</item>!!<item > id="my_item">Goodnight moon!</item></items>'); > for(var i=0; i <= $items.children().length; i++){ > if ( $items.contents()[i].id == 'my_item' ) > console.info(i) > > } > > Keep in mind that I need to use contents() to also get the text node > ("!!"). I can't seem to use contents().index() properly. > > Thanks, > > Nacho