You can do:
$("input.txt").focus() {
$("label[for='" + this.id + "']").addClass("highlight");
}).blur(function() {
$("label[for='" + this.id + "']").removeClass("highlight");
});
with:
label.highlight { background: yellow; font-weight: bold; }
While an input field has focus, its label (assuming it has one) is highlighted.
Edit: To traverse the inputs and do something with the labels:
$(":input[id]").each(function() {
if ($(this).val() != '') {
$("label[for='" + this.id + "'").each(do_something);
}
});
function do_something() {
// this refers to the label
}
or simply:
$(":input[id]").each(function() {
if ($(this).val() != '') {
$("label[for='" + this.id + "'").addClass("notnull");
}
});
or you can go the other way:
$("label[for]").each(function() {
var label = this;
$("#" + $(this).attr("foo") + ":input").each(function() {
if ($(this).val() != "") {
$(label).addClass("notnull");
}
});
});