You need to sign in to do that
Don't have an account?
Raksha Narayan
QuerySelector not working within template tag in LWC
I want to get the 'Enter the message...' in JS. Below is my LWC code:
<template>
<lightning-card title="Raksha: Mock Email to Case Automation">
<lightning-card if:true={showAutoResponseRuleModal}>
<div class="slds-container_small">
<template for:each={xmldata} for:item="mapKey">
<lightning-layout-item key={mapKey.booleanFilter} size="12">
<a></a>
<p data-id="test"> Enter the message... </p>
</lightning-layout-item>
</template>
</div>
</lightning-card>
</lightning-card>
</template>
JS:
const result = this.template.querySelector('test');
I am not able to get the message in JS. Can anyone please let me know what I am missing?
<template>
<lightning-card title="Raksha: Mock Email to Case Automation">
<lightning-card if:true={showAutoResponseRuleModal}>
<div class="slds-container_small">
<template for:each={xmldata} for:item="mapKey">
<lightning-layout-item key={mapKey.booleanFilter} size="12">
<a></a>
<p data-id="test"> Enter the message... </p>
</lightning-layout-item>
</template>
</div>
</lightning-card>
</lightning-card>
</template>
JS:
const result = this.template.querySelector('test');
I am not able to get the message in JS. Can anyone please let me know what I am missing?
Please use below line of code in .JS:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
I tried the above code. But on printing element it is giving me null.
You need to add this line in
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
let recordName = this.template.querySelector('[data-id="test"]').innerText;
Thanks
You have remomed Best Answer, any reason?
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh