I have a table which contains a single row with even tds. Half of them are remove from list data and the other half for add to list data.
So the structure in my razor view is somewhat like
<table class="table table-bordered table-hover dataTable"
role="grid" aria-describedby="example2_info">
<tbody>
@{int j = 0;}
@foreach (var i in item.Data)
{
{ j++; }
<tr role="row" class="odd">
<td class="sorting_1 remove-from-list_@j" style="word-break:break-all;">
...
<td class="add-from-list_@j">
...
So each class is getting dynamically name given.
My jQuery function, is as follows:-
<script type="text/javascript">
$(document).ready(function () {
$(".table.table-bordered.table-hover.dataTable td.add-from-list")
.not(':first').each(
function (i) {
$(".add-from-list_" + i).hover(function () {
$(this).css("background", "#fff2cc");
})
},
function (i) {
$(".add-from-list_" + i ).css("background", "");
});
$(".table.table-bordered.table-hover.dataTable td.remove-from-list").each(
function (i) {
$(".remove-from-list_" + i).hover(function () {
css("background", "#fff2cc");
})
},
function (i) {
$(".remove-from-list_" + i).css("background", "");
});
It is not working.
each.I don't see any documentation for doing that. When things don't work (or even before), the documentation should be your first port of call.tdwith the classadd-from-playlistin your HTML. I see ones withadd-from-playlist_0and such, but those won't match the selector you're using. All due respect, the problem above just needs debugging using the powerful debugger built into your browser. It may also be a good idea to step back from this task and work through some jQuery tutorials. There's no need for eachtdto have its ownadd-from-playlist_0class, for instance.