Click here to Skip to main content
15,887,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is where the div elements are generated

HTML
@if (@Model.QuateruserPoints.Count() > 0)
{

foreach (var data1 in Model.QuateruserPoints)
{
<div id="@data1.QuarterName" style="width:450px ;background-color:lightgray">

	<table class="table table-striped table-bordered" data-tbl-selector="@Model.CurrentQuarterId" id="@data1.QuarterName">
	<thead>
		<tr>
			<th>User Name</th>
			<th>Points</th>
			<th>Action</th>
		</tr>
	</thead>
	<tbody>
 @foreach (var data2 in data1.Challengepoints)
	{
		<tr>
		<tr>
			<td>@data2.UserName</td>
			<td>
			<input type="number" class="form-control" id="Points" data-selector="txtUserInp" data-username="@data2.UserName" data-challengeid="@data2.ChallengeId" value="@data2.Points" />
			 @Html.ValidationMessageFor(model => Model.Points)
		</td>
		<td class="deleteRow"><a href='#' data-username="@data2.UserName" data-challengeid="@data2.ChallengeId">delete</a></td>
		</tr>
	}
	</tbody>
	</table>
</div>

}
}


This is a javascript where you add a row to a table that is generated above and H2FY15 is one the id of div where a row inside a table is added.

JavaScript
function fillData(data) {
         $.each(jsonObj,function(index,value){
            var htmlTemplate=$('#tblRowUserPoints').html();
            $("#userData1").val(JSON.stringify(jsonObj));
            var username=value.Unametag;
            var NewUser=username.split(";");
            var replaced=htmlTemplate
                    .replace(/%UserName%/g,NewUser[1])
                    .replace(/%Points%/g,value.userPoint);
            $('#H2FY15 > tbody').append(replaced);
        });

    }


H2FY15 is hard-coded as div id so i want to dynamically get the div id that is clicked.
Posted
Comments
Sinisa Hajnal 15-May-15 3:28am    
To clarify: you don't need H2FY15, but any div clicked that is part of hte table? With Id = @data1.QuarterName?

You have two problems with that. First, Id of the table and of the parent div are the same.
Second, detecting click on the div that contains the link might prevent link click event if you're not careful.

What do you actually need to do? That is, what are you trying to accomplish? What is the final goal to that detection?

You could add class to the div...you could bind the event via class and then handle it.
sachika_88 15-May-15 3:33am    
ok.Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900