jQuery: Change part of background CSS

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

jQuery: Change part of background CSS

Post 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 ;-)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: jQuery: Change part of background CSS

Post 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))'
  )
});
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply