0

How do I apply the following css code using jquery

#centeredImage
{
   -webkit-filter: grayscale(20%) invert(0) blur(1px); 
}

Already tried this, didn't work

$('#centeredImage').css('-webkit-filter','grayscale(20%) invert(0) blur(1px)'); 
2
  • It works for me, jsfiddle.net/fn55v Commented Mar 3, 2014 at 9:08
  • try ...css('WebkitFilter', .... Commented Mar 3, 2014 at 9:08

3 Answers 3

3

Just use filter:

$('#centeredImage').css('filter','grayscale(20%) invert(0) blur(1px)');

jQuery automatically set prefixes.

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

1 Comment

the normal filter tag doesn't work for me at all, not even using css only. I'm using the newest chrome version on fedora..
2

You can use WebkitFilter instead:

$("#centeredImage").css({
    WebkitFilter: 'grayscale(20%) invert(0) blur(1px)'
})

Fiddle Demo

Comments

0

Maybe create css as a class

.centered-image
{
   -webkit-filter: grayscale(20%) invert(0) blur(1px); 
}

Then in jQuery

$('#centeredImage').addClass('centered-image');

At least this way your keeping the separation of javascript and styling...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.