Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
Get Element Reference of a DOM Element created dynamically from a library

I want to add a class to a DOM Element by taking it's reference. But the element is created by a library and I cannot access it directly, means I can't use ViewChild or HostBinding on that DOM Element.

I can access it directly using document.querySelector(<.classname>) and then add another class to it. But it is Javascript, right? Is there any way to do it in Angular? How to do DOM Manipulation for a dynamically created DOM Element not having an id or #reference?

I want to add a class "hidden" to image layer element of Openlayers. I am using the above method but how to do it in angular?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use ElementRef. Simply inject ElementRef in your component and you can select the DOM element you want using its class. Im am assuming that the element that you are looking for already has another class which you can refer to. Here is an example implementation:

import {ElementRef} from '@angular/core';

export class MyClassComponent {

   constructor(private: elRef: ElementRef) {
   
      findMyElement(): void { 
         console.log(this.elRef.nativeElement.querySelector('.myclass'));
      }
   }
}

Please note that, querySelector will find the first occurrence of this element. Therefore, you have to use it with caution.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda