<p>Let's say I have an html form.  Each input/select/textarea will have a corresponding <code>&lt;label&gt;</code> with the <code>for</code> attribute set to the id of it's companion. In this case, I know that each input will only have a single label.</p>

<p>Given an input element in javascript &mdash; via an onkeyup event, for example &mdash; what's the best way to find it's associated label?</p>

Earlier...
```
```
var labels = document.getElementsByTagName("LABEL"),
    lookup = {},
    i, label;

for (i = 0; i < labels.length; i++) {
    label = labels[i];
    if (document.getElementById(label.htmlFor)) {
        lookup[label.htmlFor] = label;
    }
}
```
```
Later...
```
```
var myLabel = lookup[myInput.id];
```
```
Snarky comment: Yes, you can also do it with JQuery. :-)