I am trying to create a div using $A.createComponent but its throwing error.
`$A.createComponent("aura:HTML",
{
"tag": "div",
"HTMLAttributes":{"id": "filter-"+ component.get('v.index') +"", "Text":"Test"},
"class":""
},
function(result, status, errorMessage){
if (status === "SUCCESS") {
$A.createComponents(components,
function(components, status, errorMessage){
if (status === "SUCCESS") {
var divElement = document.getElementById("filter-" + component.get("v.index"));
//var divElement = component.find(component.get('v.targetDiv'));
console.log('Div element');
var elementBody = divElement.get("v.body");
}
}
);
}
}
);
Please ignore if any missing brackets are there I may have made mistake while copying it. It throws that divElement does not have get method or divElement is undefined. I know that component.find(component.get('v.index')) is trying to assign some value which never exist. how can I over come this situation?
get('v.body')
. I believe when the error occurs on this line, the JS stops executing further and the element does not appear on your lighting component.