If you are playing with the DOM for gmail, you will find it requires a decent amount of maintenance. There is a firm that created a product, find the same problem, and ended up creating a solution for this called InboxSDK: https://www.inboxsdk.com/ HTH, KAM