+ Start a Discussion
YukinonYukinon 

Get value from LWC button

I want to get the value of the clicked button but it's returning undefined when using event.getSource().get("v.cs")

Component
<aura:component controller="CaseCreationController" implements="flexipage:availableForAllPageTypes" access="global">
  	<aura:attribute name="caseType" type="List" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
     <lightning:card>
        <div class="slds-p-around_medium">
            <aura:iteration items="{!v.caseType}" var="cs">
            <lightning:button variant="brand-outline" label="{!cs}" onclick="{!c.createCase}" name="{!cs}" value="{!cs}" />
   		 </aura:iteration> 
        </div>
   	</lightning:card>
</aura:component>
JS
createCase : function (cmp, event, helper) {
   		var btnVal = event.getSource().get("v.cs");
        alert(btnVal);
    }

User-added image
 
Best Answer chosen by Yukinon
CharuDuttCharuDutt
Hii Yukinon
Try Below Line
event.getSource().get("v.value")
Please Mark It As Best Answer If It Helps
Thank You!

All Answers

CharuDuttCharuDutt
Hii Yukinon
Try Below Line
event.getSource().get("v.value")
Please Mark It As Best Answer If It Helps
Thank You!
This was selected as the best answer
ravi soniravi soni

hi Yukinon,
You need to try below code for getting data.
For Value => event.getSource().get('v.value');
For Label => event.getSource().get('v.label');

you can get any attribute value from  event.getSource().get('v.attributeName');

let me know by marking it as the best answer.
Thank you