Constructor
new Element(tagNameOrNamespaceOrElement, opt_tagNameOrEventOutputsopt, opt_eventOutputsopt)
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 |
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!');
});
Members
Collection of Hooks
Properties:
Name | Type | Description |
---|---|---|
hook |
module:capsula.Hook | A hook that represents the underlying DOM element of this capsule. |
Collection of Loops
Properties:
Name | Type | Description |
---|---|---|
loop |
module:capsula.Loop | (inherited from HasRootHTML) A loop that represents the underlying DOM element of this capsule. |
Methods
addEventOutput(eventName, opt_outputNameopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
eventName |
string | event for which to create output operation, e.g. 'click' or 'dblclick' | |
opt_outputName |
string |
<optional> |
output operation name, if not specified the default value is the eventName |
Throws:
- Type
- Error
Example
Reacting on click event
let htmlElement = new html.Element('div');
...
htmlElement.addEventOutput('click');
...
htmlElement.click.wire(function(e){
alert('I have just been ' + e.type + 'ed.'); // I have just been clicked.
});