X
X
Xrist1An2015-01-16 21:34:30
JavaScript
Xrist1An, 2015-01-16 21:34:30

How to write conditions for the existence of a DOM element in JS?

There is a structure like this:

<div id="block">
  <div>
    <iframe>
    #document
      <html>
        <body>
          <iframe></iframe> <!-- вот этот iframe -->
        </body>
      </html>
    </iframe>
  </div>
</div>


You need to somehow write a condition on JS \ JQuery, that if the same iframe (the deepest) exists, then do something.
I don't know how to write a call/check of this iframe through such a long chain of nested elements. Thank you in advance for your help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IceJOKER, 2015-01-16
@Xrist1An

if($('#block body iframe').length)
  alert('exists');

//также last() метод есть )

isn't it easier to give the id also to the iframe ? O_O

S
Serezha Gromkov, 2015-01-16
@sgromkov

if($('iframe') !== undefined)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question