POV
POV

Reputation: 12005

How to check if child element has class?

I use ElementRef in Angular to get DOM elements:

private el: ElementRef;

this.el.nativeElement.children[0];

How to check if element this.el.nativeElement.children[0] has specific class?

Upvotes: 2

Views: 1785

Answers (1)

Eugene
Eugene

Reputation: 301

If it is a specific class and you know it, you can use instanceof. Like:

console.log(this.el.nativeElement.children[0] instanceof ClassName);

And it will print true or false, based on the result.

Upvotes: 2

Related Questions