How to implement dynamic IDX using the loops index?

I have a for each loop and it has an index variable , I wanted to replace the idx value in the selector with the index value. Any idea thanks.

here is the original selector


<webctrl tag='DIV' class='messageListRow msgUnread' idx='1' />