Page 1 of 1

jQuery: Change part of background CSS

Posted: Wed Dec 07, 2011 10:25 am
by jmansa
I'm making a realtime css editor using jQuery and it works just perfect except for one thing...

When I use solid backgrounds it works fine like this:

Code: Select all

jQuery("#boxtitleback").attachColorPicker();
jQuery("#boxtitleback").change(function() {jQuery('#boxtitle h1').css("background-color",jQuery("#boxtitleback").getValue())});
But what if I want to change one color of an -webkit-gradient???

How do i do that?
background:-webkit-gradient(linear,0% 0,0% 100%,from(#333),to(#5e5e65));

Thanks in advance ;-)

Re: jQuery: Change part of background CSS

Posted: Fri Dec 09, 2011 11:33 am
by pickle
You'll have to just to string concatenation:

Code: Select all

jQuery("#boxtitleback").change(function() {
  jQuery('#boxtitle h1').css(
    "-webkit-gradient",
    'linear, 0% 0,0% 100%, from('+jQuery("#boxtitleback").getValue()+'),to(#5e5e65))'
  )
});