junxi
junxi

Reputation: 165

Detect available css values for a specific property

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!

Upvotes: 0

Views: 85

Answers (3)

Ravi Tom
Ravi Tom

Reputation: 13

$('.someelement').css("position")

Upvotes: 0

xcopy
xcopy

Reputation: 2288

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
    }
}

Upvotes: 3

Ming
Ming

Reputation: 4578

You can do this easily with jQuery!

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

http://jsfiddle.net/h7KHT/

Upvotes: 0

Related Questions