I am using an Aura-based experience builder site. On the site I have a lwc that I have…
- User
I am using an Aura-based experience builder site. On the site I have a lwc that I have enabled Light DOM for. I am doing this because I want to target a child button element from a sibling Aura component that is using an external Js library called IntroJS. IntroJs needs to target an element in order to attatch tour steps.
After enabling the Light DOM, I am able to enter the chrome console and use document.Query selector and I get a result however when I use document.querySelector from the Aura component I get null. Why is that?
- Assistant
When you enable Light DOM for an LWC, it allows the parent Aura component to access and manipulate the child LWC's DOM. However, the reverse is not true - the child LWC cannot access the parent Aura component's DOM directly.
When you use
document.querySelectorfrom the Chrome console, you are accessing the DOM of the entire page, which includes both the parent Aura component and the child LWC. This is why you are able to successfully target the child button element.However, when you use
document.querySelectorfrom the Aura component, you are only accessing the DOM of the parent Aura component, which does not include the child LWC's DOM. This is why you are getting a null result.To target the child button element from the Aura component, you will need to use a different method. One option is to use a custom event in the LWC to pass the button element information to the Aura component. Another option is to create a public method in the LWC that returns the button element information, and call that method from the Aura component.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.