I'd like to change table cell positions using jQuery.
Before
— kiwi fruit
— Peach
— banana
green | fruit: kiwi fruit
pink | fruit: Peach
yellow | fruit: banana
Sour | fruit: kiwi fruit
sweet | fruit: Peach
sweet | fruit: banana
After - I want it change this way.
— kiwi fruit
green | fruit: kiwi fruit
Sour | fruit: kiwi fruit
— Peach
pink | fruit: Peach
sweet | fruit: Peach
— banana
yellow | fruit: banana
sweet | fruit: banana
They use the same format below.
"- [fruit]"
" | fruit: [fruit]"
*2nd one before the [fruit], two spaces
<table>
<tr>
<td>— kiwi fruit</td>
</tr>
<tr>
<td>— Peach</td>
</tr>
<tr>
<td>— banana</td>
</tr>
<tr>
<td>green | fruit: kiwi fruit</td>
</tr>
<tr>
<td>pink | fruit: Peach</td>
</tr>
<tr>
<td>yellow | fruit: banana</td>
</tr>
<tr>
<td>Sour | fruit: kiwi fruit</td>
</tr>
<tr>
<td>sweet | fruit: Peach</td>
</tr>
<tr>
<td>sweet | fruit: banana</td>
</tr>
</table>
I made it with sources below, but it's not practical because other fruit like 'apple','cherry',etc. can be added in the future and each time I add the new fruit I have to edit my sources.
$("tr:contains(' | fruit: kiwi fruit')").insertAfter("tr:contains('— kiwi fruit')");
$("tr:contains(' | fruit: Peach')").insertAfter("tr:contains('— Peach')");
$("tr:contains(' | fruit: banana')").insertAfter("tr:contains('— banana')");
Thank you!
I asked this question 2 days ago and have not found any solution. If someone could help me with this quiestion, I would really appriciate it.