我在 Angular 中使用 ElementRef 来获取 DOM 元素:
private el: ElementRef;
this.el.nativeElement.children[0];
如何检查元素 this.el.nativeElement.children[0]
是否具有特定类?
最佳答案
如果它是一个特定的类并且您知道它,则可以使用instanceof。喜欢:
console.log(this.el.nativeElement.children[0] instanceof ClassName);
它会根据结果打印 true 或 false。
关于angular - 如何检查子元素是否有类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55852403/