Example 1 — Official $("form input")
Select every input nested under a form — any depth.
var names = [];
$("form input").each(function () {
names.push(this.name || this.value || "(input)");
});
$("#out").text(
"Matched: " + names.length + "\n" +
names.join(", ")
); How It Works
- Ancestor.
formis the container. - Space. Means “anywhere underneath,” not only the next level.
- Match. Both the direct field and the fieldset field match.

