I have a table that looks like this:

I have this same chart on a few pages hard coded.
I want to be able to change the tables on all the pages using js and jQuery
I want to make it so that the YTD button is next to the From Date input
and the MTD is next to the To Date input.
I have tried to do that here: http://jsfiddle.net/maniator/W9YFF/9/
But it seems that it gets messed up at some points.
How do I fix that?
UPDATE
If I try doing
$('input[type="button"][value="YTD"]').insertAfter($('#fdate'));
$('input[type="button"][value="MTD"]').insertAfter($('#tdate'));
My result looks like this:
