Change the label of the clicked salesforce lightning button
Lightning Button
A lightning-button a component represents a button element that executes an action. Use lightning-button where users need to:
- submit or reset a form
- begin a new task
- trigger a new UI element to appear on the page
- specify a new or next step in a process
For More info, you can check salesforce official doc here
Change label of lightning button
Create a lightning aura component(eq: auraComponent) & write below script in .cmp(eq: auraComponent.cmp) file.
<aura:component>
<lightning:button class="deselectAllitem" onclick="{! c.docheckClick }" name="Test" label="Select All" title="Test" />
<lightning:button class="deselectAllitem" onclick="{! c.docheckClick }" name="Test2" label="Select All" title="Test2" />
</aura:component>
After adding the above script, create a js controller(auraComponentController.js) file & write the below script.
({
docheckClick : function(component, event, helper) {
var label = event.getSource().get("v.label");
if(label == 'Select All') {
event.getSource().set("v.label","Deselect All")
} else {
event.getSource().set("v.label","Select All")
}
}
})
Now create a lightning aura(auraComponentPreview) app to preview the functionality & include the above aura component in the lightning aura app(auraComponentPreview.app).
<aura:application>
<c:auraComponent/>
</aura:application>
Now click the “preview” button to check component functionality.
Tags:
Salesforce
View Comments (2)
Comment or Ask a Question
Quick Links