Shamoon Shamoon - 1 year ago 119
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?

Answer Source

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 () { /* ... */ });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download