What is better to use document.getElementById("myId")
or component.find("myId").getElement();
in terms of performance? What will be faster?
[SalesForce] document.getElementById(“theId”) vs component.find(“theId”).getElement();
Related Topic
- [SalesForce] Lightning/Aura Components: component.find().getElement never accessible
- [SalesForce] In current SF release lightning component.find(…).getElement is not working
- [SalesForce] document.getElementById(“theID”).getComputedTextLength() is not a function
- [SalesForce] Lightning Input inside aura iteration
Best Answer
Regardless of performance, you should use
component.find
. Document query selectors aren't recommended in lightning, whereascomponent.find
has explicit support:Notice the complete absence of query selectors in the enumeration of valid methods to access the DOM. It's not a supported approach, strictly speaking, even if it may work today.