Obviously I'm doing something wrong. I've never been able to get .click() to work, but other jQuery calls work fine.
I have the following Javascript function:
function showParamsFor(divID) {
//Code here works when the function is called through onclick attribute
}
Then, I basically have the following scenario:
int index = 0;
foreach (var op in Model.Operations)
{
<div id="param_container[@(index)]"
<a id="show_params[@(index)]" href="#">
Edit Parameters
</a>
</div>
index++;
}
int total = index;
<script type="text/javascript" src="~/Scripts/jquery-1.6.2.min.js"></script>
for (int i = 0; i < total; i++)
{
<script type="text/javascript">
$(document).ready($('#show_params[@(i)]').click(function () {
showParamsFor('#param_container[@(i)]');
});
</script>
}
For the life of me, I can't seem to get this to work. Aside from .click(), I've tried using the following methods:
.live('click', function())
.bind('click', function())
I've tried removing $(document).ready and adding it back in each scenario, but nothing happens when the link is clicked.
I've double checked my id names and even tried using a class name for the link (.show_params[@(i)]) instead of the id. Whaat am i doing wrong here?
EDIT
I'm using a loop because I have a dynamic list of these links. I need to bind a click event to each after they have ALL been created because each link needs a reference to each of the other links.