Example 1 — Official Demo: label + input
Select inputs that sit immediately after a label (jQuery API example).
$("label + input").each(function () {
this.value = "Labeled!";
});
console.log($("label + input").length); How It Works
- Find candidates. jQuery looks at every
inputin the document. - Check the previous sibling. Keep the input only if the element right before it is a
label. - Set the value. Each match gets
"Labeled!".

