Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!