I'd like to put invisible placeholders in a Google Doc so that they can be found and the content changed. In HTML, this would be a <span id="name-of-placeholder">, with the item findable via "elem = document.getElementById('name-of-placeholder');" and the content could be changed like for DOM, as "elem.innerHTML = newContent;".

What is the best way to do similar things with a Google Doc?

EDIT: I find lots of "mail merge" techniques which use visible placeholders, but replace the placeholders with the resulting text. Then the placeholder is gone, and there is no easy way to find it again for future updates.

  • Have you tried inserting zero width space characters in your document ( Unicode: U+200B, UTF-8: E2 80 8B)? You can adopt a convention whereby your placeholders are a series of such characters. The first one would consist of a single zero width space character, the next one would be two adjacent zero width spaces, and so on. Jun 14, 2015 at 10:22
  • @Jean-ReneBouvier While these would probably be easy to manually delete, since the area of the document won't need much manual editing if I automate it, this idea has possibility. Thanks. I haven't gotten back to this issue for a while :(
    – Victoria
    Jun 16, 2015 at 4:15

1 Answer 1


Google Docs doesn't have invisible placeholders at this time, but it has bookmarks. From the second reference:

// Insert a bookmark at the cursor position and log its ID.
 var doc = DocumentApp.getActiveDocument();
 var cursor = doc.getCursor();
 var bookmark = doc.addBookmark(cursor);

Using bookmarks in a document
Class Bookmark

  • 1
    Hmm. Unlinked bookmarks might do the trick. It will be a few days before I can experiment.
    – Victoria
    Apr 30, 2015 at 6:40
  • 1
    Unlinked bookmarks are still visible. At first, I thought maybe they'd only be visible if they were linked, but when I tried it they get a nice bookmark flag. It's cute, but plenty visible. Might be the closest thing to what I want, that is available? Some Word Processors allow defining table cells in random places separate from tables, but I don't see anything like that... maybe a single cell table with 0px border will work for my purpose... although other tables will exist, so I would have to discriminate between them somehow...
    – Victoria
    May 2, 2015 at 3:21
  • A couple of pages that could help you: Class Cell, Class RangeElement May 2, 2015 at 3:29
  • 1
    Thanks. I don't suppose there is code around that converts a Doc's internal structure to a tree-structured display in the log so that one can learn how they are put together. It occurred to me that with a 0px border, I might be able to discriminate between my tables and other tables using a weird border color.
    – Victoria
    May 2, 2015 at 3:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.