For many scenarios, a better solution might be to enclose both the and label text in a single element. This is perfectly valid HTML, works properly in all browsers, and has the added benefit of being easy to use with hierarchical data, since you don't need to use the iterator variable: