I'm using bootstrap table in my view, and table rows are dynamically created, and after they are created I would like to attach a .onclick event to my rows so in case someone clicks on the row I might highlight it, I tried it and tested it, and I couldn't figure out how to solve this.
Here is my code:
1.) First, try - absolutely bad because keeps attaching events on my row, after few clicks there is 5-6-7 alerts popup..
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script>
$('#TableItems').click(function (e) {
$('#TableItems tr').click(function (e) {
alert("Clicked!");
});
});
</script>
2.) Second try - also not good because view is rendered and tr
are not rendered yet so probably, onclick event can not be attached because when I'm clicking on it
nothing is happening
$('#TableItems tr').click(function (e) {
alert("Damn");
});
Here is my table
<div class="table-responsive" id="myTable">
<table class="table table-striped jambo_table bulk_action">
<thead>
<tr class="headings">
<th class="column-title">Title </th>
</tr>
</thead>
<tbody id="TableItems"></tbody>
</table>
</div>