Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8457075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:42:54+00:00 2026-06-10T12:42:54+00:00

I am trying to change CSS of a button on blur. I suspect it

  • 0

I am trying to change CSS of a button on blur. I suspect it might be a concatenation issue but am unable to figure out what I am doing wrong. Here is my code…

HTML

<input type="text" value="blue" id="textinput">
<button>Button</button>
<span id="color">red</span>

CSS

button {
 background-color:blue;
 background-image: -webkit-linear-gradient(top, white 0%, black 100%);    
}

jQuery

$("#textinput").blur(function () {
     setTimeout(function () {
          endColor = $("#textinput").val();
          $('button').css({ 
              'background-color' : endColor
              'background-image' : '-webkit-linear-gradient(top, #309ACB 0%,' + endColor + '100%)'       });
     }, 500);
});​

FIDDLE LINK

http://jsfiddle.net/krishollenbeck/p2jah/20/

It works fine when I remove the gradient CSS. So I am guessing I am concatenating the variable wrong. However I have tried it multiple ways but just can’t seem to figure it out. It is probably something really obvious.

Also note. I am using webkit gradient so test in chrome or safari. Thanks in advance for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:42:55+00:00Added an answer on June 10, 2026 at 12:42 pm

    You are missing a whitespace between your variable holding the color and the percentage string.

    '-webkit-linear-gradient(top, #309ACB 0%,' + endColor + ' 100%)'
                                                            ^
                                                            |
                                                            +-- Here
    

    A good way to debug this kind of situations is to use console.log to see the result of the concatenated string. In this case, for example, you’d get red100% instead of red 100%.

    An alternative, which imho, is less error-prone, is to use String.format(). This way, you can (more) clearly see if you are missing something:

    '-webkit-linear-gradient(top, #309ACB 0%, {0} 100%)'.format(endColor)
    

    Note that some browsers don’t support this function, but you can use this pollyfill to define it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am trying to change the button frame according to the orientation change but button
i've been trying to change the background image of the input button through css,
I'm trying to apply CSS to the element next to a radio button, but
I'm trying to change background-size using css: I want 100 heights and 100 widths,
I’m trying to make a small change on a CSS for Spiceworks . This
I'm trying to change the color of a DataGridTextColumn. Here's what I'm doing: <DataGridTextColumn
I have the following simple line in d3 but haven't an issue trying to
I'm trying to create a particular CSS button described here: http://www.2shared.com/file/5131551/412bd8a8/Sans_titre-1_copie.html Basically, it's a
Im trying out the Google Maps API Geocoding feature.The map loads fine, but im
Am a newbie who's trying out jQuery Plugin development. I am trying to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.