Instead of before and remove, use jquery replaceWith