Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda