Yes the editors do have some cleanup logic that can cause problems like this. So its best to use whichever editor works best for your needs. In the Html content feature in the settings you can also disable the editor so that you edit raw html. Sometimes this is needed when putting javascript in the content to prevent the editor from doing cleanup that breaks it.
Best,
Joe