document.createElement multiple arguments

3.9k Views Asked by At

I was reading through the polymer documentation, and I saw this:

var el2 = document.createElement('input', 'my-input'); Source

Forgetting about polymer for a second, can document.createElement currently take 2 arguments? Is it related to Polymer's type-extensions?

Side note: Webstorm was "complaining" when I called it with 2 arguments.

2

There are 2 best solutions below

3
On BEST ANSWER

At the moment, document.createElement will only take one parameter (Ignoring the second). It does appear that there is a spec that will allow you to pass a typeExtension which you can read about here. This spec is still in the works, and is not implemented in any form on any browser as of yet.

Quick edit: It does appear that chrome stable does contain the typeExtension parameter, which can be found here. Thanks @ScottMiles for the clarification.

0
On

No it can not. FROM MDN: In an HTML document, the Document.createElement() method creates the specified HTML element or an HTMLUnknownElement if the given element name isn't a known one.

var element = document.createElement(tagName);

element is the created Element object. tagName is a string that specifies the type of element to be created. The nodeName of the created element is initialized with the value of tagName.

https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement