Constructor
new Element(tagNameOrNamespaceOrElement, opt_tagNameOrEventOutputsopt, opt_eventOutputsopt)
When creating an instance of Element capsule you either create new DOM element or wrap an already existing DOM element. In any case, newly created capsule behaves as a wrapper for the underlying DOM element. Creating an instance of Element capsule is simple, although there are three different legal ways to do it. See examples bellow for more details.
Parameters:
Name |
Type |
Attributes |
Description |
tagNameOrNamespaceOrElement |
string
|
Element
|
|
denotes: a) the tag name of the DOM element to be created, or b) the namespace of the DOM element to be created (in case of creating SVG element for example), or c) the DOM element itself (in case you just want to wrap it) |
opt_tagNameOrEventOutputs |
string
|
Array.<string>
|
<optional>
|
if the first parameter is a namespace then this one should be a tag name of the DOM element to be created, otherwise it is an optional array of events (e.g. ['click', 'dbclick']) for which output operations should be created (see addEventOutput) |
opt_eventOutputs |
Array.<string>
|
<optional>
|
if the first parameter is a namespace then this one should be an optional array of events (e.g. ['click', 'dbclick']) for which output operations should be created (see addEventOutput), otherwise this parameter has no meaning |
- Since:
- Source:
Throws:
-
-
-
Type
-
Error
Examples
Creating new HTML (DOM) element and new Element capsule as its wrapper
let htmlElement = new html.Element('div'); // using tag name
Creating new SVG (DOM) element (needs namespace) and new Element capsule as its wrapper
let svgElement = new html.Element('http://www.w3.org/2000/svg', 'rect'); // using namespace and tag name
Creating new Element capsule to wrap an existing DOM element
let existingElement = document.createElement('div'); // or document.getElementById or whatever...
let htmlElement = new html.Element(existingElement);
Specifying output operations (optional in all three ways of instantiation)
let htmlElement = new html.Element('div', ['click', 'dblclick']); // reacts on click and double click
htmlElement.click.wire(function(e){
alert('Clicked!');
});
Creates new output operation for the given event name (e.g. 'click'). Each time the event is captured output operation is called with event object as an argument. If output name is provided in the second argument, output operation would take that name, otherwise it would default to the event name.