Inherited CSS Values via Javascript

后端 未结 4 2040
半阙折子戏
半阙折子戏 2020-12-06 17:55

On my page I am changing some css styles via javascript. When I try and pull a value that has been inherited - it comes up blank. Consider the following:

            


        
4条回答
  •  庸人自扰
    2020-12-06 18:30

    Your second CSS rule:

    .Sliding #FilterBox
    {
        height: 185px;
        background-color: Fuchsia;
    }
    

    will match anything with id "FilterBox" that is a descendant of anything with a class "Sliding", so this rule does not apply to your div.

    And to get the computed style, you can refer to Fabien's answer, or consider using jQuery, which makes this stuff a lot easier:

    using jQuery, $("#FilterBox").css("display") would return the current value for "display".

提交回复
热议问题