Use 'reverse-ordered' jquery's replaceAll();