简体   繁体   English

类型“ HTMLElement”上不存在属性“ pseudoStyle”

[英]Property 'pseudoStyle' does not exist on type 'HTMLElement'

I'm trying to modify the pseudo element's height using Typescript. 我正在尝试使用Typescript修改伪元素的高度。

I'm getting the following error in my IDE (vscode) 我在IDE(vscode)中遇到以下错误

This is my code. 这是我的代码。

// select element
let el: HTMLElement = document.getElementById('filter-container');
//  style the height of psydo element
el.pseudoStyle("before", "height", newHeight);
...

You can't style a pseudo-class on a particular element alone, you can do it by altering the stylesheet: 您不能仅对特定元素设置伪类的样式,而是可以通过更改样式表来做到这一点:

document.styleSheets[0].insertRule('#id:hover { background-color: blue; }', 0);
document.styleSheets[0].cssRules[0].style.backgroundColor= 'blue';

尝试el.prototype.pseudoStyle("before", "height", newHeight);

As I know in JavaScript we can't change pseudo elements and I guess same in TS because of it is a JS superset. 正如我在JavaScript中所知道的,我们无法更改伪元素,并且我猜在TS中也是如此,因为它是JS超集。 With best regards. 最诚挚的问候。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM