0

My style sheet specifies:

.side-grad {
  background: linear-gradient(to top, #ffdd00 0%, rgba(255, 221, 0, 0) 40%, rgba(255, 221, 0, 0) 100%);
}

I'd like to overwrite this color getting the input from a color picker input#color-gradient using jquery. My understanding is that I can use decimal or hex code for the rgb component of rgba(), so I type this into my console:

>> colorGradient = $("#color-gradient").val()
"#ff00cc"
>> $(".side-grad").css("background",(
     "linear-gradient(to top," 
     + colorGradient 
     + " 0,rgba(" 
     + colorGradient 
     + ",0) 40%,rgba(" 
     + colorGradient 
     + ",0) 100%)"
     )
   );
Object { 0: <div.side-grad>, 1: <div.side-grad>, length: 2, prevObject: Object, context: HTMLDocument → example.html, selector: ".side-grad" }

No error is thrown, but visually nothing changes. If I set `background: #ff00cc" there's no problem and the color changes as anticipated. What am I screwing up?

2
  • Create two css classes, then you can switch over. using addClass and removeClass Commented Nov 9, 2015 at 13:16
  • This is for a theme visualization tool, so .side-grad is already the dynamic css class. Commented Nov 9, 2015 at 13:27

1 Answer 1

0

No, you cannot use hex in rgba. Here's the formal syntax: https://developer.mozilla.org/en/docs/Web/CSS/background-color#Formal_syntax

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.