Alias for the current document. This is normally the value of window[“document”];


The purpose of this class is twofold. First, it provides a shorter reference to getting ahold of the current document. Second, all references that make use of it can have its document scope altered temporarily by changes to the dojo.doc variable. This is used by other functions dojo.withDoc and dojo.setContext to change the document scope during certain operations.


Use this variable in place of calls to window.document. That way you are assured you will be working against the document that is considered to be the current ‘page’. And .. by using this variable, things that alter it will still operate properly against your widget during document changes. This is particularly important for your custom widgets if they are to be used inside iframes and the like.

Dojo 1.7 (AMD)

require(["dojo/_base/window"], function(win){
   var currentBody = win.body();  // You can also use: dojo.body() to get the current document body.
   var newText = win.doc.createTextNode("Some text");

Dojo < 1.7

var currentBody = dojo.doc.body;  // You can also use: dojo.body() to get the current document body.
var newText = dojo.doc.createTextNode("Some text");


Example usage of dojo.doc as replacement for document calls

function addText(){
  dojo.connect(dijit.byId("addTextButton"), "onClick", function(){
     var newText = dojo.doc.createTextNode("New Text!");
<button id="addTextButton" data-dojo-type="dijit.form.Button">Click me to add 'New Text!' to the page</button><br><br>
<b>Click the button several times, then scroll down to see the appended text.</b>
Error in the documentation? Can’t find what you are looking for? Let us know!