How would I sort HTML attributes using JavaScript?
I have this HTML:
<table>
<tbody>
<tr>
<td>Cell 0,0</td>
<td>Cell 1,0</td>
<td>Cell 2,0</td>
</tr>
<tr>
<td>Cell 0,1</td>
<td rowspan="2" colspan="2">Cell 1,1
<br>Cell 2,1
<br>Cell 1,2
<br>Cell 2,2</td>
</tr>
<tr>
<td>Cell 0,2</td>
</tr>
</tbody>
</table>
And I want to sort all attribute in all elements into alphabetical order. E.g:
<td colspan="2" rowspan="2">Cell 1,1
The sort function could either be based on a HTML string, or a jQuery object, or a node (it doesn't matter which one).
The reason I need this is because I am doing a diff (with JS, in the browser, after a failed unit test) between 2 sets of HTML and the attribute order is making it fail.
So my questions are:
How can I reorder a nodes attributes?, Or how can I reorder attributes in an HTML string?, Or how can I reorder a jQuery elements attributes?
I haven't got any code for it yet, as I am unsure which method would be the best.