HTML <div class="green" style="color: red;"> Hello </div> css .green { color: green !impotrant } JS let elemColor = document.querySelector('.green').style.color; console.log( elemColor )
CSS | style |
---|---|
padding-top | paddingTop |
margin-left | marginLeft |
border-bottom-left-radius | borderBottomLeftRadius |
Перезапись атрибутов методом setAttribute
HTML <div class="text" style="color: red;"> Hello </div> JS let elem = document.querySelector('.text'); elem.style.backgroundColor = " orange "; HTML <div class="text" style="background-color: orange; color: red;"> Hello </div>
HTML <div class="text" style="color: red;"> Hello </div> JS let elem = document.querySelector('.text'); elem.setAttribute('style','background-color: orange'); HTML <div class="green" style="background-color: orange;"> Hello </div>
Используйте window.getComputedStyle(elem) для вычесленных CSS свойств.