How to access child element out of children()?

Posted by user291701 on Stack Overflow See other posts from Stack Overflow or by user291701
Published on 2010-06-14T03:13:17Z Indexed on 2010/06/14 3:22 UTC
Read the original article Hit count: 232

Filed under:

Hi,

I'd like to get the # of immediate children an element has, and then get the class of a child at a particular index. Something like:

var index = 25;
var children = $("#myListElement").children();
if (index < children.length) {
    if (children[index].hasClass("testClass")) {
        alert("hi!");
    }
}

I think the syntax for .children() is ok, but how do I get the indexed element out of them in jquery style?

Thanks

© Stack Overflow or respective owner

Related posts about jQuery