The Scenario:
I have a form in which I register people. I have a button "Add more people". The repeater has ran 4 times on Page_Load and all the controls is already on the page(they are just hidden). When I click the button I find the first hidden div and just show it.
The Problem:
Now I need to do stuff with a speciffic element in a speciffic div generated by the repeater (for example change it's class). However I don't know how to access it. Access by Id doesn't work and neither does access by class. I can't do anything from the code behind becaus everything is already on the page. It has to be done in javascript. Any ideas?
The code:
<asp:Repeater ID="rptOtherPeople" runat="server">
<HeaderTemplate>
<h3>Other people</h3>
</HeaderTemplate>
<ItemTemplate>
<div class="GridRow" id="personRow" style="display: none">
<dl>
<dt class="form-lbl left">Name</dt>
<dd class="form-value left">
<asp:TextBox ID="txtFirstName" CssClass="mid-inp required" Text="" runat="server"></asp:TextBox>
</dd>
</dl>
<div class="clear"></div>
<div class="separator"></div>
</div>
</ItemTemplate>
<FooterTemplate> </FooterTemplate>
</asp:Repeater>
The javascript that shows the next row:
var peopleNum = 1;
$(document).ready(function () {
for (i = 0; i < peopleNum; i++) {
$(".GridRow").each(function (index) {
if (index == i)
$(this).show();
});
}
})
function addPerson() {
peopleNum++;
$(".GridRow").each(function (index) {
if (index == peopleNum-1)
$(this).show();
});
}