Get properties Css

0

Does anyone know how to identify, using javascript, only the css properties of a Class, for example:

.in-text{
   color: red;
   font-weight: 500;
}

in html

<label class="in-text">Digite um texto</label>

I tried this method, getComputedStyle(document.querySelector('.in-text')) however I get many properties and not only the in-text class

    
asked by anonymous 22.05.2017 / 20:03

1 answer

0

You can use getComputedStyle () that returns an object with all the attributes that were declared for the last element. And using getPropertyValue () you pass the name of the css attribute you want to access

var elemento = document.getElementById("algo");
window.getComputedStyle(elemento, null).getPropertyValue("margin-top")

If you want to know more about this, you can see the documentation on the link: link

    
23.05.2017 / 05:23