简体   繁体   English

如何在特定元素中附加内容?

[英]How to append something in a specific element?

How do I append the created element in a specific element? 如何将创建的元素附加到特定元素中?

  container = document.createElement( 'div' );
  document.body.appendChild( container );

像这样...

document.getElementById('specific_ele').appendChild(container);

This code will append "container" in body elemnt. 此代码将在正文中附加“容器”。 To append in another element, I have to select it at first. 要添加另一个元素,我必须首先选择它。 So you can use "getElementById" or something like that to find the element. 因此,您可以使用“ getElementById”或类似的方法来查找元素。 Then you can use appendChild for append tag into found tag. 然后,您可以使用appendChild将标签附加到找到的标签中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM