In Lightning is not possible to access CSS Style and modify css properties like background color. In my case I need to change CSS Background color style based on custom record field value.

I am interested in how to implement this on Lightning.

  • What do you mean in Lightning? Are you developing Lightning components? Jul 24, 2017 at 15:42
  • Yes, I mean how to achieve in Lightning components the same effect if we use javascript with jquery function something like $(elem).css('background', dynamicalValueOfCssBackgroundDerivenFromSObjectFieldValueOrFromSomewhereElse)
    – Patlatus
    Jul 24, 2017 at 15:54

2 Answers 2


I think you should use inline css - somethink like this:

<aura:attribute type="String" name="colorBackground" default='blue'/> 
<div style="{! 'background-color:' + v.colorBackground }">
     <!-- code -->

In Lightning components, you can also use html properties and Javascript code.

First, you can define an id to your custom div using:

<div id="test"></div>

Then, you'll be able to modify its background using Javascript:

var myDiv = document.getElementById("test");
myDiv.style.background = "dynamicalValueOfCssBackgroundDerivenFromSObjectFieldValueOrF‌​romSomewhereElse";

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .