javascript - 类型 'pseudoStyle' 上不存在属性 'HTMLElement'

标签 javascript angular typescript ionic3 pseudo-element

我正在尝试使用 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/

相关文章:

javascript - 如何修复 Angular 中未定义的形式错误 'validate'

angular - 你如何在 Angular 5 的自定义验证指令中使用多个参数?

angular - 错误 : node_modules/@types/d3-dsv/index. d.ts(159,60):错误 TS1005:预期为 ','

javascript - 如何按 'key' 与相应标题下方列出的关联数据进行分组

javascript - ES6 super() 在构造函数中实际上做了什么?

javascript - 如何在 React 自定义 Hook 中正确调用 useState?

angular - 空注入(inject)器错误: No provider for ElementRef

node.js - 将 Typescript 类发布为 npm 包

angular - 类型 'Draw' 上不存在属性 'typeof Control'

javascript - 从工厂访问范围