You need to sign in to do that
Don't have an account?
Cannot access DOM element from Lightning Component
I have a Lightning Component which displays a <table> element after rendering.
I want to access the table and add a class to it, but for some reason it does not find the table.
Please help.
I want to access the table and add a class to it, but for some reason it does not find the table.
Please help.
<aura:handler name="render" value="{!this}" action="{!c.onRender}"/>
onRender: function (component, event, helper) { var table = document.getElementsByTagName("table"); if (table != undefined) { table.classList.add("slds-p-bottom_large"); } }getElementsByTagName does not find the table, why?
As you know, Salesforce’s first priority product security.
so they have introduced LockerService For Lightning Components.
You may be wondering what is benefits of LockerService
All Answers
You cant access DOM in lightning components
please refer this link to create a table in a lightning component
https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=ALLQUESTIONS&id=9060G0000005cN4QAI
please go through https://trailhead.salesforce.com/en/modules/lex_dev_lc_basics
Mark as best answer if it helps you.
Thanks,
Ghanshyam Choudhari
We have found a workaround, but thanks for the info
Can you explain me why on earth it is not possible to access DOM in Lightning?
I just cannot believe that
As you know, Salesforce’s first priority product security.
so they have introduced LockerService For Lightning Components.
You may be wondering what is benefits of LockerService