How to take the "style" of an element inside a div

Asked

Viewed 310 times

0

I wanted to take the font size of the element with the id "test"

<div id="div">
    <h1 id="teste">OLÁ</div>
</div>

2 answers

0

You can use the window.getComputedStyle to get all styles of the element h1, and then the font-size:

var h1 = document.getElementById('teste');
var fontSize = window.getComputedStyle(h1, null).getPropertyValue('font-size');
console.log("font-size: " + fontSize);
<div id="div">
    <h1 id="teste">OLÁ</div>
</div>

0


It is possible to know the font size through Javascript:

window.getComputedStyle(document.getElementById("teste")).fontSize

Browser other questions tagged

You are not signed in. Login or sign up in order to post.