Skip to main content
added 261 characters in body
Source Link
TrevorBliss
  • 3.8k
  • 15
  • 31

This is because you are trying to access the DOM elements in the init handler before they have been rendered. Even if you use the native document.getElementById('myDiv') call inside the init handler with LockerService disabled, you'll get null back.

If you move your find('myDiv') call to a button click handler it will return the correct SecureComponent object.

Also, the access="global" on a div element won't do anything useful. That property is specifically for Aura types (components, attributes, etc).

Edit (Nov. 16):

From Doug's comment, for situations similar to this you may want to explore custom renderers. Handle with care though.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_renderers.htm?search_text=renderer

This is because you are trying to access the DOM elements in the init handler before they have been rendered. Even if you use the native document.getElementById('myDiv') call inside the init handler with LockerService disabled, you'll get null back.

If you move your find('myDiv') call to a button click handler it will return the correct SecureComponent object.

Also, the access="global" on a div element won't do anything useful. That property is specifically for Aura types (components, attributes, etc).

This is because you are trying to access the DOM elements in the init handler before they have been rendered. Even if you use the native document.getElementById('myDiv') call inside the init handler with LockerService disabled, you'll get null back.

If you move your find('myDiv') call to a button click handler it will return the correct SecureComponent object.

Also, the access="global" on a div element won't do anything useful. That property is specifically for Aura types (components, attributes, etc).

Edit (Nov. 16):

From Doug's comment, for situations similar to this you may want to explore custom renderers. Handle with care though.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_renderers.htm?search_text=renderer

Source Link
TrevorBliss
  • 3.8k
  • 15
  • 31

This is because you are trying to access the DOM elements in the init handler before they have been rendered. Even if you use the native document.getElementById('myDiv') call inside the init handler with LockerService disabled, you'll get null back.

If you move your find('myDiv') call to a button click handler it will return the correct SecureComponent object.

Also, the access="global" on a div element won't do anything useful. That property is specifically for Aura types (components, attributes, etc).