I'm working in a Lightning Aura component, and when I run it in the browser it's saying that my element is undefined.
HTML
<div id="myElement">
...
</div>
Controller.js
doInit: function(component, event, helper) {
helper.myFunction(component, event, helper);
}
Helper.js
myFunction: function(component, event, helper) {
const myElement = document.getElementById("myElement");
$A.util.addClass(myElement , "hello-world");
},
I've tried a variation by setting aura:id
on the HTML element...
HTML
<div aura:id="myElement">
...
</div>
Helper.js
myFunction: function(component, event, helper) {
const myElement = component.find("myElement").getElement();
$A.util.addClass(myElement , "hello-world");
},
But the results are the same: myFunction
still comes across as undefined.
aura:id/find
version I'm using which also says my element is undefined.