I have the following table:
<table summary='' id='table_csrdownloadcenter'>
<thead>
<tr>
<th>text1</th>
<th>text2</th>
<th>text3</th>
<th>text4</th>
<th>text5</th>
<th>text6</th>
<th>text7</th>
<th>text8</th>
</tr>
</thead>
<tbody>
<tr id='nom_du_pdf'>
<td class='dc-date'></td>
<td class='dc-dl'></td>
<td class='dc-title'></td>
<td class='dc-area'></td>
<td class='dc-category'></td>
<td class='dc-file'></td>
<td class='dc-ranking'></td>
<td class='dc-checkbox'><input type='checkbox' name='chk"+PathFile[i]+"' ></td>
</tr>
<tr id='nom_du_pdf2'>
<td class='dc-date'></td>
<td class='dc-dl'></td>
<td class='dc-title'></td>
<td class='dc-area'></td>
<td class='dc-category'></td>
<td class='dc-file'></td>
<td class='dc-ranking'></td>
<td class='dc-checkbox'><input type='checkbox' name='chk"+PathFile[i]+"' ></td>
</tr>
</tbody>
<table>
For each <tr>
I would like to save in a string the value of the name attribute in the 8th <td>
I tried this :
function DownloadZip()
{
$('.DownloadZip').click(function(){
var res = "";
$('#table_csrdownloadcenter').find("tbody").find("tr").find(td:nth-child(8)).find("input").each(function(){
res = $(this).attr("name").text();
alert(res);
}
});
}
Can anyone help me to make this working?
Just remove
text()
method , theattr("name")
will return the value of name attribute, also you are missing""
Iterate each
tr
, then check the8th
td'sinput
This creates an array of each of the
name
attribute values.To create a string:
You can use:
instead of:
since
$(this).attr("name")
already give you the string that contain the value of yourname
attribute.text() is a jQuery method and only jQuery object can utilize that method but
$(this).attr("name")
give you a string so obviously a string cannot apply jQuery method.Also you're missing quotes around your selector here
It should be