How to find the margin-right of the element via js?

<div class="div"></div>
.div{
margin-right: 14px;
}
April 3rd 20 at 18:50
3 answers
April 3rd 20 at 18:52
Solution
const el = document.querySelector(".div");
const getprop = window.getComputedStyle(el, null).getPropertyValue("margin-right");
Displays as 14px. Whether it is possible to bring the number to perform the mathematical operations? - angel commented on April 3rd 20 at 18:55
@angel, parseFloat(getprop); - Monserrat.Rueck commented on April 3rd 20 at 18:58
April 3rd 20 at 18:54
Solution
getComputedStyle(myElement); // get all styles
getComputedStyle(myElement).marginRight; // get the margin-right
April 3rd 20 at 18:56
Here is an example of how to

Find more questions by tags JavaScript