+ Start a Discussion

Accessing Components with their IDs - how does it work?

Anyone know why $Component is useful?


For example, what is really the difference between  







... there doesn't seem to be any validation on the $Component  tag.

Best Answer chosen by Admin (Salesforce Developers) 

Because $Component is protection against changes in DOM id creation.  DOM ids can and do change, especially when the structure of your page changes.


We don't promise that the way DOM ids are created, based on the component ids you pass into your id attributes, will be the same forever, so that's why you have a safe mechanism to access your components by id.


Often times components that probably should have been contributing to the resulting DOM id were not, and we have made changes to this before.  By using $Component correctly, your script should never break (unless you drastically rearrange your page, of course).