I have an HTML table on a page that I'd like to use jQuery to take the information from, clean/sanitize it, and create a new "clean" HTML table with the information.
I have the table with the following <tr> structure:
<tr class="dirRow">
<td style="border-style:None;width:35px;">
<a href="http://www.link.com">
<img class="class-here" src="/media/proxy.ashx?id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&size=50w50h_fxd" style="border-width:0px;height:35px;width:35px;">
</a>
</td>
<td style="border-style:None;">
<a href="http://www.link2.com">Full Name</a>
</td>
<td style="border-style:None;">
<span>123.456.7890</span>
</td>
<td style="border-style:None;">
<span>456.789.0123</span>
</td>
<td style="border-style:None;">
<span>Office</span>
</td>
<td style="border-style:None;">
<span>Title</span>
</td>
<td style="border-style:None;">
<span>Supervisor</span>
</td>
</tr>
<!-- 150+ more tr with same structure -->
Which I'd like to input the information into the following table (formatted this way to use a plugin that takes this table input and formats it into an org chart). I've commented how the information should be modified from the original HTML table.
<table id="orgChartData">
<tbody>
<tr>
<th>id</th>
<th>parent id</th>
<th>image</th>
<th>name</th>
<th>phone</th>
<th>phonecell</th>
<th>office</th>
<th>title</th>
<th>supervisor</th>
</tr>
<tr>
<td>
<!-- Full Name (text only, no href, goes here) -->
Full Name
</td>
<td>
<!-- Supervisor (text only, no span, goes here) -->
Supervisor
</td>
<td>
<!-- img src (just the relative path, no query string) -->
/media/proxy.ashx?id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
</td>
<td>
<!-- Full Name (including href with "xlink:" added to the beginning of the href) -->
<a xlink:href="http://www.google.com/" target="_blank">Full Name</a>
</td>
<td>
<!-- Phone (no span) -->
123.456.7890
</td>
<td>
<!-- Phonecell (no span) -->
456.789.0123
</td>
<td>
<!-- Office (no span) -->
Office
</td>
<td>
<!-- Title (no span) -->
Title
</td>
<td>
<!-- Supervisor (no span) -->
Supervisor
</td>
</tr>
</tbody>
</table>
Updated my code based on Michael Sacket's answer below
I now have all the variables in the right format, but need to create the new <tr>s based on these variables.
$('tr.dirRow').each(function () {
var tds = $(this).children();
var fullName = tds.eq(1).text();
var supervisor = tds.eq(6).text();
var imgSource = tds.eq(0).find("img").attr("src");
var imgSourceClean = imgSource.substring(0, imgSource.indexOf('&'));
var fullNameHref = tds.eq(1).find("a").attr("href");
var fullNameHyperlink = '<a xlink:href="' + fullNameHref + '">' + fullName + '</a>';
var phone = tds.eq(2).text();
var phoneCell = tds.eq(3).text();
var office = tds.eq(4).text();
var title = tds.eq(5).text();
});
Thanks for any help.