I have the following code :
<input pid="hidVoteKey" type="hidden" value="0" />
<ul id="mainPostList" class="verticalList">
@foreach (var postViewModel in Model.Posts)
{
<li><div class="voteCon">...</div></li>
}
</ul>
Then I have a jquery that loop all elements with class voteCon and then try to get the parent input like this :
$(".voteCon").each(function () {
InitVoteControl($(this), $(this).parent("input[pid='hidVoteKey']").val());
});
The problem is that it will not find the hiddenfield?
In this case the voteCon contains up/down buttons and there is some javascript functions bound here to make ajax calls. There will be multiple lists like the one above on the same page but thay all will have diffrent hidVoteKey.
It won’t find the
<input>because it isn’t a parent (or ancestor) of the<div class="voteCon">. It’s on the same level as (a sibling of) the<ul>, which is an ancestor of the<div>. You could do this: