MiChAeLoKGB MiChAeLoKGB - 7 months ago 18
Javascript Question

jQuery if iframe with class exists

I am trying to detect if iframe with specific class exists, but its not working for me.

I need to detect if iframe with chat exists on site https://gaming.youtube.com for one of my scripts. Its weird that in this demo it can detect iframe: http://jsfiddle.net/t7qMF/13/ but when you go to any live stream on https://gaming.youtube.com, you can not detect if the iframe with chat exists.

When I use

$("iframe.class");
it returns the iframe, but when I try
$("iframe.class").length;
I get
undefined
.

I tried googling, but everybody is saying to use
element.length
, which is just not working for me. It actually returns undefined even when I just use
$("iframe").length


Here is screen of my console where its not working:

enter image description here

Thanks.

Answer

Because $ is not always jQuery. In Chrome dev console, when jQuery is not available, it is alias to document.querySelector()