JavaScript implementations to get legend for fieldset, and fieldset for legend
Demo for W3 bug 12834

This page demonstrates JavaScript implementations of getFieldset(legend) and getLegend(fieldset) functions that would be used to get fieldset for given legend and legend for given fieldset, respectively, as for the proposal bug 12834.

When loaded, the page shows identifiers of determined legends of two fieldsets. Identifiers of legends has names that are clearly related to their owner-fieldsets:

root-fieldset (root fieldset id)
root-fieldset-legend (id of legend of root fieldset)
desc-fieldset (id of fieldset that is descendant to root fieldset)
desc-fieldset-legend (id of legend for descendant fieldset)

There is also a fieldset without legend to even more demonstrate that the JS functions used here are bulletproof enough.

Legend of the root fieldset
First descendant fieldset — without legend.
Legend of the second descendant fieldset