Opened 8 years ago

Last modified 4 years ago

#15226 assigned enhancement

domConstruct.create() optional document parameter — at Version 1

Reported by: bill Owned by: Eugene Lazutkin
Priority: undecided Milestone: 1.15
Component: HTML Version: 1.7.2
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by bill)

Most of the methods in the dom* modules allow optionally explicitly or implicitly specifying a document. For example:

  • dom.byId(id, doc) looks up "id" in document "doc"
  •"<div>hi</div>", refNode) creates the <div> in refNode.ownerDocument

However, domConstruct.create() doesn't take an optional document parameter, so you can't easily specify a document for a case like:

domConstruct.create("div", {role: "dialog", innerHTML: "hi"});

If your code has a refNode, the document is implied by the refNode:

domConstruct.create("div", {role: "dialog", innerHTML: "hi"}, refNode);

However, sometimes there's no refNode, in which case you either need to stop using domConstruct.create(), ex:

var div = myDoc.createElement("div");
domAttr.set(div, {role: "dialog", innerHTML: "hi"});


var div = domConstruct.toDom("<div role=dialog>hi</div>")[0];

or use the dojo/_base/window withDoc() mechanism, which is a little clunky:

win.withDoc(myDoc, function(){
   domConstruct.create("div", {role: "dialog", innerHTML: "hi"});

(I'm also not sure if withDoc() will be around in 2.0.)

So, this is a ticket to consider adding an optional document parameter to the create() method. I'm not sure what the signature would be though, since create() already has a number of optional parameters.

Change History (1)

comment:1 Changed 8 years ago by bill

Description: modified (diff)
Summary: dom.create() document parameterdomConstruct.create() optional document parameter
Note: See TracTickets for help on using tickets.