Reputation: 6820
I have a table like this:
<table>
<tbody>
<tr></tr>
<tr></tr>
<tr class="TableContent">
<td class="shouldbeunderTableMenu"></td>
<td class="TableMenu"></td>
</tr>
</tbody>
</table>
As you can see I have a td with class equal to TableMenu
. I would like to position the td above the td with class shouldbeunderTableMenu
.
So that the first td is vertically positioned under the second td. Image to clarify:
But how can I do this?
Upvotes: 1
Views: 276
Reputation: 40639
Try to use before,
$(".shouldbeunderTableMenu").before($(".TableMenu"));
$(".shouldbeunderTableMenu").before($(".TableMenu"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tbody>
<tr></tr>
<tr></tr>
<tr class="TableContent">
<td class="shouldbeunderTableMenu">1</td>
<td class="TableMenu">2</td>
</tr>
</tbody>
</table>
or use after
$(".TableMenu").after($(".shouldbeunderTableMenu"));
$(".TableMenu").after($(".shouldbeunderTableMenu"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tbody>
<tr></tr>
<tr></tr>
<tr class="TableContent">
<td class="shouldbeunderTableMenu">1</td>
<td class="TableMenu">2</td>
</tr>
</tbody>
</table>
Upvotes: 6
Reputation: 9472
Why use all that fancy jQuery when you can use css :P
td{
border:1px solid black;
display:block;
}
.TableMenu{
margin-top:-45px;
}
.shouldbeunderTableMenu{
margin-top:25px;
}
Working example:http://jsfiddle.net/h0pLe8cw/1/
Upvotes: 1
Reputation: 12132
I would do this:
$(document).ready(function() {
var shoulder = $(".TableContent .shouldbeunderTableMenu");
var clone = shoulder.clone();
shoulder.remove();
$(".TableContent").append(clone);
});
Upvotes: 0
Reputation: 10216
With jQuery:
$('td.TableMenu').each(function() { $(this).prependTo($(this).parent()); });
Or more generally:
$('td.TableMenu').each(function() { $(this).before($(this).siblings('.shouldbeunderTableMenu')); });
Upvotes: 3