1

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? – Martin Lezer Jul 24 '17 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 '17 at 15:54
2

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";
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 -->
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.