Answers for "read properties from css file"

CSS
1

read properties from css file

function propertyFromStylesheet(selector, attribute) {
    var value;

    [].some.call(document.styleSheets, function (sheet) {
        return [].some.call(sheet.rules, function (rule) {
            if (selector === rule.selectorText) {
                return [].some.call(rule.style, function (style) {
                    if (attribute === style) {
                        value = rule.style.getPropertyValue(attribute);
                        return true;
                    }

                    return false;
                });
            }

            return false;
        });
    });

    return value;
}

console.log(propertyFromStylesheet(".box", "height"));
Posted by: Guest on July-06-2021
1

read properties from css file

.box {
    position:absolute;
    background-color:red;
    height:10px;
    width:10px;
}
Posted by: Guest on July-06-2021

Browse Popular Code Answers by Language