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 7547469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:27:39+00:00 2026-05-30T09:27:39+00:00

I’ve seen a couple of other posts on here in regards to jQuery .css()

  • 0

I’ve seen a couple of other posts on here in regards to jQuery .css() not working with -webkit-gradient, however I’ve yet to find one pertaining to -ms-linear-gradient, -o-linear-gradient and linear-gradient.

Long story short, I’ve created a function which sets a #hex based background gradient for an element using the all the most popular CSS properties for cross-browser compatibility, taken directly from ColorZilla.

Here’s a look at the particular snippet I’m talking about:

$(elem).css({
        'background': b,
        'background': '-moz-linear-gradient(top,  '+a+' 0%, '+b+' 100%)', 
        'background': '-webkit-gradient(linear, left top, left bottom, color-stop(0%,'+a+'), color-stop(100%,'+b+'))',
        'background': '-webkit-linear-gradient(top,  '+a+' 0%,'+b+' 100%)',
        'background': '-o-linear-gradient(top,  '+a+' 0%,'+b+' 100%)', // Breaks execution
        'background': '-ms-linear-gradient(top,  '+a+' 0%,'+b+' 100%)', // Breaks execution
        'background': 'linear-gradient(top,  '+a+' 0%,'+b+' 100%)', // Breaks execution
        'filter': 'progid:DXImageTransform.Microsoft.gradient( startColorstr=\''+a+'\', endColorstr=\''+b+'\',GradientType=0 )'
        });

I’ve placed a //breaks execution comment next to each of the properties that when active (either collectively, or individually) break the script’s execution (no other properties, e.g. background: b (b of course being a variable) are set.

I’m absolutely stumped as to why this is.

So far I’ve tried:

  • Using double quotes instead of single quotes.
  • Replacing the variable usage (+a+, +b+) with actual hex’s.

I’m thinking perhaps there’s a character in those three that needs to be escaped or something?

Any help towards figuring out why this is would be greatly appreciated!

  • 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-05-30T09:27:40+00:00Added an answer on May 30, 2026 at 9:27 am

    You’re setting and re-setting the background property of the JavaScript object again and again.

    In the end, if you try logging the object you’re passing to .css(), you’ll see it only contains 2 properties: The last background value in the list, and filter.

    So your code is equivalent to:

    $(elem).css({
        'background': 'linear-gradient(top,  '+a+' 0%,'+b+' 100%)',
        'filter': 'progid:DXImageTransform.Microsoft.gradient( startColorstr=\''+a+'\', endColorstr=\''+b+'\',GradientType=0 )'
    });
    

    You can try something like this instead (jsfiddle demo):

    var i, l, backgrounds = [
        '-moz-linear-gradient(top,  '+a+' 0%, '+b+' 100%)', 
        '-webkit-gradient(linear, left top, left bottom, color-stop(0%,'+a+'), color-stop(100%,'+b+'))',
        '-webkit-linear-gradient(top,  '+a+' 0%,'+b+' 100%)',
        '-o-linear-gradient(top,  '+a+' 0%,'+b+' 100%)',
        '-ms-linear-gradient(top,  '+a+' 0%,'+b+' 100%)',
        'linear-gradient(top,  '+a+' 0%,'+b+' 100%)'
    ];
    
    // Try each background declaration, one at a time
    // Like in a stylesheet, the browser should(!) ignore those
    // it doesn't understand.
    for( i = 0, l = backgrounds.length ; i < l ; i++ ) {
        $(elem).css({ background: backgrounds[i] });
    }
    
    $(elem).css({
        'filter': "progid:DXImageTransform.Microsoft.gradient( startColorstr='"+a+"', endColorstr='"+b+"',GradientType=0 )"
    });
    

    This code is of course not very efficient at all. And for browsers that understand more than one of the declarations, it’ll pointlessly overwrite those that work already. So optimize as you see fit.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.