javascript - Why do querySelector and querySelectorAll NOT iterate within an iframe? - Stack Overflow

This works:parent.document.getElementById('iframeID').contentWindow.document.querySelectorAl

This works:

parent.document.getElementById('iframeID').contentWindow.document.querySelectorAll('*[id^="elementId"]');

But this doesn't:

parent.document.getElementById('iframeID').querySelectorAll('*[id^="elementId"]');

According to querySelectorAll's reference:

The Element method querySelectorAll() returns a static (not live) NodeList representing a list of elements matching the specified group of selectors which are descendants of the element on which the method was called.

If contentWindow is a descendant of the iframe element, shouldn't the iframe element be recursively iterated until, eventually, contentWindow and document are encountered, as it is the case with, for example:

<div id="div1">
  <div id="div2">
    <div id="div3">
      <div id="div4">
        <div id="div5">

        </div>
      </div>
    </div>
  </div>
</div>


<script>
console.log(document.getElementById("div1").querySelectorAll('div'));
</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745087614a4610497.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信