I have the following loop using the jQuery each method. I'm trying to leverage the index of the loop to ensure checkboxes and labels in my markup have the correct dynamic content. On each pass through, I'm appending the index to the class name then assigning a value and text content to the appropriate elements, based on the new modified class name. Is there a simpler or cleaner way to go about this? 'Managers' in this case contains text and value properties for the items I'm iterating through.
$(Managers).each(function (index) {
$('.chk-hr').attr('class', 'chk-hr-' + index);
$('.chk-hr-' + index).attr("value", this.Text);
$('.lbl-hr').attr('class', 'lbl-hr-' + index);
$('.lbl-hr-' + index).text(this.Text);
});
Desired output:
<input class="chk-hr-0" value="Bob">
<span class="lbl-hr-0">Bob</span>
<input class="chk-hr-1" value="John">
<span class="lbl-hr-1">John</span>