How do I detect the inherited background-color of an element using jQuery/JS?

后端 未结 6 918
礼貌的吻别
礼貌的吻别 2020-11-30 11:40

Using jQuery (or just JavaScript), how do I detect the inherited background-color of an element?

For example:

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 12:17

    #target has no background color to read because background-color is not inherited.

    you could write some javascript that keeps climbing up the DOM tree to search for a background-color declaration until it finds one., but there's no guarantee that that will get you the background color of an element that actually contains your #target.

    btw. the css() method gets computed styles, so its giving you the correct reading.

提交回复
热议问题