Merging 2 (selected) TD in Pure Javascript

Slightly modified version that works better when merging cells that both already have colspan or rowspan

Note that each of the versions I have provided will only work properly for multiple merges if you start merging from the bottom right of the table. If cells have been merged above or to the left of the ones to be merged then the cell counts for working out which are adjacent will no longer match up. For example if you merge IJ then the code will not let you merge GK as it doesn’t recognise that they are in the same column. It would however allow you to merge FK as it mistakenly identifies those as adjacent and so makes a mess of the table.

To get the code to work properly for all possible merges we need to be able to accurately identify which cells are adjacent even when other cells have already been merged.