You need to sign in to do that
Don't have an account?
Jake Jeon
Dynamically change background color using controller on lightning controller
Hi all,
I would like to implement component having a background color change feature.
I tried to get some information on how to change CSS using Lightning Component controller, I couldn't get much about it.
Please advise me if you have any idea to solve this.
Thanks for your help in advance.
Component :
I would like to implement component having a background color change feature.
I tried to get some information on how to change CSS using Lightning Component controller, I couldn't get much about it.
Please advise me if you have any idea to solve this.
Thanks for your help in advance.
Component :
<aura:component> <div> <lightning:input type="color" label="Color" name="color" value="" onchange="{!c.colorChanger}" aura:id="color"/> </div> </aura:component>Controller :
({ colorChanger : function(component, event, helper) { var color = component.find("color").get("v.value"); this.css({"background" : color}) } })*tried this.style.background = color;
Please find the tested code to change the background of any div in the component.
Component code:
Controller js code:
Style code:
Output:
Naveen
Team codengine.in
All Answers
Please find the tested code to change the background of any div in the component.
Component code:
Controller js code:
Style code:
Output:
Naveen
Team codengine.in
Thanks for your reply!
I understand that using $.util make component change their class to give a variation of CSS.
In my case, I would like to give them changes directly using javascript like document.getElementById('id1').style.color = 'red'
My scenario is the same as below :
Use color picker choose the color, using onchange attribute send a color code to the controller and directly give it background-color changes.
Naveen