Since the createElement() method is a member of the document object, it can be accessed using either dot notation :
var form = document.createElement("form");
Or parenthesis designation :
var form = document["createElement"]("form");
This can be useful if the name of the method to call is stored in a variable:
var methodName = "createElement"; var form = document[methodName]("form");
It can also be used if the actual invocation method is dependent on external conditions. Here is an example (far-fetched):
function createNode(str, isTextNode) { return document[isTextNode ? "createTextNode" : "createElement"](str); }
FrΓ©dΓ©ric hamidi
source share