How can you change the Lightning button’s variant by clicking the button in LWC?

440    Asked by DianaCampbell in Salesforce , Asked on Aug 18, 2023

 I want to change the variant once I click the Lightning button. I have tried to build a JavaScript code based on that. But I cannot find any way to do that.  I am at a loss here. Can I get any suggestion as to how I can change the variant whenever I click on the Lightning button. 

JS Code: 


Answered by Diana Campbell

You can take help from destructing assignment: [a, b] = [b, a] to change the variant of the Lightning button. You can swap the two variables. If you store a the default variant in yearlyVariant and monthlyVariant, you can have:


Your Answer

Interviews

Parent Categories