I want to convert HTML
table to ul
and li
elements. my table structure is
<table>
<tbody>
<tr>
<th>1974</th>
<td>UK</td>
</tr>
<tr>
<th>1976</th>
<td>Street</td>
</tr>
<tr>
<th>1976-2002</th>
<td>visitors.</td>
</tr>
</tbody>
</table>
I tried to convert this to
<ul>
<li>
<p>1974</p>
<p>UK</p>
</li>
<li>
<p>1976</p>
<p>Street</p>
</li>
<li>
<p>1976-2002</p>
<p>visitors.</p>
</li>
</ul>
using jquery
replaceWith
function as below. Here I firstly going to convert <tbody>
element.
$(document).ready(function() {
$("tbody").each(function(){
var html = $(this).html();
$(this).replaceWith("<ul>" + html + "</ul>");
});
)};
but this not give any positive answer. Anybody have any idea how to do this.
Thanks.
<table> <ul>
isn't a valid markup, it should be<table> <tr> <td> <ul></ul></td></tr></table>
. – Charity