Are you unable to capture div's style.display value lwc?
I'm trying to capture the display css property value for an element. However, unless I set style.display value in js it does HTML:
A
B
C
CSS:
.dropdown{ position: absolute; display: none; background: white; }
JS: Below JS method is be called from one of the input boxes in html:
updateDropDownStyle(){ console.log('display : ' ,this.template.querySelector('.dropdown').style.display); }
However, the console prints nothing at all. However, if in the same method I set the element.style.display value as none and then try to console the above - it prints none. What's the issue here?
Style.display is expected. The classes do not impose their values on the style attribute of the DOM element. However, if you want to know the style, use getComputedStyle instead:
let style = window.getComputedStyle(this.template.querySelector('.dropdown')); console.log(style.display); // should output "none"