0

Are there any function, library or anything else can detect values of css properties?

Take "position" for an example, use some methods then I can get "absolute", "static", "relative" ... are "position"'s values.

So I can detect the supporting degree of a css property. And how many values for this property I can use.

Thanks very much!

4
  • If my guess is right, you wanted to know the possible values for a particular css property.. right? Commented Nov 26, 2013 at 3:57
  • document.getElementById('your element').style returns all of your current styles to that particular element.. Commented Nov 26, 2013 at 3:59
  • Just look here, the best compatibility tables for support HTML and CSS: caniuse.com Commented Nov 26, 2013 at 4:03
  • I'm sorry. Maybe I describe it unclearly. I mean the value of the property. "caniuse.com" just the compatibility data of the property. But it can't tell me the details for each properties. Commented Nov 27, 2013 at 7:38

3 Answers 3

3

If I am understanding correctly, you wish to iterate over the possible values for a css property. Unfortunately, there is no way to do this. What you could do is store the possible values so that when you need to list them, you can just look them up. Take the following example.

var cssProperties = { position: ['inherit', 'static', 'relative', 'absolute', 'sticky', 'fixed'], float: ['inherit', 'left', 'right', 'none'] };

function lookupCssValues(property) {
    return cssProperties[property];
}

You can traverse the possible css properties for an element by doing something like this:

for(var property in element.style) {
    if(typeof elem.style[property] === 'string') {
        console.log(property) // this is a css property for the element
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, thanks, I think you got the point. I hope there some ways to do this. Indeed, no way.
0

You can do this easily with jQuery!

$('.element-in-question').css('position');

http://jsfiddle.net/h7KHT/

1 Comment

I'm sorry. Maybe I describe it unclearly. I mean the possible values for a property. Not the values I set.
0
$('.someelement').css("position")

1 Comment

I'm sorry. Maybe I describe it unclearly. I mean the possible values for a property. Not the values I set.

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.