You can use facets to do this. For example, a simple test.app
:
<aura:application access="GLOBAL">
<aura:attribute name="messages" type="Aura.Component[]" access="GLOBAL"/>
<div aura:id="messages">
{!v.messages}
</div>
<ui:button label="Show Message" press="{!c.showMessage}"/>
</aura:application>
The corresponding testController.js
:
({
showMessage: function(component, event, helper) {
$A.createComponent("ui:outputText",
{value: "Message created at " + Date.now()},
function(cmp) {
component.set("v.messages", [cmp]);
setTimeout(function() {
$A.run(function() {
component.set("v.messages", []);
});
}, 5000)
});
}
})
The facet is an attribute of type Aura.Component[]
that you render in the desired spot using an expression such as {!v.messages}
. When the element is created, set the value of this facet to be an array with one component, the [cmp]
in the code. Set a timeout, etc., then set the value of this facet to be an empty array with []
. Make sure to wrap the calls with $A.run
.
If you use the Chrome or other tools to inspect the DOM, you'll see the component elements appear and disappear.
If this isn't what you're looking for, please provide more details.
Best Answer
The DOM (DOM (Document Object Model) is just a model of the document. It could be a HTML/XHTML documents or XML document. The DOM only describes a structure of objects and it representation and accessibility.
In relation to Salesforce you have some ways where you can "use" DOM in Apex programming language and on the Visualforce pages.
In Apex the use of DOM is useful while creating or reading XML-documents. For that Apex language offers some classes:
Good XML and Apex examples could be found here: Reading and Writing XML Using the DOM
Other use case of the DOM in Salesforce is a Visualforce Page. It is like any other HTML page but processed all dynamic content on the server. When the page is loaded (rendered) completely - you can access page elements guided by DOM. For example manipulate the visibility, look & appearance with Javascript and CSS. For that you must have a strong understanding and knowledge of HTML, Javascript and CSS.
Some helpful topics: