0
let element = id('mydiv'); // id() is element Selector by id
let style = getComputedStyle(element);
let eleHeight = parseInt(style.height);

I know I can get any style value using the js code above.

Now focus on the following.

function getCSS(css, element) {
    return parseInt(getComputedStyle(element).css);
}

// usage

let eleHeight = getCSS('height', id('mydiv')); // but it will return 'NaN'

I am trying to create my own instantiated function to do this. Please make it workable

1
  • 1
    Consider not putting the key in the file name, but use a query parameter instead? http://anyweb.ext/media/filename.mp4?key=XXXX Commented Jan 4, 2022 at 11:42

1 Answer 1

1

You will need to use a string for the CSS property as object keys can be used like arrays or using the "dot" way.

function getCSS(css, element) {
    return parseInt(getComputedStyle(element)[css]);
}

let eleHeight = getCSS("height", id('mydiv'))
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. The only problem was defining the CSS property. Now I understand. Thanks again man...

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.