DOM navigation error? getElementsByTagName error

Asked 2 years ago, Updated 2 years ago, 47 views

If you open the developer tool to get the video tag from Naver blogs or cafes and run document.getElementsByTagName('video') or document.querySelectorAll('video') you will find a strange empty array. What's more strange is that if you search <video on the Elements tab with Ctrl+F, once you click the part of the video tag you found and run document.getElementsByTagName('video') again, you will return the normally. What the hell is the problem??

javascript dom element

2022-09-20 22:12

1 Answers

I answer myself... This is because the Naver video uses the iframe tag.

document.querySelectorAll('iframe').forEach(item =>
  item.contentWindow.document.body.querySelectorAll('video');
)


2022-09-20 22:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.