Reputation: 3927
I'm adding rows dinamically in my WebPage and at one moment I want to get the value of each cell in a row.
This is the declaration of my row:
<tr class="template-upload fade">
<td class="name"><span>{%=file.name%}</span></td>
<td class="title"><label>Andar: <input name="andar" required></label></td>
</tr>
As you see, my rows have two cells: name and title. I'm trying to get the value of "name" cell and value of the input "andar" using jQuery.
This is what I have so far:
$('.template-upload tr').each(function () {
var item = $(this); //this should represent one row
var name = item.find('.name').text();
var andar = item.find('input:text[name=andar]').val();
});
However, I'm not getting anything in this two variable.
What could I be missing here?
Upvotes: 0
Views: 3395
Reputation: 8325
You have a typo...
$('tr.template-upload').each(function () {
...
});
Upvotes: 0
Reputation: 3091
.template-upload
IS your tr
Change your selector to something like:
$('.template-upload').each(function(node){ /* logic */ }
Upvotes: 0
Reputation: 25099
Are you sure your selector is right? Looking at it your selector is .template-upload tr
which means you're looking for the tr
elements inside the element with the .template-upload
class.
I think you'd be wanting:
$('tr.template-upload').each(...)
Upvotes: 0
Reputation: 207901
You were close, you just needed to remove the tr
from your selector. Your row already has the class .template-upload
so $('.template-upload tr')
doesn't exist:
$('.template-upload').each(function () {
var item = $(this); //this should represent one row
var name = item.find('.name').text();
var andar = item.find('input:text[name=andar]').val();
});
Upvotes: 1