I’m trying to figure out if a div has an iframe and then apply a css class to another div if it does. The iframes are loaded dynamically from google ad manager. So if the div has an iframe then I need to hide something else on the page. For some reason I just cant figure it out.


if($(‘YOUR_DIV_SELECTOR’).children(‘iframe’)){
$(‘YOUR_OTHER_DIV_SELECTOR’).addClass(‘YOUR_NEW_CLASS’);
}
if($('YOUR_DIV_SELECTOR').children('iframe')) {
This condition will always return true because jQuery returns an object even if there are no matches. You’d need to check .length on the object.
Probably something along the lines of:
jsfiddle
What’s putting the iframe in the div?
google ad manager
Members
Online

source