1

I have this table:

<table class="catsTable" width="100%" cellspacing="1" cellpadding="0" border="0">
  <tbody><tr>
    <td style="width:25%" class="catsTd" id="cid5" valign="top">
        <a href="/load/prison_break_online/sezonul_1/5" >Sezonul 1</a> <span class="catNumData" style="unicode-bidi:embed;">[6]</span>
    </td>
    <td style="width:25%" class="catsTd" id="cid6" valign="top"><a href="/prison_break_online/sezonul_2/6" class="catName">Sezonul 2</a> <span class="catNumData" style="unicode-bidi:embed;">[0]</span></td>
    <td style="width:25%" class="catsTd" id="cid7" valign="top"><a href="/prison_break_online/sezonul_3/7" class="catName">Sezonul 3</a> <span class="catNumData" style="unicode-bidi:embed;">[0]</span></td>
    <td style="width:25%" class="catsTd" id="cid8" valign="top"><a href="/prison_break_online/sezonul_4/8" class="catName">Sezonul 4</a> <span class="catNumData" style="unicode-bidi:embed;">[0]</span></td>
  </tr></tbody>
</table>

So it is possible to replace this with :

<ul id="menu-css">
    <li><a href="/prison_break_online/sezonul_2/6">Sezonul 2</a></li>
    <li><a href="/prison_break_online/sezonul_3/7">Sezonul 3</a></li>
    <li><a href="/prison_break_online/sezonul_4/8">Sezonul 4</a></li>
    <li><a href="/prison_break_online/sezonul_5/9">Sezonul 4</a></li>
</ul>

I tried with:

<script>
    $($('.catsTable').find('td').get().reverse()).each(function(){
         $(this).replaceWith($('<li>'+$(this).html()+'</li>'))
    })
    $('.catNumData').remove();
</script>

but there still remains <table><tbody><tr> or is not even possible something like this?

3 Answers 3

1

Why not simply:

var newUL = $('<ul />',{'id' : 'menu-css'}).insertBefore('table.catsTable');
$('table.catsTable').find('a').each(function(){
    $(this).wrap('<li></li>').parent().appendTo(newUL);
}).closest('ul').next('table').remove();

JS Fiddle demo.

References:

Sign up to request clarification or add additional context in comments.

Comments

0

Perhaps you should try this fix:

<script>
    $('.catsTable').find('td').each(function(){
         $(this).replaceWith('<li>'+$(this).html()+'</li>);
    });
    $('.catNumData').remove();
</script>

I fixed some of your syntax. You had some extra $() that I deleted.

Comments

0

If you want to replace all the table with the <ul>, you could do something like:

$('.catsTable').after('<ul id="menu-css">' + 
    '<li><a href="/prison_break_online/sezonul_2/6">Sezonul 2</a></li>' +
    '<li><a href="/prison_break_online/sezonul_3/7">Sezonul 3</a></li>' +
    '<li><a href="/prison_break_online/sezonul_4/8">Sezonul 4</a></li>' +
    '<li><a href="/prison_break_online/sezonul_5/9">Sezonul 4</a></li>' +
'</ul>').first().remove();

I hope I'm not misunderstanding what you want...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.