1

Is it possible to get an attribute of a DOM element, for example line-height, using javascript? I need to get this value to be able to add it with another value. I want this to be dynamic, that if I change this value in css, it will automatically change in javascript

2
  • w3schools.com/js/js_htmldom_css.asp check this link :) Commented Nov 26, 2020 at 12:23
  • 2
    This is to pass a value to the attribute, I want to get the value of the attribute Commented Nov 26, 2020 at 12:36

1 Answer 1

2

You can use getComputedStyle()

var element = document.getElementById('id_of_element')
var elementStyle = window.getComputedStyle(element);
var lineh = elementStyle.getPropertyValue('line-height')
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much friend! It is difficult to ask questions here. There is always someone who doesn't know and demoting the question. Thank you very much for your attention, this information will help me a lot

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.