Reputation: 3973
I have a table that I'm using with the jQuery datatables API. In some of the cells in that table, I have links with the class adder
. When the user clicks that link, I need to get the index location of that row, so that I can do some processing. I'm using the following code to test it out:
$('.adder').click(function() {
alert(searchTable.fnGetPosition($(this).parent().parent()));
return false;
});
My expectation based on the API documentation is that this would alert the index of the row in question. The parent of the a
element should be the td
element, and the parent of that is the tr
element. However, when I click one of the links, what is actually happening is that the whole table is just refreshing. Nothing shows up in the javascript console...
Any thoughts?
Upvotes: 2
Views: 4647
Reputation: 1092
This is because the parent of the parent is a jQuery object and not a tablerow element or table cell element. Since it appears you want the table row element then I would do something like this.
$('.adder').click(function() {
alert(searchTable.fnGetPosition($(this).parent().parent()[0]));
return false;
});
Here's the documentation for this api call as well in case you missed it.
Upvotes: 5