Reputation: 41
I am using following code to iterate table rows with id
$('#resultingTableOfSaveDataJS tr').each(function () { //line 1
var rowID = $(this).id.charAt(6); //line 2
if (rowID == currentID) { //line 3
$('#this td').slice(diff); //line 4
}
});
At line 2 i am trying to get the character at 6th position of my each row's id. But I am getting a Undefined error at line 2.
Please help me to get this code right.
Upvotes: 0
Views: 280
Reputation: 318182
each() has parameters that you can use:
$('#resultingTableOfSaveDataJS tr').each(function(index, elem){
var rowID = elem.id.charAt(6);
if (rowID == currentID){
$('td', elem).slice(diff);
}
});
Upvotes: 1
Reputation: 253308
You're using DOM methods on jQuery objects. To get the id
from a jQuery object:
$(this).attr('id').charAt(6);
Or:
$(this).prop('id').charAt(6);
Without jQuery (and JQuery is needless, and over-expensive for this), using the DOM/'plain' JavaScript:
this.id.charAt(6);
References:
Upvotes: 0
Reputation: 63524
It's either
$(this).attr('id').charAt(6); // jQuery
Or
this.id.charAt(6); // non-jQuery
Upvotes: 0