If I have a table already inside my html file, which is sortable because its class is declared like so, it works. There is a javascript file included which defines the sortable class.

<table id="test" class="sortable">
<thead>
<tr><th>col1</th><th>col2</th></tr>
</thead>
<tbody>
<tr><td>one</td><td>10</td></tr>
<tr><td>two</td><td>20</td></tr>
<tr><td>three</td><td>30</td></tr>
<tr><td>four</td><td>40</td></tr>
</tbody>
</table>

But, if I inject the table using AJAX into a

like so:

var div = document.getElementById( "divID" );
div.innerHTML = tableText;

After injecting, the table appears but is not sortable.

I've tried doing this:

var myTable = document.getElementById( "test" );

myTable.className = "sortable";
myTable.style.className = "sortable";

If I inspect the DOM using FireFox's DOM inspector, it does show the sortable class is assigned (but it still doesn't work).

Any info or examples would be greatly appreciated (where injecting some HTML retains its class), thanks.