通过DOM搜索动态插入的标签 [英] Search a dynamically inserted tag through DOM
问题描述
Hii全部,
是否可以通过DOM搜索动态插入的标签?
例如,在我的html页面中,如果我创建一个"video"标签(使用document.createElement("video")),是否可以通过DOM检查该标签是否包含在页面中?如果可能的话,我该怎么做?
谢谢.....
Hii All,
Is it possible to search for a dynamically inserted tag through DOM?.
For example, in my html page if I create a "video" tag(using document.createElement("video")), is it possible to check through DOM whether that tag is included in the page or not? If possible how will I do that?
Thanks.....
推荐答案
是否有可能通过DOM检查该标签是否包含在页面中?
is it possible to check through DOM whether that tag is included in the page or not?
是的!你可以.
一旦它们成为文档页面的一部分,就可以在DOM中访问它们.
=====
更新:
创建标签后,您需要将该标签添加到任何现有的先前标签中.完成后,您应该可以遍历它.
看这里:
使用Javascript动态添加和删除HTML元素 [ ^ ]
动态DOM内容 [
Yes! you can.
Once they are the part of the document page, they are accessible in DOM.
=====
UPDATE:
Once you create a tag, you need to add that tag to any existing previous tags. Once done, you should be able to traverse it out.
Look here:
Add and Remove HTML elements dynamically with Javascript[^]
Dynamic DOM content[^]
如Sandeep Mewara所说,
document.createElement 这将创建一个仅在DOM中尚未插入的对象实例(元素),
要添加/插入它,您需要在所需元素父示例中使用 appendChild :
0)您有一个 Div ,其ID为="VidzArea"
1)您可以使用 document.getElementById
获得该DIV的引用
2)现在 DIV (VidzArea)是您想要的父母
3),最后将其添加到 document.createElement
as Sandeep Mewara says,
document.createElement this create a just an object instance (element) not inserted yet in DOM,
for to add/insert it, you need to use appendChild in desired element parent example :
0) you have a Div with id = "VidzArea"
1) you get reference of this DIV by using document.getElementById
2) now DIV (VidzArea) is your desired parent
3) and finally you add it your Video element created by document.createElement
这篇关于通过DOM搜索动态插入的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!