jQuery: selecting each td in a tr
Your $(magicSelector)
could be $('td', this)
. This will grab all td
that are children of this
, which in your case is each tr
. This is the same as doing $(this).find('td')
.
$('td', this).each(function() {
// Logic
});
You don't need a jQuery selector at all. You already have a reference to the cells in each row via the cells
property.
$('#tblNewAttendees tr').each(function() {
$.each(this.cells, function(){
alert('hi');
});
});
It is far more efficient to utilize a collection that you already have, than to create a new collection via DOM selection.
Here I've used the jQuery.each()
(docs) method which is just a generic method for iteration and enumeration.
expanding on the answer above the 'each' function will return you the table-cell html object. wrapping that in $() will then allow you to perform jquery actions on it.
$(this).find('td').each (function( column, td) {
$(td).blah
});
You can simply do the following inside your TR loop:
$(this).find('td').each (function() {
// do your cool stuff
});