3

Is there a generic way in javascript to check if the css property is supported by current browser or not?

I am currently using "document.compatMode" to check if it is quirks or not. But there must be a way to check specific to a property.

1

3 Answers 3

9

You can do this, ex:

typeof document.body.style.borderRadius

In supported browsers, it should return 'string'. In non supported, it will be 'undefined'

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

1 Comment

Thanks, it works. Anyways do you know a way to find pseudo class is also supported or not? I meant by ':hover',':active'.
1

There is a new DOM API CSS.supports for that purpose. FF, Opera (as supportsCSS) and Chrome Canary already implement this method.

For cross-browser compatibility you can use my CSS.supports polyfill

Example:

CSS.supports("display", "table");//IE<8 return false

But, you still need to specify browser prefix for prefixing css properties. For example:

CSS.supports("-webkit-filter", "blur(10px)");

I suggest to using Modernizr for feature-detection.

1 Comment

Thank you for your suggestion. I am familiar with Modernizr but didn't want to include a js lib for 1 single detection.
-3

No.

There's not.

1 Comment

There is never "no" for a problem.

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.