我正在尝试使用 Typescript 修改伪元素的高度。
我在 IDE (vscode) 中收到以下错误
这是我的代码。
// select element
let el: HTMLElement = document.getElementById('filter-container');
// style the height of psydo element
el.pseudoStyle("before", "height", newHeight);
...
最佳答案
您不能单独在特定元素上设置伪类的样式,您可以通过更改样式表来实现:
document.styleSheets[0].insertRule('#id:hover { background-color: blue; }', 0);
document.styleSheets[0].cssRules[0].style.backgroundColor= 'blue';
关于javascript - 类型 'pseudoStyle' 上不存在属性 'HTMLElement',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50249951/