I need to change the order of columns in a table in html / js dynamically, you can tell me how to do it?
Here's a jQuery plugin I just wrote to switch the contents of two columns:
$.fn.switchColumns = function ( col1, col2 ) {
var $this = this,
$tr = $this.find('tr');
$tr.each(function(i, ele){
var $ele = $(ele),
$td = $ele.find('td'),
$tdt;
$tdt = $td.eq( col1 ).clone();
$td.eq( col1 ).html( $td.eq( col2 ).html() );
$td.eq( col2 ).html( $tdt.html() );
});
};
See example →