Difference between body.style.backgroundColor and window.getComputedStyle(body).getPropertyValue('background-color')

后端 未结 4 1271
青春惊慌失措
青春惊慌失措 2020-12-20 02:11

I am trying to get the background color of the body, and I am wondering what is the difference between:

body.style.backgrounColor and

wi         


        
4条回答
  •  攒了一身酷
    2020-12-20 02:22

    Actually, document.body.style.backgroundColor will get only inline style property of an element like this

    
    

    On the other hand window.getComputedStyle will get the actual property after CSS and styles are applied to the element, for example, this is possible to get using window.getComputedStyle

    body{
        background-color:#fff;
    }
    

    But it's not possible to read css style given above using document.body.style.backgroundColor. Check this example. Also, check this.

提交回复
热议问题