0
@Color1 = #fff;
@Color2 = #b00;

h1 {
  color:@Color1;
  background:@Color2;
}

How can i change @Color1 and @Color2 with JS? This is my example code.

or

.chat-wrapper .chat-message.chat-message-sender .chat-message-wrapper:before {
    right: -20px;
    border-left-color: #8AC0D9;
}

How can I reach the border-left-color JavaScript code? I have a dynamically changing color value. I have to apply this. How can I do it ?

EDIT

main.css // this my css file @Álvaro-gonzález

.chat-wrapper .chat-message.chat-message-sender .chat-message-wrapper,
.chat-wrapper .chat-message.chat-message-sender .chat-message-content {
    float: right;
}
.chat-wrapper .chat-message.chat-message-sender .chat-message-wrapper:before {
    right: -20px;
    border-left-color: #8AC0D9;
}
5
  • I don't think this is supported yet... You may use LESS for this. Commented Apr 21, 2017 at 8:55
  • 1
    I don't think this is pure CSS. You're probably using some CSS preprocessor. If that's the case, the browser does not even see the original code, just the generated CSS. Please update the question to reflect the missing information. Commented Apr 21, 2017 at 9:26
  • What is @Color1? Commented Apr 21, 2017 at 12:02
  • Example code @torazaburo Commented Apr 21, 2017 at 12:16
  • This is not how CSS works. You do not change property values in CSS rules. Instead, you add classes to elements so the right rule is selected. The only thing JS needs to do is add or remove the necessary classes. This is basic CSS. Commented Apr 21, 2017 at 12:20

1 Answer 1

1

here is the answer to your question. So if you want to change value of any variable from linked question, you nee to do something like:

document.styleSheets[0].rules[0].style.setProperty("--red", "#FF0000");

Of course indexes of arrays must be double checked of iterated for finding corresponding selector

Sign up to request clarification or add additional context in comments.

3 Comments

@forguta Did you just copy the pseudo-code from that other question and pretended that it's working CSS??
it's hardly ever a good idea, and hardly ever necessary. to mutate the style sheet like this.
I try not to discuss an entire idea. There is a question and here is an answer. It's pretty simple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.