Shamoon Shamoon - 8 months ago 51
jQuery Question

How do I iterate through child elements of a div using jQuery?

I have a div and it has several input elements in it... I'd like to iterate through each of those elements. Ideas?


Use children() and each(), you can optionally pass a selector to children

$('#mydiv').children('input').each(function () {
    alert($(this).value); // "$(this)" is the current element in the loop

You could also just use the immediate child selector:

$('#mydiv > input').each(function () { /* ... */ });