我的想法来自:
Can you check an object's CSS display with JavaScript?
现在看下面我的代码:
HTML :
<div style="display: none">
<input type="text" id="myInput" value="5">
</div>
Javascript:
console.log(document.getElementById('myInput').value);
console.log(document.getElementById('myInput').style.display);
我电脑上的结果在我的浏览器控制台上什么也没有显示。
My problem :
I need to know the parent of input type text style. cause if the parent style is none make the input type text show nothing when i try to get value of input type text. So the main question is how to get parent style WITHOUT add new id/class/name in div?
最佳答案
您可以将 .parentNode
属性与 style
一起使用,以获得您正在寻找的特定 CSS 属性。所有这些都列在对象上。 HTML 将是:
<div style="display: none">
<div id='one'>
</div>
</div>
javascript 将是:
var node = document.getElementById('one');
console.log(node.parentNode.style.display);
关于javascript - 如何使用 Javascript 了解父/容器样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43535732/