[英]Get value of CSS property using JavaScript
I need to do some if
logic depending if an element in the DOM has the property display: none
. 我需要做一些
if
逻辑,取决于DOM中的元素是否具有display: none
属性display: none
。
I was looking at getComputedStyle()
and have come this far: 我一直在看
getComputedStyle()
并走到了这么远:
var bla = document.querySelectorAll('#nvk-popup-wapper')[0]
getComputedStyle(bla)
This returns an object and if I expand it in Chrome's console I can see a property display
with a value of none
. 这将返回一个对象,如果在Chrome的控制台中将其展开,则可以看到一个
display
值为none
的属性。 But if I go bla.display
I get undefined
whereas I had hoped to get the value of the display
property for that element. 但是,如果我去
bla.display
我将undefined
而我希望获得该元素的display
属性值。
For a particular element, how do I get the value of the display
property for that element? 对于特定元素,如何获取该元素的
display
属性值?
try this 尝试这个
var style = getComputedStyle(bla)
var display =style.getPropertyValue('display');
Using JQuery : 使用JQuery:
$("#some-element").css("display");
would return the property display
of the some-element
将返回
some-element
的属性display
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.