HTML:
<fieldset id="10">
<h1>Select a color:</h1>
<select name="color">
<option>red</option>
<option>blue</option>
</select>
</fieldset>
JS:
var fields = $(":input").serializeArray();
$.each(fields, function (i, field) {
var field_id = $(field.name).closest("fieldset").attr('id');
$("#results").append('<a href="'+field_id+'">'+field.value+'</a>');
});
All I get is undefined
?
When I do: field.name
, it gives me "color". I want to be able to find the parent or closest fieldset that this form element belongs to.
I expect field_id
to equal "10" in this example.