为什么检查DOM元素比在控制台中使用jQuery ID选择器显示的东西更困难?

Why is Inspecting the DOM element showing something diff than using jQuery ID selector in console?

本文关键字:显示 选择器 ID jQuery 元素 DOM 检查 控制台 为什么      更新时间:2023-09-26

我正在一个网站上显示一个图形。由于某些原因,当我检查元素时,我看到了这样的内容:

<div id="canvas-daily" style="position:relative;" ng-if="currentMode == 'day'"      class="ng-scope"><div class="circle-background"></div></div>

但是当我做document.getElementById("canvas-daily")在我的控制台,我得到父(canvas-daily) IDdiv内的svg图形。为什么会发生这种情况,我怎么能修复/hack到这个追加的内容,显然有吗?

Edit -由于OP对他们的问题进行了编辑,这个答案已经过时了。由于评论中发生的对话,它尚未被删除。


要查找问题中HTML中显示的DOM元素,只需使用以下命令:

document.getElementById("canvas-daily")

传递给document.getElementById()的字符串中不要包含#。这只用于接受CSS选择器(如document.querySelectorAll())的更通用的函数。document.getElementById()只需要一个与您正在寻找的ID匹配的普通字符串。