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

210
Vistas
Select an iframe, if the parent element has a specific class

So I have this piece of jQuery inside one of my methods:

videos: $('iframe[src*="vimeo"], iframe[src*="youtube"]'),

What it currently does is select all <iframe> elements with the src containing youtube.

Here is what I'm attempting to do:

Select all the <iframe> elements with the src containing youtube and NOT containing the modal class in the parent element.

So let's say that I have this:
enter image description here

If it has the modal class inside the <section> don't select the <iframe>.

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

0

Although I think jQuery has a specific way to do this, you can also use the CSS , not the pseudo-class .

 const iframes = $('section:not(.modal) iframe[src*="vimeo"], section:not(.modal) iframe[src*="youtube"]');

Note that this will work if some parent/ancestor section doesn't have the modal class.

If you need it to be the direct parent, use:

 const iframes = $('*:not(.modal) > iframe[src*="vimeo"], *:not(.modal) > iframe[src*="youtube"]');

I've also used the universal selector * so it's not specific to the section element.

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